diff --git a/Cargo.lock b/Cargo.lock index 8252dc5fe867fc0668ea94b41cee502b47e3aa84..c3002f449719306f3714754b1fd94811b073b150 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -13623,6 +13623,7 @@ dependencies = [ "runtimelib", "schemars", "serde", + "serde_derive", "serde_json", "settings", "smol", diff --git a/assets/settings/default.json b/assets/settings/default.json index 4cb779b5a0bacbee3f74126abf89bfeb77aecc49..68aef5cccc92d9cc4133ae8db65bfeb9d4e39923 100644 --- a/assets/settings/default.json +++ b/assets/settings/default.json @@ -1844,6 +1844,15 @@ // "typescript": "deno" // } }, + // Repl settings. + "repl": { + // Maximum number of columns to keep in REPL's scrollback buffer. + // Clamped with [20, 512] range. + "max_columns": 128, + // Maximum number of lines to keep in REPL's scrollback buffer. + // Clamped with [4, 256] range. + "max_lines": 32 + }, // Vim settings "vim": { "default_mode": "normal", diff --git a/crates/repl/Cargo.toml b/crates/repl/Cargo.toml index 5821bc6297266cffba19234d82efec3f6190c310..dea04243b2ed8f6c0611f17077a00e0c02c13693 100644 --- a/crates/repl/Cargo.toml +++ b/crates/repl/Cargo.toml @@ -40,6 +40,7 @@ project.workspace = true runtimelib.workspace = true schemars.workspace = true serde.workspace = true +serde_derive.workspace = true serde_json.workspace = true settings.workspace = true smol.workspace = true diff --git a/crates/repl/src/outputs/plain.rs b/crates/repl/src/outputs/plain.rs index 268224fda35d6db78135f0b0154966159570dc4c..844bf6ed132fbe004b1aa22ddffb78ba39911855 100644 --- a/crates/repl/src/outputs/plain.rs +++ b/crates/repl/src/outputs/plain.rs @@ -31,6 +31,7 @@ use theme::ThemeSettings; use ui::{IntoElement, prelude::*}; use crate::outputs::OutputContent; +use crate::repl_settings::ReplSettings; /// The `TerminalOutput` struct handles the parsing and rendering of text input, /// simulating a basic terminal environment within REPL output. @@ -53,9 +54,6 @@ pub struct TerminalOutput { handler: alacritty_terminal::Term, } -const DEFAULT_NUM_LINES: usize = 32; -const DEFAULT_NUM_COLUMNS: usize = 128; - /// Returns the default text style for the terminal output. pub fn text_style(window: &mut Window, cx: &mut App) -> TextStyle { let settings = ThemeSettings::get_global(cx).clone(); @@ -99,8 +97,8 @@ pub fn terminal_size(window: &mut Window, cx: &mut App) -> terminal::TerminalBou .unwrap() .width; - let num_lines = DEFAULT_NUM_LINES; - let columns = DEFAULT_NUM_COLUMNS; + let num_lines = ReplSettings::get_global(cx).max_lines; + let columns = ReplSettings::get_global(cx).max_columns; // Reversed math from terminal::TerminalSize to get pixel width according to terminal width let width = columns as f32 * cell_width; diff --git a/crates/repl/src/repl.rs b/crates/repl/src/repl.rs index 7c17b5fac2a3aa9107a44543416f6210dcaa80c7..f6005f1ed73ac07697af48297643b30be113c83c 100644 --- a/crates/repl/src/repl.rs +++ b/crates/repl/src/repl.rs @@ -5,6 +5,7 @@ pub mod notebook; mod outputs; mod repl_editor; mod repl_sessions_ui; +mod repl_settings; mod repl_store; mod session; @@ -22,6 +23,7 @@ pub use crate::repl_editor::*; pub use crate::repl_sessions_ui::{ ClearOutputs, Interrupt, ReplSessionsPage, Restart, Run, Sessions, Shutdown, }; +pub use crate::repl_settings::ReplSettings; use crate::repl_store::ReplStore; pub use crate::session::Session; @@ -31,6 +33,7 @@ pub fn init(fs: Arc, cx: &mut App) { set_dispatcher(zed_dispatcher(cx)); JupyterSettings::register(cx); ::editor::init_settings(cx); + ReplSettings::register(cx); repl_sessions_ui::init(cx); ReplStore::init(fs, cx); } diff --git a/crates/repl/src/repl_settings.rs b/crates/repl/src/repl_settings.rs new file mode 100644 index 0000000000000000000000000000000000000000..541455c7fc3adc16cbb1e48fb811a2ac3a30bbbc --- /dev/null +++ b/crates/repl/src/repl_settings.rs @@ -0,0 +1,55 @@ +use gpui::App; +use schemars::JsonSchema; +use serde_derive::{Deserialize, Serialize}; +use settings::{Settings, SettingsKey, SettingsSources, SettingsUi}; + +/// Settings for configuring REPL display and behavior. +#[derive(Clone, Debug, Serialize, Deserialize, JsonSchema, SettingsUi, SettingsKey)] +#[settings_key(key = "repl")] +pub struct ReplSettings { + /// Maximum number of lines to keep in REPL's scrollback buffer. + /// Clamped with [4, 256] range. + /// + /// Default: 32 + #[serde(default = "default_max_lines")] + pub max_lines: usize, + /// Maximum number of columns to keep in REPL's scrollback buffer. + /// Clamped with [20, 512] range. + /// + /// Default: 128 + #[serde(default = "default_max_columns")] + pub max_columns: usize, +} + +impl Settings for ReplSettings { + type FileContent = Self; + + fn load(sources: SettingsSources, _cx: &mut App) -> anyhow::Result { + let mut settings: ReplSettings = sources.json_merge()?; + settings.max_columns = settings.max_columns.clamp(20, 512); + settings.max_lines = settings.max_lines.clamp(4, 256); + Ok(settings) + } + + fn import_from_vscode(_vscode: &settings::VsCodeSettings, _current: &mut Self::FileContent) {} +} + +const DEFAULT_NUM_LINES: usize = 32; +const DEFAULT_NUM_COLUMNS: usize = 128; + +fn default_max_lines() -> usize { + DEFAULT_NUM_LINES +} + +fn default_max_columns() -> usize { + DEFAULT_NUM_COLUMNS +} + +impl Default for ReplSettings { + fn default() -> Self { + ReplSettings { + max_lines: DEFAULT_NUM_LINES, + max_columns: DEFAULT_NUM_COLUMNS, + } + } +} diff --git a/docs/src/configuring-zed.md b/docs/src/configuring-zed.md index 4a95bb50437f5b37a30c2658b41d28fc0f3a1708..a7b89dc5207e0acea422401b0ce77946c7d484c6 100644 --- a/docs/src/configuring-zed.md +++ b/docs/src/configuring-zed.md @@ -4026,6 +4026,23 @@ Example command to set the title: `echo -e "\e]2;New Title\007";` } ``` +## REPL + +- Description: Repl settings. +- Setting: `repl` +- Default: + +```json +"repl": { + // Maximum number of columns to keep in REPL's scrollback buffer. + // Clamped with [20, 512] range. + "max_columns": 128, + // Maximum number of lines to keep in REPL's scrollback buffer. + // Clamped with [4, 256] range. + "max_lines": 32 +}, +``` + ## Theme - Description: The theme setting can be specified in two forms - either as the name of a theme or as an object containing the `mode`, `dark`, and `light` themes for the Zed UI.