Code at the speed of thought – Zed is a high-performance, multiplayer code editor from the creators of Atom and Tree-sitter.
Expose REPL Settings (#37927)
Casper van Elterenc50b561e1c82
diff --git a/Cargo.lock b/Cargo.lockindex 8252dc5fe86..c3002f44971 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.jsonindex 4cb779b5a0b..68aef5cccc9 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.tomlindex 5821bc62972..dea04243b2e 100644--- a/crates/repl/Cargo.toml+++ b/crates/repl/Cargo.toml@@ -40,6 +40,7 @@ project.workspace = trueruntimelib.workspace = trueschemars.workspace = trueserde.workspace = true+serde_derive.workspace = trueserde_json.workspace = truesettings.workspace = truesmol.workspace = truediff --git a/crates/repl/src/outputs/plain.rs b/crates/repl/src/outputs/plain.rsindex 268224fda35..844bf6ed132 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<VoidListener>,}-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 widthlet width = columns as f32 * cell_width;diff --git a/crates/repl/src/repl.rs b/crates/repl/src/repl.rsindex 7c17b5fac2a..f6005f1ed73 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<dyn Fs>, 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.rsnew file mode 100644index 00000000000..541455c7fc3--- /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<Self::FileContent>, _cx: &mut App) -> anyhow::Result<Self> {+ 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.mdindex 4a95bb50437..a7b89dc5207 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.