aboutsummaryrefslogtreecommitdiff
path: root/alacritty_terminal/src/tty
diff options
context:
space:
mode:
Diffstat (limited to 'alacritty_terminal/src/tty')
-rw-r--r--alacritty_terminal/src/tty/mod.rs20
-rw-r--r--alacritty_terminal/src/tty/unix.rs40
-rw-r--r--alacritty_terminal/src/tty/windows/child.rs4
-rw-r--r--alacritty_terminal/src/tty/windows/conpty.rs18
-rw-r--r--alacritty_terminal/src/tty/windows/mod.rs4
-rw-r--r--alacritty_terminal/src/tty/windows/winpty.rs10
6 files changed, 48 insertions, 48 deletions
diff --git a/alacritty_terminal/src/tty/mod.rs b/alacritty_terminal/src/tty/mod.rs
index f3e07eb2..69afd773 100644
--- a/alacritty_terminal/src/tty/mod.rs
+++ b/alacritty_terminal/src/tty/mod.rs
@@ -12,7 +12,7 @@
// See the License for the specific language governing permissions and
// limitations under the License.
//
-//! tty related functionality
+//! TTY related functionality.
use std::{env, io};
use terminfo::Database;
@@ -52,28 +52,28 @@ pub trait EventedReadWrite {
fn write_token(&self) -> mio::Token;
}
-/// Events concerning TTY child processes
+/// Events concerning TTY child processes.
#[derive(Debug, PartialEq)]
pub enum ChildEvent {
- /// Indicates the child has exited
+ /// Indicates the child has exited.
Exited,
}
-/// A pseudoterminal (or PTY)
+/// A pseudoterminal (or pty).
///
/// This is a refinement of EventedReadWrite that also provides a channel through which we can be
-/// notified if the PTY child process does something we care about (other than writing to the TTY).
+/// notified if the pty child process does something we care about (other than writing to the TTY).
/// In particular, this allows for race-free child exit notification on UNIX (cf. `SIGCHLD`).
pub trait EventedPty: EventedReadWrite {
fn child_event_token(&self) -> mio::Token;
- /// Tries to retrieve an event
+ /// Tries to retrieve an event.
///
/// Returns `Some(event)` on success, or `None` if there are no events to retrieve.
fn next_child_event(&mut self) -> Option<ChildEvent>;
}
-// Setup environment variables
+/// Setup environment variables.
pub fn setup_env<C>(config: &Config<C>) {
// Default to 'alacritty' terminfo if it is available, otherwise
// default to 'xterm-256color'. May be overridden by user's config
@@ -83,13 +83,13 @@ pub fn setup_env<C>(config: &Config<C>) {
if Database::from_name("alacritty").is_ok() { "alacritty" } else { "xterm-256color" },
);
- // Advertise 24-bit color support
+ // Advertise 24-bit color support.
env::set_var("COLORTERM", "truecolor");
- // Prevent child processes from inheriting startup notification env
+ // Prevent child processes from inheriting startup notification env.
env::remove_var("DESKTOP_STARTUP_ID");
- // Set env vars from config
+ // Set env vars from config.
for (key, value) in config.env.iter() {
env::set_var(key, value);
}
diff --git a/alacritty_terminal/src/tty/unix.rs b/alacritty_terminal/src/tty/unix.rs
index 3be59467..e4276589 100644
--- a/alacritty_terminal/src/tty/unix.rs
+++ b/alacritty_terminal/src/tty/unix.rs
@@ -12,7 +12,7 @@
// See the License for the specific language governing permissions and
// limitations under the License.
//
-//! tty related functionality
+//! TTY related functionality.
use crate::config::{Config, Shell};
use crate::event::OnResize;
@@ -37,9 +37,9 @@ use std::process::{Child, Command, Stdio};
use std::ptr;
use std::sync::atomic::{AtomicUsize, Ordering};
-/// Process ID of child process
+/// Process ID of child process.
///
-/// Necessary to put this in static storage for `sigchld` to have access
+/// Necessary to put this in static storage for `SIGCHLD` to have access.
static PID: AtomicUsize = AtomicUsize::new(0);
macro_rules! die {
@@ -53,7 +53,7 @@ pub fn child_pid() -> pid_t {
PID.load(Ordering::Relaxed) as pid_t
}
-/// Get raw fds for master/slave ends of a new pty
+/// Get raw fds for master/slave ends of a new pty.
fn make_pty(size: winsize) -> (RawFd, RawFd) {
let mut win_size = size;
win_size.ws_xpixel = 0;
@@ -64,7 +64,7 @@ fn make_pty(size: winsize) -> (RawFd, RawFd) {
(ends.master, ends.slave)
}
-/// Really only needed on BSD, but should be fine elsewhere
+/// Really only needed on BSD, but should be fine elsewhere.
fn set_controlling_terminal(fd: c_int) {
let res = unsafe {
// TIOSCTTY changes based on platform and the `ioctl` call is different
@@ -91,13 +91,13 @@ struct Passwd<'a> {
shell: &'a str,
}
-/// Return a Passwd struct with pointers into the provided buf
+/// Return a Passwd struct with pointers into the provided buf.
///
/// # Unsafety
///
/// If `buf` is changed while `Passwd` is alive, bad thing will almost certainly happen.
fn get_pw_entry(buf: &mut [i8; 1024]) -> Passwd<'_> {
- // Create zeroed passwd struct
+ // Create zeroed passwd struct.
let mut entry: MaybeUninit<libc::passwd> = MaybeUninit::uninit();
let mut res: *mut libc::passwd = ptr::null_mut();
@@ -117,10 +117,10 @@ fn get_pw_entry(buf: &mut [i8; 1024]) -> Passwd<'_> {
die!("pw not found");
}
- // sanity check
+ // Sanity check.
assert_eq!(entry.pw_uid, uid);
- // Build a borrowed Passwd struct
+ // Build a borrowed Passwd struct.
Passwd {
name: unsafe { CStr::from_ptr(entry.pw_name).to_str().unwrap() },
passwd: unsafe { CStr::from_ptr(entry.pw_passwd).to_str().unwrap() },
@@ -140,7 +140,7 @@ pub struct Pty {
signals_token: mio::Token,
}
-/// Create a new tty and return a handle to interact with it.
+/// Create a new TTY and return a handle to interact with it.
pub fn new<C>(config: &Config<C>, size: &SizeInfo, window_id: Option<usize>) -> Pty {
let win_size = size.to_winsize();
let mut buf = [0; 1024];
@@ -166,12 +166,12 @@ pub fn new<C>(config: &Config<C>, size: &SizeInfo, window_id: Option<usize>) ->
// Setup child stdin/stdout/stderr as slave fd of pty
// Ownership of fd is transferred to the Stdio structs and will be closed by them at the end of
// this scope. (It is not an issue that the fd is closed three times since File::drop ignores
- // error on libc::close.)
+ // error on libc::close.).
builder.stdin(unsafe { Stdio::from_raw_fd(slave) });
builder.stderr(unsafe { Stdio::from_raw_fd(slave) });
builder.stdout(unsafe { Stdio::from_raw_fd(slave) });
- // Setup shell environment
+ // Setup shell environment.
builder.env("LOGNAME", pw.name);
builder.env("USER", pw.name);
builder.env("SHELL", pw.shell);
@@ -183,7 +183,7 @@ pub fn new<C>(config: &Config<C>, size: &SizeInfo, window_id: Option<usize>) ->
unsafe {
builder.pre_exec(move || {
- // Create a new process group
+ // Create a new process group.
let err = libc::setsid();
if err == -1 {
die!("Failed to set session id: {}", io::Error::last_os_error());
@@ -191,7 +191,7 @@ pub fn new<C>(config: &Config<C>, size: &SizeInfo, window_id: Option<usize>) ->
set_controlling_terminal(slave);
- // No longer need slave/master fds
+ // No longer need slave/master fds.
libc::close(slave);
libc::close(master);
@@ -206,17 +206,17 @@ pub fn new<C>(config: &Config<C>, size: &SizeInfo, window_id: Option<usize>) ->
});
}
- // Handle set working directory option
+ // Handle set working directory option.
if let Some(dir) = &config.working_directory {
builder.current_dir(dir);
}
- // Prepare signal handling before spawning child
+ // Prepare signal handling before spawning child.
let signals = Signals::new(&[sighook::SIGCHLD]).expect("error preparing signal handling");
match builder.spawn() {
Ok(child) => {
- // Remember child PID so other modules can use it
+ // Remember child PID so other modules can use it.
PID.store(child.id() as usize, Ordering::Relaxed);
unsafe {
@@ -332,9 +332,9 @@ impl EventedPty for Pty {
}
}
-/// Types that can produce a `libc::winsize`
+/// Types that can produce a `libc::winsize`.
pub trait ToWinsize {
- /// Get a `libc::winsize`
+ /// Get a `libc::winsize`.
fn to_winsize(&self) -> winsize;
}
@@ -350,7 +350,7 @@ impl<'a> ToWinsize for &'a SizeInfo {
}
impl OnResize for Pty {
- /// Resize the pty
+ /// Resize the pty.
///
/// Tells the kernel that the window size changed with the new pixel
/// dimensions and line/column counts.
diff --git a/alacritty_terminal/src/tty/windows/child.rs b/alacritty_terminal/src/tty/windows/child.rs
index 69bff75c..c841c29a 100644
--- a/alacritty_terminal/src/tty/windows/child.rs
+++ b/alacritty_terminal/src/tty/windows/child.rs
@@ -106,10 +106,10 @@ mod tests {
child.kill().unwrap();
- // Poll for the event or fail with timeout if nothing has been sent
+ // Poll for the event or fail with timeout if nothing has been sent.
poll.poll(&mut events, Some(WAIT_TIMEOUT)).unwrap();
assert_eq!(events.iter().next().unwrap().token(), child_events_token);
- // Verify that at least one `ChildEvent::Exited` was received
+ // Verify that at least one `ChildEvent::Exited` was received.
assert_eq!(child_exit_watcher.event_rx().try_recv(), Ok(ChildEvent::Exited));
}
}
diff --git a/alacritty_terminal/src/tty/windows/conpty.rs b/alacritty_terminal/src/tty/windows/conpty.rs
index 99d52b05..c8a41f63 100644
--- a/alacritty_terminal/src/tty/windows/conpty.rs
+++ b/alacritty_terminal/src/tty/windows/conpty.rs
@@ -42,7 +42,7 @@ use crate::tty::windows::{cmdline, win32_string, Pty};
// done until a safety net is in place for versions of Windows
// that do not support the ConPTY api, as such versions will
// pass unit testing - but fail to actually function.
-/// Dynamically-loaded Pseudoconsole API from kernel32.dll
+/// Dynamically-loaded Pseudoconsole API from kernel32.dll.
///
/// The field names are deliberately PascalCase as this matches
/// the defined symbols in kernel32 and also is the convention
@@ -58,7 +58,7 @@ struct ConptyApi {
impl ConptyApi {
/// Load the API or None if it cannot be found.
pub fn new() -> Option<Self> {
- // Unsafe because windows API calls
+ // Unsafe because windows API calls.
unsafe {
let hmodule = GetModuleHandleA("kernel32\0".as_ptr() as _);
assert!(!hmodule.is_null());
@@ -80,7 +80,7 @@ impl ConptyApi {
}
}
-/// RAII Pseudoconsole
+/// RAII Pseudoconsole.
pub struct Conpty {
pub handle: HPCON,
api: ConptyApi,
@@ -91,7 +91,7 @@ impl Drop for Conpty {
// XXX: This will block until the conout pipe is drained. Will cause a deadlock if the
// conout pipe has already been dropped by this point.
//
- // See PR #3084 and https://docs.microsoft.com/en-us/windows/console/closepseudoconsole
+ // See PR #3084 and https://docs.microsoft.com/en-us/windows/console/closepseudoconsole.
unsafe { (self.api.ClosePseudoConsole)(self.handle) }
}
}
@@ -118,7 +118,7 @@ pub fn new<C>(config: &Config<C>, size: &SizeInfo, _window_id: Option<usize>) ->
let coord =
coord_from_sizeinfo(size).expect("Overflow when creating initial size on pseudoconsole");
- // Create the Pseudo Console, using the pipes
+ // Create the Pseudo Console, using the pipes.
let result = unsafe {
(api.CreatePseudoConsole)(
coord,
@@ -133,7 +133,7 @@ pub fn new<C>(config: &Config<C>, size: &SizeInfo, _window_id: Option<usize>) ->
let mut success;
- // Prepare child process startup info
+ // Prepare child process startup info.
let mut size: SIZE_T = 0;
@@ -185,12 +185,12 @@ pub fn new<C>(config: &Config<C>, size: &SizeInfo, _window_id: Option<usize>) ->
}
}
- // Set thread attribute list's Pseudo Console to the specified ConPTY
+ // Set thread attribute list's Pseudo Console to the specified ConPTY.
unsafe {
success = UpdateProcThreadAttribute(
startup_info_ex.lpAttributeList,
0,
- 22 | 0x0002_0000, // PROC_THREAD_ATTRIBUTE_PSEUDOCONSOLE
+ 22 | 0x0002_0000, // PROC_THREAD_ATTRIBUTE_PSEUDOCONSOLE.
pty_handle,
mem::size_of::<HPCON>(),
ptr::null_mut(),
@@ -242,7 +242,7 @@ pub fn new<C>(config: &Config<C>, size: &SizeInfo, _window_id: Option<usize>) ->
})
}
-// Panic with the last os error as message
+// Panic with the last os error as message.
fn panic_shell_spawn() {
panic!("Unable to spawn shell: {}", Error::last_os_error());
}
diff --git a/alacritty_terminal/src/tty/windows/mod.rs b/alacritty_terminal/src/tty/windows/mod.rs
index 03e2a3cd..8e5b4668 100644
--- a/alacritty_terminal/src/tty/windows/mod.rs
+++ b/alacritty_terminal/src/tty/windows/mod.rs
@@ -51,9 +51,9 @@ pub struct Pty {
// `conout` before `backend` will cause a deadlock.
backend: PtyBackend,
// TODO: It's on the roadmap for the Conpty API to support Overlapped I/O.
- // See https://github.com/Microsoft/console/issues/262
+ // See https://github.com/Microsoft/console/issues/262.
// When support for that lands then it should be possible to use
- // NamedPipe for the conout and conin handles
+ // NamedPipe for the conout and conin handles.
conout: EventedReadablePipe,
conin: EventedWritablePipe,
read_token: mio::Token,
diff --git a/alacritty_terminal/src/tty/windows/winpty.rs b/alacritty_terminal/src/tty/windows/winpty.rs
index 5fa6feea..d466955d 100644
--- a/alacritty_terminal/src/tty/windows/winpty.rs
+++ b/alacritty_terminal/src/tty/windows/winpty.rs
@@ -31,25 +31,25 @@ use crate::tty::windows::{cmdline, Pty};
pub use winpty::Winpty as Agent;
pub fn new<C>(config: &Config<C>, size: &SizeInfo, _window_id: Option<usize>) -> Pty {
- // Create config
+ // Create config.
let mut wconfig = WinptyConfig::new(ConfigFlags::empty()).unwrap();
wconfig.set_initial_size(size.cols().0 as i32, size.lines().0 as i32);
wconfig.set_mouse_mode(&MouseMode::Auto);
- // Start agent
+ // Start agent.
let mut agent = Winpty::open(&wconfig).unwrap();
let (conin, conout) = (agent.conin_name(), agent.conout_name());
let cmdline = cmdline(&config);
- // Spawn process
+ // Spawn process.
let spawnconfig = SpawnConfig::new(
SpawnFlags::AUTO_SHUTDOWN | SpawnFlags::EXIT_AFTER_SHUTDOWN,
- None, // appname
+ None, // appname.
Some(&cmdline),
config.working_directory.as_ref().map(|p| p.as_path()),
- None, // Env
+ None, // Env.
)
.unwrap();