Added scrollback history setting to terminals
This commit is contained in:
1 parent
2d54d74c69
commit
ee01826fb9
4 files changed
+172
-12
No files matched your search
+26
-7
@@ -91,18 +91,23 @@ pub fn grid_size(size: iced::Size, font_size: f32) -> (u16, u16) {
|
||||
(rows, cols)
|
||||
}
|
||||
|
||||
/// Default number of scrollback lines kept for each terminal session.
|
||||
pub const DEFAULT_SCROLLBACK_SIZE: usize = 10_000;
|
||||
/// Upper bound for the configurable scrollback size.
|
||||
pub const MAX_SCROLLBACK_SIZE: usize = 1_000_000;
|
||||
|
||||
/// Parsed terminal screen. This has no knowledge of where the bytes came from.
|
||||
pub struct Emulator {
|
||||
parser: vt100::Parser,
|
||||
}
|
||||
|
||||
impl Emulator {
|
||||
pub fn new(rows: u16, cols: u16) -> Self {
|
||||
pub fn new(rows: u16, cols: u16, scrollback: usize) -> Self {
|
||||
let rows = std::num::NonZeroU16::new(rows.max(1)).unwrap();
|
||||
let cols = std::num::NonZeroU16::new(cols.max(1)).unwrap();
|
||||
|
||||
Self {
|
||||
parser: vt100::Parser::new(rows, cols, 2000),
|
||||
parser: vt100::Parser::new(rows, cols, scrollback),
|
||||
}
|
||||
}
|
||||
|
||||
@@ -247,19 +252,26 @@ pub struct Session {
|
||||
|
||||
impl Session {
|
||||
pub fn spawn(start_dir: &Path, rows: u16, cols: u16) -> Result<Self, String> {
|
||||
Self::spawn_with(start_dir, rows, cols, Shell::Default)
|
||||
Self::spawn_with_scrollback(
|
||||
start_dir,
|
||||
rows,
|
||||
cols,
|
||||
Shell::Default,
|
||||
DEFAULT_SCROLLBACK_SIZE,
|
||||
)
|
||||
}
|
||||
|
||||
pub fn spawn_with(
|
||||
pub fn spawn_with_scrollback(
|
||||
start_dir: &Path,
|
||||
rows: u16,
|
||||
cols: u16,
|
||||
shell: Shell,
|
||||
scrollback: usize,
|
||||
) -> Result<Self, String> {
|
||||
let pty = pty::Pty::spawn_with(start_dir, rows, cols, shell)?;
|
||||
|
||||
Ok(Self {
|
||||
emulator: Emulator::new(rows, cols),
|
||||
emulator: Emulator::new(rows, cols, scrollback),
|
||||
pty,
|
||||
})
|
||||
}
|
||||
@@ -1161,7 +1173,7 @@ mod tests {
|
||||
fn session() -> Session {
|
||||
let pty = pty::Pty::spawn_for_test(Path::new("/"), 24, 80).unwrap();
|
||||
Session {
|
||||
emulator: Emulator::new(24, 80),
|
||||
emulator: Emulator::new(24, 80, DEFAULT_SCROLLBACK_SIZE),
|
||||
pty,
|
||||
}
|
||||
}
|
||||
@@ -1377,6 +1389,13 @@ mod tests {
|
||||
assert!(resized, "the shell did not observe the new window size");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn emulator_uses_the_configured_scrollback() {
|
||||
let emulator = Emulator::new(24, 80, 12_345);
|
||||
|
||||
assert_eq!(emulator.screen().scrollback_capacity(), 12_345);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn shell_runs_in_the_start_directory() {
|
||||
let directory =
|
||||
@@ -1386,7 +1405,7 @@ mod tests {
|
||||
let mut session = {
|
||||
let pty = pty::Pty::spawn_for_test(&directory, 24, 80).unwrap();
|
||||
Session {
|
||||
emulator: Emulator::new(24, 80),
|
||||
emulator: Emulator::new(24, 80, DEFAULT_SCROLLBACK_SIZE),
|
||||
pty,
|
||||
}
|
||||
};
|
||||
|
||||
Reference in new issue
Block a user