Skip to repository content

tenant.openagents/omega

No repository description is available.

OpenAgents Git authority 2026-07-28T04:12:52.258Z Public web read
NIP-34 coordinate30617:7649603503856e5148d571eac2766b288a8ff1e9e35d380337a1d2b0015b4f92:omega
MaintainersHidden in public view
References2 branches · 1 tag
Read-only clonegit clone https://openagents.com/git/tenant.openagents/omega.git
Browse files

terminal_settings.rs

165 lines · 6.6 KB · rust
1use collections::HashMap;
2use gpui::{FontFallbacks, FontFeatures, FontWeight, Pixels, px};
3use schemars::JsonSchema;
4use serde::{Deserialize, Serialize};
5
6pub use settings::AlternateScroll;
7
8use settings::{
9    IntoGpui, PathHyperlinkRegex, RegisterSetting, ShowScrollbar, TerminalBell, TerminalBlink,
10    TerminalDockPosition, TerminalLineHeight, VenvSettings, WorkingDirectory,
11    merge_from::MergeFrom,
12};
13use task::Shell;
14use theme_settings::FontFamilyName;
15
16#[derive(Copy, Clone, Debug, Serialize, Deserialize, JsonSchema, PartialEq, Eq)]
17pub struct Toolbar {
18    pub breadcrumbs: bool,
19}
20
21#[derive(Clone, Debug, Deserialize, RegisterSetting)]
22pub struct TerminalSettings {
23    pub shell: Shell,
24    pub working_directory: WorkingDirectory,
25    pub font_size: Option<Pixels>, // todo(settings_refactor) can be non-optional...
26    pub font_family: Option<FontFamilyName>,
27    pub font_fallbacks: Option<FontFallbacks>,
28    pub font_features: Option<FontFeatures>,
29    pub font_weight: Option<FontWeight>,
30    pub line_height: TerminalLineHeight,
31    pub env: HashMap<String, String>,
32    pub cursor_shape: CursorShape,
33    pub blinking: TerminalBlink,
34    pub alternate_scroll: AlternateScroll,
35    pub option_as_meta: bool,
36    pub copy_on_select: bool,
37    pub keep_selection_on_copy: bool,
38    pub open_links_in_mouse_mode: bool,
39    pub button: bool,
40    pub dock: TerminalDockPosition,
41    pub flexible: bool,
42    pub default_width: Pixels,
43    pub default_height: Pixels,
44    pub detect_venv: VenvSettings,
45    pub max_scroll_history_lines: Option<usize>,
46    pub scroll_multiplier: f32,
47    pub toolbar: Toolbar,
48    pub scrollbar: ScrollbarSettings,
49    pub minimum_contrast: f32,
50    pub path_hyperlink_regexes: Vec<String>,
51    pub path_hyperlink_timeout_ms: u64,
52    pub show_count_badge: bool,
53    pub bell: TerminalBell,
54}
55
56#[derive(Copy, Clone, Debug, Serialize, Deserialize, JsonSchema, PartialEq, Eq)]
57pub struct ScrollbarSettings {
58    /// When to show the scrollbar in the terminal.
59    ///
60    /// Default: inherits editor scrollbar settings
61    pub show: Option<ShowScrollbar>,
62}
63
64fn settings_shell_to_task_shell(shell: settings::Shell) -> Shell {
65    match shell {
66        settings::Shell::System => Shell::System,
67        settings::Shell::Program(program) => Shell::Program(program),
68        settings::Shell::WithArguments {
69            program,
70            args,
71            title_override,
72        } => Shell::WithArguments {
73            program,
74            args,
75            title_override,
76        },
77    }
78}
79
80impl settings::Settings for TerminalSettings {
81    fn from_settings(content: &settings::SettingsContent) -> Self {
82        let user_content = content.terminal.clone().unwrap();
83        // Note: we allow a subset of "terminal" settings in the project files.
84        let mut project_content = user_content.project.clone();
85        project_content.merge_from_option(content.project.terminal.as_ref());
86        TerminalSettings {
87            shell: settings_shell_to_task_shell(project_content.shell.unwrap()),
88            working_directory: project_content.working_directory.unwrap(),
89            font_size: user_content.font_size.map(|s| s.into_gpui()),
90            font_family: user_content.font_family,
91            font_fallbacks: user_content.font_fallbacks.map(|fallbacks| {
92                FontFallbacks::from_fonts(
93                    fallbacks
94                        .into_iter()
95                        .map(|family| family.0.to_string())
96                        .collect(),
97                )
98            }),
99            font_features: user_content.font_features.map(|f| f.into_gpui()),
100            font_weight: user_content.font_weight.map(|w| w.into_gpui()),
101            line_height: user_content.line_height.unwrap(),
102            env: project_content.env.unwrap(),
103            cursor_shape: user_content.cursor_shape.unwrap().into(),
104            blinking: user_content.blinking.unwrap(),
105            alternate_scroll: user_content.alternate_scroll.unwrap(),
106            option_as_meta: user_content.option_as_meta.unwrap(),
107            copy_on_select: user_content.copy_on_select.unwrap(),
108            keep_selection_on_copy: user_content.keep_selection_on_copy.unwrap(),
109            open_links_in_mouse_mode: user_content.open_links_in_mouse_mode.unwrap(),
110            button: user_content.button.unwrap(),
111            dock: user_content.dock.unwrap(),
112            default_width: px(user_content.default_width.unwrap()),
113            default_height: px(user_content.default_height.unwrap()),
114            flexible: user_content.flexible.unwrap(),
115            detect_venv: project_content.detect_venv.unwrap(),
116            scroll_multiplier: user_content.scroll_multiplier.unwrap(),
117            max_scroll_history_lines: user_content.max_scroll_history_lines,
118            toolbar: Toolbar {
119                breadcrumbs: user_content.toolbar.unwrap().breadcrumbs.unwrap(),
120            },
121            scrollbar: ScrollbarSettings {
122                show: user_content.scrollbar.unwrap().show,
123            },
124            minimum_contrast: user_content.minimum_contrast.unwrap(),
125            path_hyperlink_regexes: project_content
126                .path_hyperlink_regexes
127                .unwrap()
128                .into_iter()
129                .map(|regex| match regex {
130                    PathHyperlinkRegex::SingleLine(regex) => regex,
131                    PathHyperlinkRegex::MultiLine(regex) => regex.join("\n"),
132                })
133                .collect(),
134            path_hyperlink_timeout_ms: project_content.path_hyperlink_timeout_ms.unwrap(),
135            show_count_badge: user_content.show_count_badge.unwrap(),
136            bell: user_content.bell.unwrap(),
137        }
138    }
139}
140
141#[derive(Clone, Copy, Debug, Default, Serialize, Deserialize, PartialEq, Eq, JsonSchema)]
142#[serde(rename_all = "snake_case")]
143pub enum CursorShape {
144    /// Cursor is a block like `█`.
145    #[default]
146    Block,
147    /// Cursor is an underscore like `_`.
148    Underline,
149    /// Cursor is a vertical bar like `⎸`.
150    Bar,
151    /// Cursor is a hollow box like `▯`.
152    Hollow,
153}
154
155impl From<settings::CursorShapeContent> for CursorShape {
156    fn from(value: settings::CursorShapeContent) -> Self {
157        match value {
158            settings::CursorShapeContent::Block => CursorShape::Block,
159            settings::CursorShapeContent::Underline => CursorShape::Underline,
160            settings::CursorShapeContent::Bar => CursorShape::Bar,
161            settings::CursorShapeContent::Hollow => CursorShape::Hollow,
162        }
163    }
164}
165
Served at tenant.openagents/omega Member data and write actions are omitted.