Skip to repository content

tenant.openagents/omega

No repository description is available.

OpenAgents Git authority 2026-07-28T01:50:08.225Z 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

base_keymap_setting.rs

144 lines · 5.1 KB · rust
1use std::fmt::{Display, Formatter};
2
3use crate::{self as settings, settings_content::BaseKeymapContent};
4use schemars::JsonSchema;
5use serde::{Deserialize, Serialize};
6use settings::{RegisterSetting, Settings};
7
8/// Base key bindings scheme. Base keymaps can be overridden with user keymaps.
9///
10/// Default: Zed
11#[derive(
12    Copy, Clone, Debug, Serialize, Deserialize, JsonSchema, PartialEq, Eq, Default, RegisterSetting,
13)]
14pub enum BaseKeymap {
15    #[default]
16    Zed,
17    VSCode,
18    JetBrains,
19    SublimeText,
20    Atom,
21    TextMate,
22    Emacs,
23    Cursor,
24    None,
25}
26
27impl From<BaseKeymapContent> for BaseKeymap {
28    fn from(value: BaseKeymapContent) -> Self {
29        match value {
30            BaseKeymapContent::Zed => Self::Zed,
31            BaseKeymapContent::VSCode => Self::VSCode,
32            BaseKeymapContent::JetBrains => Self::JetBrains,
33            BaseKeymapContent::SublimeText => Self::SublimeText,
34            BaseKeymapContent::Atom => Self::Atom,
35            BaseKeymapContent::TextMate => Self::TextMate,
36            BaseKeymapContent::Emacs => Self::Emacs,
37            BaseKeymapContent::Cursor => Self::Cursor,
38            BaseKeymapContent::None => Self::None,
39        }
40    }
41}
42impl Into<BaseKeymapContent> for BaseKeymap {
43    fn into(self) -> BaseKeymapContent {
44        match self {
45            BaseKeymap::Zed => BaseKeymapContent::Zed,
46            BaseKeymap::VSCode => BaseKeymapContent::VSCode,
47            BaseKeymap::JetBrains => BaseKeymapContent::JetBrains,
48            BaseKeymap::SublimeText => BaseKeymapContent::SublimeText,
49            BaseKeymap::Atom => BaseKeymapContent::Atom,
50            BaseKeymap::TextMate => BaseKeymapContent::TextMate,
51            BaseKeymap::Emacs => BaseKeymapContent::Emacs,
52            BaseKeymap::Cursor => BaseKeymapContent::Cursor,
53            BaseKeymap::None => BaseKeymapContent::None,
54        }
55    }
56}
57
58impl Display for BaseKeymap {
59    fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
60        match self {
61            BaseKeymap::Zed => write!(f, "Zed"),
62            BaseKeymap::VSCode => write!(f, "VS Code"),
63            BaseKeymap::JetBrains => write!(f, "JetBrains"),
64            BaseKeymap::SublimeText => write!(f, "Sublime Text"),
65            BaseKeymap::Atom => write!(f, "Atom"),
66            BaseKeymap::TextMate => write!(f, "TextMate"),
67            BaseKeymap::Emacs => write!(f, "Emacs (beta)"),
68            BaseKeymap::Cursor => write!(f, "Cursor (beta)"),
69            BaseKeymap::None => write!(f, "None"),
70        }
71    }
72}
73
74impl BaseKeymap {
75    #[cfg(target_os = "macos")]
76    pub const OPTIONS: [(&'static str, Self); 8] = [
77        ("Zed (Default)", Self::Zed),
78        ("VS Code", Self::VSCode),
79        ("Atom", Self::Atom),
80        ("JetBrains", Self::JetBrains),
81        ("Sublime Text", Self::SublimeText),
82        ("Emacs (beta)", Self::Emacs),
83        ("TextMate", Self::TextMate),
84        ("Cursor", Self::Cursor),
85    ];
86
87    #[cfg(not(target_os = "macos"))]
88    pub const OPTIONS: [(&'static str, Self); 7] = [
89        ("Zed (Default)", Self::Zed),
90        ("VS Code", Self::VSCode),
91        ("Atom", Self::Atom),
92        ("JetBrains", Self::JetBrains),
93        ("Sublime Text", Self::SublimeText),
94        ("Emacs (beta)", Self::Emacs),
95        ("Cursor", Self::Cursor),
96    ];
97
98    pub fn asset_path(&self) -> Option<&'static str> {
99        #[cfg(target_os = "macos")]
100        match self {
101            BaseKeymap::JetBrains => Some("keymaps/macos/jetbrains.json"),
102            BaseKeymap::SublimeText => Some("keymaps/macos/sublime_text.json"),
103            BaseKeymap::Atom => Some("keymaps/macos/atom.json"),
104            BaseKeymap::TextMate => Some("keymaps/macos/textmate.json"),
105            BaseKeymap::Emacs => Some("keymaps/macos/emacs.json"),
106            BaseKeymap::Cursor => Some("keymaps/macos/cursor.json"),
107            BaseKeymap::VSCode => Some("keymaps/macos/vscode.json"),
108            BaseKeymap::Zed => None,
109            BaseKeymap::None => None,
110        }
111
112        #[cfg(not(target_os = "macos"))]
113        match self {
114            BaseKeymap::JetBrains => Some("keymaps/linux/jetbrains.json"),
115            BaseKeymap::SublimeText => Some("keymaps/linux/sublime_text.json"),
116            BaseKeymap::Atom => Some("keymaps/linux/atom.json"),
117            BaseKeymap::Emacs => Some("keymaps/linux/emacs.json"),
118            BaseKeymap::Cursor => Some("keymaps/linux/cursor.json"),
119            BaseKeymap::TextMate => None,
120            BaseKeymap::VSCode => Some("keymaps/linux/vscode.json"),
121            BaseKeymap::Zed => None,
122            BaseKeymap::None => None,
123        }
124    }
125
126    pub fn names() -> impl Iterator<Item = &'static str> {
127        Self::OPTIONS.iter().map(|(name, _)| *name)
128    }
129
130    pub fn from_names(option: &str) -> BaseKeymap {
131        Self::OPTIONS
132            .iter()
133            .copied()
134            .find_map(|(name, value)| (name == option).then_some(value))
135            .unwrap_or_default()
136    }
137}
138
139impl Settings for BaseKeymap {
140    fn from_settings(s: &crate::settings_content::SettingsContent) -> Self {
141        s.base_keymap.unwrap().into()
142    }
143}
144
Served at tenant.openagents/omega Member data and write actions are omitted.