repl_settings.rs

 1use gpui::App;
 2use schemars::JsonSchema;
 3use serde::{Deserialize, Serialize};
 4use settings::{Settings, SettingsKey, SettingsSources, SettingsUi};
 5
 6/// Settings for configuring REPL display and behavior.
 7#[derive(Clone, Debug, Serialize, Deserialize, JsonSchema, SettingsUi, SettingsKey)]
 8#[settings_key(key = "repl")]
 9pub struct ReplSettings {
10    /// Maximum number of lines to keep in REPL's scrollback buffer.
11    /// Clamped with [4, 256] range.
12    ///
13    /// Default: 32
14    #[serde(default = "default_max_lines")]
15    pub max_lines: usize,
16    /// Maximum number of columns to keep in REPL's scrollback buffer.
17    /// Clamped with [20, 512] range.
18    ///
19    /// Default: 128
20    #[serde(default = "default_max_columns")]
21    pub max_columns: usize,
22}
23
24impl Settings for ReplSettings {
25    type FileContent = Self;
26
27    fn load(sources: SettingsSources<Self::FileContent>, _cx: &mut App) -> anyhow::Result<Self> {
28        let mut settings: ReplSettings = sources.json_merge()?;
29        settings.max_columns = settings.max_columns.clamp(20, 512);
30        settings.max_lines = settings.max_lines.clamp(4, 256);
31        Ok(settings)
32    }
33
34    fn import_from_vscode(_vscode: &settings::VsCodeSettings, _current: &mut Self::FileContent) {}
35}
36
37const DEFAULT_NUM_LINES: usize = 32;
38const DEFAULT_NUM_COLUMNS: usize = 128;
39
40fn default_max_lines() -> usize {
41    DEFAULT_NUM_LINES
42}
43
44fn default_max_columns() -> usize {
45    DEFAULT_NUM_COLUMNS
46}
47
48impl Default for ReplSettings {
49    fn default() -> Self {
50        ReplSettings {
51            max_lines: DEFAULT_NUM_LINES,
52            max_columns: DEFAULT_NUM_COLUMNS,
53        }
54    }
55}