summaryrefslogtreecommitdiff
path: root/alacritty_terminal/src/tty
diff options
context:
space:
mode:
authorKirill Chibisov <contact@kchibisov.com>2022-04-06 13:06:39 +0300
committerGitHub <noreply@github.com>2022-04-06 13:06:39 +0300
commit673710487afac8596a9f18fea9e04aeada32c2be (patch)
tree1305e00422c01e35d91c533b12004c0082528eb4 /alacritty_terminal/src/tty
parent851dbc328efd9b212bb2c7b9caaf5763eb4e524b (diff)
downloadalacritty-673710487afac8596a9f18fea9e04aeada32c2be.tar.gz
alacritty-673710487afac8596a9f18fea9e04aeada32c2be.zip
Extract `SizeInfo` from alacritty_terminal
The `SizeInfo` is a SizeInfo used for rendering, which contains information about padding, and such, however all the terminal need is number of visible lines and columns.
Diffstat (limited to 'alacritty_terminal/src/tty')
-rw-r--r--alacritty_terminal/src/tty/unix.rs40
-rw-r--r--alacritty_terminal/src/tty/windows/conpty.rs35
-rw-r--r--alacritty_terminal/src/tty/windows/mod.rs12
3 files changed, 37 insertions, 50 deletions
diff --git a/alacritty_terminal/src/tty/unix.rs b/alacritty_terminal/src/tty/unix.rs
index 206dbe8d..2bb5e973 100644
--- a/alacritty_terminal/src/tty/unix.rs
+++ b/alacritty_terminal/src/tty/unix.rs
@@ -22,9 +22,7 @@ use signal_hook::consts as sigconsts;
use signal_hook_mio::v0_6::Signals;
use crate::config::{Program, PtyConfig};
-use crate::event::OnResize;
-use crate::grid::Dimensions;
-use crate::term::SizeInfo;
+use crate::event::{OnResize, WindowSize};
use crate::tty::{ChildEvent, EventedPty, EventedReadWrite};
macro_rules! die {
@@ -36,11 +34,11 @@ macro_rules! die {
/// 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;
- win_size.ws_ypixel = 0;
+ let mut window_size = size;
+ window_size.ws_xpixel = 0;
+ window_size.ws_ypixel = 0;
- let ends = openpty(Some(&win_size), None).expect("openpty failed");
+ let ends = openpty(Some(&window_size), None).expect("openpty failed");
(ends.master, ends.slave)
}
@@ -137,8 +135,8 @@ fn default_shell(pw: &Passwd<'_>) -> Program {
}
/// Create a new TTY and return a handle to interact with it.
-pub fn new(config: &PtyConfig, size: &SizeInfo, window_id: Option<usize>) -> Result<Pty> {
- let (master, slave) = make_pty(size.to_winsize());
+pub fn new(config: &PtyConfig, window_size: WindowSize, window_id: Option<usize>) -> Result<Pty> {
+ let (master, slave) = make_pty(window_size.to_winsize());
#[cfg(any(target_os = "linux", target_os = "macos"))]
if let Ok(mut termios) = termios::tcgetattr(master) {
@@ -229,7 +227,7 @@ pub fn new(config: &PtyConfig, size: &SizeInfo, window_id: Option<usize>) -> Res
signals,
signals_token: mio::Token::from(0),
};
- pty.on_resize(size);
+ pty.on_resize(window_size);
Ok(pty)
},
Err(err) => Err(Error::new(
@@ -347,8 +345,8 @@ impl OnResize for Pty {
///
/// Tells the kernel that the window size changed with the new pixel
/// dimensions and line/column counts.
- fn on_resize(&mut self, size: &SizeInfo) {
- let win = size.to_winsize();
+ fn on_resize(&mut self, window_size: WindowSize) {
+ let win = window_size.to_winsize();
let res = unsafe { libc::ioctl(self.file.as_raw_fd(), libc::TIOCSWINSZ, &win as *const _) };
@@ -361,17 +359,17 @@ impl OnResize for Pty {
/// Types that can produce a `libc::winsize`.
pub trait ToWinsize {
/// Get a `libc::winsize`.
- fn to_winsize(&self) -> winsize;
+ fn to_winsize(self) -> winsize;
}
-impl<'a> ToWinsize for &'a SizeInfo {
- fn to_winsize(&self) -> winsize {
- winsize {
- ws_row: self.screen_lines() as libc::c_ushort,
- ws_col: self.columns() as libc::c_ushort,
- ws_xpixel: self.width() as libc::c_ushort,
- ws_ypixel: self.height() as libc::c_ushort,
- }
+impl ToWinsize for WindowSize {
+ fn to_winsize(self) -> winsize {
+ let ws_row = self.num_lines as libc::c_ushort;
+ let ws_col = self.num_cols as libc::c_ushort;
+
+ let ws_xpixel = ws_col * self.cell_width as libc::c_ushort;
+ let ws_ypixel = ws_row * self.cell_height as libc::c_ushort;
+ winsize { ws_row, ws_col, ws_xpixel, ws_ypixel }
}
}
diff --git a/alacritty_terminal/src/tty/windows/conpty.rs b/alacritty_terminal/src/tty/windows/conpty.rs
index 9556be8b..e856a1b1 100644
--- a/alacritty_terminal/src/tty/windows/conpty.rs
+++ b/alacritty_terminal/src/tty/windows/conpty.rs
@@ -1,6 +1,6 @@
use std::io::Error;
use std::os::windows::io::IntoRawHandle;
-use std::{i16, mem, ptr};
+use std::{mem, ptr};
use mio_anonymous_pipes::{EventedAnonRead, EventedAnonWrite};
use winapi::shared::basetsd::{PSIZE_T, SIZE_T};
@@ -16,9 +16,7 @@ use winapi::um::winbase::{EXTENDED_STARTUPINFO_PRESENT, STARTF_USESTDHANDLES, ST
use winapi::um::wincontypes::{COORD, HPCON};
use crate::config::PtyConfig;
-use crate::event::OnResize;
-use crate::grid::Dimensions;
-use crate::term::SizeInfo;
+use crate::event::{OnResize, WindowSize};
use crate::tty::windows::child::ChildExitWatcher;
use crate::tty::windows::{cmdline, win32_string, Pty};
@@ -40,7 +38,7 @@ impl Drop for Conpty {
// The ConPTY handle can be sent between threads.
unsafe impl Send for Conpty {}
-pub fn new(config: &PtyConfig, size: &SizeInfo) -> Option<Pty> {
+pub fn new(config: &PtyConfig, window_size: WindowSize) -> Option<Pty> {
let mut pty_handle = 0 as HPCON;
// Passing 0 as the size parameter allows the "system default" buffer
@@ -50,13 +48,10 @@ pub fn new(config: &PtyConfig, size: &SizeInfo) -> Option<Pty> {
let (conout, conout_pty_handle) = miow::pipe::anonymous(0).unwrap();
let (conin_pty_handle, conin) = miow::pipe::anonymous(0).unwrap();
- let coord =
- coord_from_sizeinfo(size).expect("Overflow when creating initial size on pseudoconsole");
-
// Create the Pseudo Console, using the pipes.
let result = unsafe {
CreatePseudoConsole(
- coord,
+ window_size.into(),
conin_pty_handle.into_raw_handle(),
conout_pty_handle.into_raw_handle(),
0,
@@ -174,22 +169,16 @@ fn panic_shell_spawn() {
}
impl OnResize for Conpty {
- fn on_resize(&mut self, sizeinfo: &SizeInfo) {
- if let Some(coord) = coord_from_sizeinfo(sizeinfo) {
- let result = unsafe { ResizePseudoConsole(self.handle, coord) };
- assert_eq!(result, S_OK);
- }
+ fn on_resize(&mut self, window_size: WindowSize) {
+ let result = unsafe { ResizePseudoConsole(self.handle, window_size.into()) };
+ assert_eq!(result, S_OK);
}
}
-/// Helper to build a COORD from a SizeInfo, returning None in overflow cases.
-fn coord_from_sizeinfo(size: &SizeInfo) -> Option<COORD> {
- let lines = size.screen_lines();
- let columns = size.columns();
-
- if columns <= i16::MAX as usize && lines <= i16::MAX as usize {
- Some(COORD { X: columns as i16, Y: lines as i16 })
- } else {
- None
+impl From<WindowSize> for COORD {
+ fn from(window_size: WindowSize) -> Self {
+ let lines = window_size.num_lines;
+ let columns = window_size.num_cols;
+ COORD { X: columns as i16, Y: lines as i16 }
}
}
diff --git a/alacritty_terminal/src/tty/windows/mod.rs b/alacritty_terminal/src/tty/windows/mod.rs
index 0cc6a8bc..aa21ce14 100644
--- a/alacritty_terminal/src/tty/windows/mod.rs
+++ b/alacritty_terminal/src/tty/windows/mod.rs
@@ -5,8 +5,7 @@ use std::os::windows::ffi::OsStrExt;
use std::sync::mpsc::TryRecvError;
use crate::config::{Program, PtyConfig};
-use crate::event::OnResize;
-use crate::term::SizeInfo;
+use crate::event::{OnResize, WindowSize};
use crate::tty::windows::child::ChildExitWatcher;
use crate::tty::{ChildEvent, EventedPty, EventedReadWrite};
@@ -28,8 +27,9 @@ pub struct Pty {
child_watcher: ChildExitWatcher,
}
-pub fn new(config: &PtyConfig, size: &SizeInfo, _window_id: Option<usize>) -> Result<Pty> {
- conpty::new(config, size).ok_or_else(|| Error::new(ErrorKind::Other, "failed to spawn conpty"))
+pub fn new(config: &PtyConfig, window_size: WindowSize, _window_id: Option<usize>) -> Result<Pty> {
+ conpty::new(config, window_size)
+ .ok_or_else(|| Error::new(ErrorKind::Other, "failed to spawn conpty"))
}
impl Pty {
@@ -160,8 +160,8 @@ impl EventedPty for Pty {
}
impl OnResize for Pty {
- fn on_resize(&mut self, size: &SizeInfo) {
- self.backend.on_resize(size)
+ fn on_resize(&mut self, window_size: WindowSize) {
+ self.backend.on_resize(window_size)
}
}