Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature: Configurable scroll buffer #936

Merged
merged 4 commits into from
Jan 4, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions zellij-server/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ use route::route_thread_main;
use zellij_utils::{
channels::{self, ChannelWithContext, SenderWithContext},
cli::CliArgs,
consts::{DEFAULT_SCROLL_BUFFER_SIZE, SCROLL_BUFFER_SIZE},
errors::{ContextType, ErrorInstruction, ServerContext},
input::{
command::{RunCommand, TerminalAction},
Expand Down Expand Up @@ -547,6 +548,15 @@ fn init_session(
layout,
plugins,
} = options;

SCROLL_BUFFER_SIZE
.set(
config_options
.scroll_buffer_size
.unwrap_or(DEFAULT_SCROLL_BUFFER_SIZE),
)
.unwrap();

let (to_screen, screen_receiver): ChannelWithContext<ScreenInstruction> = channels::unbounded();
let to_screen = SenderWithContext::new(to_screen);

Expand Down
19 changes: 13 additions & 6 deletions zellij-server/src/panes/grid.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,13 @@ use std::{
str,
};

use zellij_utils::{position::Position, vte, zellij_tile};
use zellij_utils::{
consts::{DEFAULT_SCROLL_BUFFER_SIZE, SCROLL_BUFFER_SIZE},
position::Position,
vte, zellij_tile,
};

const TABSTOP_WIDTH: usize = 8; // TODO: is this always right?
pub const SCROLL_BACK: usize = 10_000;
pub const MAX_TITLE_STACK_SIZE: usize = 1000;

use vte::{Params, Perform};
Expand Down Expand Up @@ -226,7 +229,7 @@ fn transfer_rows_from_lines_below_to_viewport(

fn bounded_push(vec: &mut VecDeque<Row>, value: Row) -> Option<usize> {
let mut dropped_line_width = None;
if vec.len() >= SCROLL_BACK {
if vec.len() >= *SCROLL_BUFFER_SIZE.get().unwrap() {
let line = vec.pop_front();
if let Some(line) = line {
dropped_line_width = Some(line.width());
Expand Down Expand Up @@ -418,7 +421,11 @@ impl Debug for Grid {
impl Grid {
pub fn new(rows: usize, columns: usize, colors: Palette) -> Self {
Grid {
lines_above: VecDeque::with_capacity(SCROLL_BACK),
lines_above: VecDeque::with_capacity(
// .get_or_init() is used instead of .get().unwrap() to prevent
// unit tests from panicking where SCROLL_BUFFER_SIZE is uninitialized.
*SCROLL_BUFFER_SIZE.get_or_init(|| DEFAULT_SCROLL_BUFFER_SIZE),
),
viewport: vec![Row::new(columns).canonical()],
lines_below: vec![],
horizontal_tabstops: create_horizontal_tabstops(columns),
Expand Down Expand Up @@ -1348,7 +1355,7 @@ impl Grid {
self.should_render = true;
}
fn reset_terminal_state(&mut self) {
self.lines_above = VecDeque::with_capacity(SCROLL_BACK);
self.lines_above = VecDeque::with_capacity(*SCROLL_BUFFER_SIZE.get().unwrap());
self.lines_below = vec![];
self.viewport = vec![Row::new(self.width).canonical()];
self.alternative_lines_above_viewport_and_cursor = None;
Expand Down Expand Up @@ -1844,7 +1851,7 @@ impl Perform for Grid {
Some(1049) => {
let current_lines_above = std::mem::replace(
&mut self.lines_above,
VecDeque::with_capacity(SCROLL_BACK),
VecDeque::with_capacity(*SCROLL_BUFFER_SIZE.get().unwrap()),
);
let current_viewport = std::mem::replace(
&mut self.viewport,
Expand Down
2 changes: 1 addition & 1 deletion zellij-utils/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ interprocess = "1.1.1"
lazy_static = "1.4.0"
libc = "0.2"
nix = "0.19.1"
once_cell = "1.7.2"
once_cell = "1.8.0"
serde = { version = "1.0", features = ["derive"] }
serde_yaml = "0.8"
serde_json = "1.0"
Expand Down
7 changes: 7 additions & 0 deletions zellij-utils/assets/config/default.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -392,3 +392,10 @@ plugins:
# - true (default)
# - false
#mouse_mode: false

# Configure the scroll back buffer size
# This is the number of lines zellij stores for each pane in the scroll back
# buffer. Excess number of lines are discarded in a FIFO fashion.
# Valid values: positive integers
# Default value: 10000
#scroll_buffer_size: 10000
3 changes: 3 additions & 0 deletions zellij-utils/src/consts.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,16 @@ use crate::shared::set_permissions;
use directories_next::ProjectDirs;
use lazy_static::lazy_static;
use nix::unistd::Uid;
use once_cell::sync::OnceCell;
use std::path::PathBuf;
use std::{env, fs};

pub const ZELLIJ_CONFIG_FILE_ENV: &str = "ZELLIJ_CONFIG_FILE";
pub const ZELLIJ_CONFIG_DIR_ENV: &str = "ZELLIJ_CONFIG_DIR";
pub const ZELLIJ_LAYOUT_DIR_ENV: &str = "ZELLIJ_LAYOUT_DIR";
pub const VERSION: &str = env!("CARGO_PKG_VERSION");
pub const DEFAULT_SCROLL_BUFFER_SIZE: usize = 10_000;
pub static SCROLL_BUFFER_SIZE: OnceCell<usize> = OnceCell::new();

pub const SYSTEM_DEFAULT_CONFIG_DIR: &str = "/etc/zellij";
pub const SYSTEM_DEFAULT_DATA_DIR_PREFIX: &str = system_default_data_dir();
Expand Down
7 changes: 7 additions & 0 deletions zellij-utils/src/input/options.rs
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,8 @@ pub struct Options {
/// Set behaviour on force close (quit or detach)
#[structopt(long)]
pub on_force_close: Option<OnForceClose>,
#[structopt(long)]
pub scroll_buffer_size: Option<usize>,
}

impl Options {
Expand All @@ -91,6 +93,7 @@ impl Options {
let layout_dir = other.layout_dir.or_else(|| self.layout_dir.clone());
let theme = other.theme.or_else(|| self.theme.clone());
let on_force_close = other.on_force_close.or(self.on_force_close);
let scroll_buffer_size = other.scroll_buffer_size.or(self.scroll_buffer_size);

Options {
simplified_ui,
Expand All @@ -101,6 +104,7 @@ impl Options {
mouse_mode,
pane_frames,
on_force_close,
scroll_buffer_size,
}
}

Expand Down Expand Up @@ -128,6 +132,7 @@ impl Options {
let layout_dir = other.layout_dir.or_else(|| self.layout_dir.clone());
let theme = other.theme.or_else(|| self.theme.clone());
let on_force_close = other.on_force_close.or(self.on_force_close);
let scroll_buffer_size = other.scroll_buffer_size.or(self.scroll_buffer_size);

Options {
simplified_ui,
Expand All @@ -138,6 +143,7 @@ impl Options {
mouse_mode,
pane_frames,
on_force_close,
scroll_buffer_size,
}
}

Expand Down Expand Up @@ -184,6 +190,7 @@ impl From<CliOptions> for Options {
mouse_mode: opts.mouse_mode,
pane_frames: opts.pane_frames,
on_force_close: opts.on_force_close,
scroll_buffer_size: opts.scroll_buffer_size,
}
}
}