Skip to main content

terminal_profiles/
lib.rs

1use serde::{Deserialize, Serialize};
2use std::collections::HashMap;
3
4
5#[derive(Debug, Clone, Serialize, Deserialize)]
6#[serde(rename_all = "camelCase")]
7pub struct WindowsTerminalSettings {
8    pub default_profile: String,
9    pub always_on_top: Option<bool>,
10    pub always_show_tabs: Option<bool>,
11    pub copy_on_select: Option<bool>,
12    pub focus_follow_mouse: Option<bool>,
13    pub copy_formatting: Option<CopyFormat>,
14    pub disable_animations: Option<bool>,
15    pub large_paste_warning: Option<bool>,
16    pub multi_line_paste_warning: Option<bool>,
17    pub startup_actions: Option<String>,
18    pub initial_cols: Option<i32>,
19    pub initial_rows: Option<i32>,
20    pub initial_position: Option<String>,
21    pub launch_mode: Option<LaunchMode>,
22    pub first_window_preference: Option<FirstWindowPreference>,
23    pub show_tabs_in_titlebar: Option<bool>,
24    pub show_terminal_title_in_titlebar: Option<bool>,
25    pub tab_width_mode: Option<TabWidthMode>,
26    pub word_delimiters: Option<String>,
27    pub confirm_close_all_tabs: Option<bool>,
28    pub tab_switcher_mode: Option<TabSwitcherMode>,
29    pub windowing_behavior: Option<WindowingBehavior>,
30    pub new_tab_position: Option<NewTabPosition>,
31    pub auto_hide_window: Option<bool>,
32
33    pub theme: Option<ThemeValue>,
34    pub themes: Option<Vec<Theme>>,
35
36    pub actions: Option<Vec<Action>>,
37    pub keybindings: Option<Vec<Keybinding>>,
38
39    pub new_tab_menu: Option<Vec<NewTabMenuEntry>>,
40
41    pub profiles: ProfilesValue,
42
43    pub schemes: Vec<ColorScheme>,
44}
45
46
47#[derive(Debug, Clone, Serialize, Deserialize)]
48#[serde(untagged)]
49pub enum ProfilesValue {
50    List(Vec<Profile>),
51    // TODO: reduce enum size
52    Object(Box<ProfilesObject>),
53}
54
55
56#[derive(Debug, Clone, Serialize, Deserialize)]
57pub struct ProfilesObject {
58    pub list: Vec<Profile>,
59    pub defaults: Option<Profile>,
60}
61#[derive(Debug, Clone, Serialize, Deserialize)]
62pub struct Profile {
63    #[serde(skip_serializing_if = "Option::is_none")]
64    pub guid: Option<String>,
65    #[serde(skip_serializing_if = "Option::is_none")]
66    pub name: Option<String>,
67    #[serde(skip_serializing_if = "Option::is_none")]
68    pub hidden: Option<bool>,
69    #[serde(skip_serializing_if = "Option::is_none")]
70    pub source: Option<String>,
71    #[serde(skip_serializing_if = "Option::is_none")]
72    pub commandline: Option<String>,
73    #[serde(skip_serializing_if = "Option::is_none")]
74    pub starting_directory: Option<String>,
75    #[serde(skip_serializing_if = "Option::is_none")]
76    pub tab_title: Option<String>,
77    #[serde(skip_serializing_if = "Option::is_none")]
78    pub suppress_application_title: Option<bool>,
79    #[serde(skip_serializing_if = "Option::is_none")]
80    pub icon: Option<String>,
81    #[serde(skip_serializing_if = "Option::is_none")]
82    pub tab_color: Option<String>,
83    #[serde(skip_serializing_if = "Option::is_none")]
84    pub close_on_exit: Option<CloseOnExit>,
85    #[serde(skip_serializing_if = "Option::is_none")]
86    pub background: Option<String>,
87    #[serde(skip_serializing_if = "Option::is_none")]
88    pub background_image: Option<String>,
89    #[serde(skip_serializing_if = "Option::is_none")]
90    pub background_image_alignment: Option<BackgroundImageAlignment>,
91    #[serde(skip_serializing_if = "Option::is_none")]
92    pub background_image_opacity: Option<f64>,
93    #[serde(skip_serializing_if = "Option::is_none")]
94    pub background_image_stretch_mode: Option<BackgroundImageStretchMode>,
95    #[serde(skip_serializing_if = "Option::is_none")]
96    pub cursor_color: Option<String>,
97    #[serde(skip_serializing_if = "Option::is_none")]
98    pub cursor_shape: Option<CursorShape>,
99    #[serde(skip_serializing_if = "Option::is_none")]
100    pub cursor_height: Option<i32>,
101    #[serde(skip_serializing_if = "Option::is_none")]
102    pub foreground: Option<String>,
103    #[serde(skip_serializing_if = "Option::is_none")]
104    pub selection_background: Option<String>,
105    #[serde(skip_serializing_if = "Option::is_none")]
106    pub color_scheme: Option<ColorSchemeValue>,
107    #[serde(skip_serializing_if = "Option::is_none")]
108    pub opacity: Option<f64>,
109    #[serde(skip_serializing_if = "Option::is_none")]
110    pub use_acrylic: Option<bool>,
111    #[serde(skip_serializing_if = "Option::is_none")]
112    pub padding: Option<String>,
113    #[serde(skip_serializing_if = "Option::is_none")]
114    pub font: Option<FontConfig>,
115    #[serde(skip_serializing_if = "Option::is_none")]
116    pub font_face: Option<String>,
117    #[serde(skip_serializing_if = "Option::is_none")]
118    pub font_size: Option<f64>,
119    #[serde(skip_serializing_if = "Option::is_none")]
120    pub font_weight: Option<FontWeight>,
121    #[serde(skip_serializing_if = "Option::is_none")]
122    pub antialiasing_mode: Option<AntialiasingMode>,
123    #[serde(skip_serializing_if = "Option::is_none")]
124    pub history_size: Option<i32>,
125    #[serde(skip_serializing_if = "Option::is_none")]
126    pub snap_on_input: Option<bool>,
127    #[serde(skip_serializing_if = "Option::is_none")]
128    pub alt_gr_aliasing: Option<bool>,
129    #[serde(skip_serializing_if = "Option::is_none")]
130    pub bell_style: Option<BellStyle>,
131    #[serde(skip_serializing_if = "Option::is_none")]
132    pub bell_sound: Option<BellSound>,
133    #[serde(skip_serializing_if = "Option::is_none")]
134    pub intense_text_style: Option<IntenseTextStyle>,
135    #[serde(skip_serializing_if = "Option::is_none")]
136    pub adjust_indistinguishable_colors: Option<AdjustIndistinguishableColors>,
137    #[serde(skip_serializing_if = "Option::is_none")]
138    pub scrollbar_state: Option<ScrollbarState>,
139    #[serde(skip_serializing_if = "Option::is_none")]
140    pub path_translation_style: Option<PathTranslationStyle>,
141    #[serde(skip_serializing_if = "Option::is_none")]
142    pub elevate: Option<bool>,
143    #[serde(skip_serializing_if = "Option::is_none")]
144    pub environment: Option<HashMap<String, String>>,
145    #[serde(skip_serializing_if = "Option::is_none")]
146    pub auto_mark_prompts: Option<bool>,
147    #[serde(skip_serializing_if = "Option::is_none")]
148    pub show_marks_on_scrollbar: Option<bool>,
149    #[serde(skip_serializing_if = "Option::is_none")]
150    pub unfocused_appearance: Option<AppearanceConfig>,
151}
152
153
154#[derive(Debug, Clone, Serialize, Deserialize)]
155pub struct FontConfig {
156    pub face: Option<String>,
157    pub size: Option<f64>,
158    pub weight: Option<FontWeight>,
159    pub features: Option<HashMap<String, i32>>,
160    pub axes: Option<HashMap<String, f64>>,
161    pub cell_width: Option<String>,
162    pub cell_height: Option<String>,
163}
164
165
166#[derive(Debug, Clone, Serialize, Deserialize)]
167pub struct AppearanceConfig {
168    pub color_scheme: Option<ColorSchemeValue>,
169    pub foreground: Option<String>,
170    pub background: Option<String>,
171    pub selection_background: Option<String>,
172    pub cursor_color: Option<String>,
173    pub cursor_shape: Option<CursorShape>,
174    pub cursor_height: Option<i32>,
175    pub background_image: Option<String>,
176    pub background_image_opacity: Option<f64>,
177    pub background_image_stretch_mode: Option<BackgroundImageStretchMode>,
178    pub background_image_alignment: Option<BackgroundImageAlignment>,
179    pub intense_text_style: Option<IntenseTextStyle>,
180    pub adjust_indistinguishable_colors: Option<AdjustIndistinguishableColors>,
181    pub use_acrylic: Option<bool>,
182    pub opacity: Option<f64>,
183}
184
185
186#[derive(Debug, Clone, Serialize, Deserialize)]
187pub struct ColorScheme {
188    pub name: String,
189    pub background: Option<String>,
190    pub black: Option<String>,
191    pub blue: Option<String>,
192    pub bright_black: Option<String>,
193    pub bright_blue: Option<String>,
194    pub bright_cyan: Option<String>,
195    pub bright_green: Option<String>,
196    pub bright_purple: Option<String>,
197    pub bright_red: Option<String>,
198    pub bright_white: Option<String>,
199    pub bright_yellow: Option<String>,
200    pub cursor_color: Option<String>,
201    pub cyan: Option<String>,
202    pub foreground: Option<String>,
203    pub green: Option<String>,
204    pub purple: Option<String>,
205    pub red: Option<String>,
206    pub selection_background: Option<String>,
207    pub white: Option<String>,
208    pub yellow: Option<String>,
209}
210
211
212#[derive(Debug, Clone, Serialize, Deserialize)]
213#[serde(untagged)]
214pub enum ColorSchemeValue {
215    String(String),
216    SchemePair(SchemePair),
217}
218
219
220#[derive(Debug, Clone, Serialize, Deserialize)]
221pub struct SchemePair {
222    pub light: Option<String>,
223    pub dark: Option<String>,
224}
225
226
227#[derive(Debug, Clone, Serialize, Deserialize)]
228pub struct Theme {
229    pub name: String,
230    pub tab: Option<TabTheme>,
231    pub tab_row: Option<TabRowTheme>,
232    pub window: Option<WindowTheme>,
233}
234
235
236#[derive(Debug, Clone, Serialize, Deserialize)]
237pub struct TabTheme {
238    pub background: Option<ThemeColor>,
239    pub unfocused_background: Option<ThemeColor>,
240    pub show_close_button: Option<ShowCloseButton>,
241    pub icon_style: Option<IconStyle>,
242}
243
244
245#[derive(Debug, Clone, Serialize, Deserialize)]
246pub struct TabRowTheme {
247    pub background: Option<ThemeColor>,
248    pub unfocused_background: Option<ThemeColor>,
249}
250
251
252#[derive(Debug, Clone, Serialize, Deserialize)]
253pub struct WindowTheme {
254    pub application_theme: Option<ApplicationTheme>,
255    pub use_mica: Option<bool>,
256    pub frame: Option<ThemeColor>,
257    pub unfocused_frame: Option<ThemeColor>,
258}
259
260
261#[derive(Debug, Clone, Serialize, Deserialize)]
262#[serde(untagged)]
263pub enum ThemeColor {
264    String(String),
265    Special(SpecialThemeColor),
266}
267
268
269#[derive(Debug, Clone, Serialize, Deserialize)]
270pub struct Action {
271    pub command: Option<CommandValue>,
272    pub icon: Option<String>,
273    pub name: Option<CommandName>,
274    pub id: Option<String>,
275    pub iterate_on: Option<IterateOn>,
276    pub commands: Option<Vec<SubCommand>>,
277}
278
279
280#[derive(Debug, Clone, Serialize, Deserialize)]
281pub struct SubCommand {
282    pub command: Option<CommandValue>,
283    pub name: Option<CommandName>,
284}
285
286
287#[derive(Debug, Clone, Serialize, Deserialize)]
288pub struct Keybinding {
289    pub id: Option<String>,
290    pub keys: KeyChordValue,
291}
292
293
294#[derive(Debug, Clone, Serialize, Deserialize)]
295#[serde(untagged)]
296pub enum NewTabMenuEntry {
297    Folder(FolderEntry),
298    Separator(SeparatorEntry),
299    Profile(ProfileEntry),
300    MatchProfiles(MatchProfilesEntry),
301    RemainingProfiles(RemainingProfilesEntry),
302    Action(ActionEntry),
303}
304
305
306#[derive(Debug, Clone, Serialize, Deserialize)]
307pub struct FolderEntry {
308    #[serde(rename = "type")]
309    pub entry_type: String,
310    pub name: Option<String>,
311    pub icon: Option<String>,
312    pub entries: Vec<NewTabMenuEntry>,
313    pub inline: Option<FolderEntryInlining>,
314    pub allow_empty: Option<bool>,
315}
316
317
318#[derive(Debug, Clone, Serialize, Deserialize)]
319pub struct SeparatorEntry {
320    #[serde(rename = "type")]
321    pub entry_type: String,
322}
323
324
325#[derive(Debug, Clone, Serialize, Deserialize)]
326pub struct ProfileEntry {
327    #[serde(rename = "type")]
328    pub entry_type: String,
329    pub profile: Option<String>,
330}
331
332
333#[derive(Debug, Clone, Serialize, Deserialize)]
334pub struct MatchProfilesEntry {
335    #[serde(rename = "type")]
336    pub entry_type: String,
337    pub name: Option<String>,
338    pub source: Option<String>,
339    pub commandline: Option<String>,
340}
341
342
343#[derive(Debug, Clone, Serialize, Deserialize)]
344pub struct RemainingProfilesEntry {
345    #[serde(rename = "type")]
346    pub entry_type: String,
347}
348
349
350#[derive(Debug, Clone, Serialize, Deserialize)]
351pub struct ActionEntry {
352    #[serde(rename = "type")]
353    pub entry_type: String,
354    pub id: Option<String>,
355}
356
357// ========== 枚举类型 ==========
358
359
360#[derive(Debug, Clone, Serialize, Deserialize)]
361#[serde(untagged)]
362pub enum CopyFormat {
363    Boolean(bool),
364    Array(Vec<CopyFormatType>),
365    String(CopyFormatType),
366}
367
368
369#[derive(Debug, Clone, Serialize, Deserialize)]
370#[serde(rename_all = "camelCase")]
371pub enum LaunchMode {
372    Fullscreen,
373    Maximized,
374    Default,
375    Focus,
376    MaximizedFocus,
377}
378
379
380#[derive(Debug, Clone, Serialize, Deserialize)]
381#[serde(rename_all = "camelCase")]
382pub enum FirstWindowPreference {
383    DefaultProfile,
384    PersistedWindowLayout,
385}
386
387
388#[derive(Debug, Clone, Serialize, Deserialize)]
389#[serde(rename_all = "camelCase")]
390pub enum TabWidthMode {
391    Equal,
392    TitleLength,
393    Compact,
394}
395
396
397#[derive(Debug, Clone, Serialize, Deserialize)]
398#[serde(rename_all = "camelCase")]
399pub enum TabSwitcherMode {
400    Mru,
401    InOrder,
402    Disabled,
403}
404
405
406#[derive(Debug, Clone, Serialize, Deserialize)]
407#[serde(rename_all = "camelCase")]
408pub enum WindowingBehavior {
409    UseNew,
410    UseExisting,
411    UseAnyExisting,
412}
413
414
415#[derive(Debug, Clone, Serialize, Deserialize)]
416#[serde(rename_all = "camelCase")]
417pub enum NewTabPosition {
418    AfterLastTab,
419    AfterCurrentTab,
420}
421
422
423#[derive(Debug, Clone, Serialize, Deserialize)]
424#[serde(rename_all = "camelCase")]
425pub enum CloseOnExit {
426    Never,
427    Graceful,
428    Always,
429    Automatic,
430}
431
432
433#[derive(Debug, Clone, Serialize, Deserialize)]
434#[serde(rename_all = "camelCase")]
435pub enum BackgroundImageAlignment {
436    Bottom,
437    BottomLeft,
438    BottomRight,
439    Center,
440    Left,
441    Right,
442    Top,
443    TopLeft,
444    TopRight,
445}
446
447
448#[derive(Debug, Clone, Serialize, Deserialize)]
449#[serde(rename_all = "camelCase")]
450pub enum BackgroundImageStretchMode {
451    Fill,
452    None,
453    Uniform,
454    UniformToFill,
455}
456
457
458#[derive(Debug, Clone, Serialize, Deserialize)]
459#[serde(rename_all = "camelCase")]
460pub enum CursorShape {
461    Bar,
462    DoubleUnderscore,
463    EmptyBox,
464    FilledBox,
465    Underscore,
466    Vintage,
467}
468
469
470#[derive(Debug, Clone, Serialize, Deserialize)]
471#[serde(untagged)]
472pub enum FontWeight {
473    String(FontWeightString),
474    Integer(i32),
475}
476
477
478#[derive(Debug, Clone, Serialize, Deserialize)]
479#[serde(rename_all = "camelCase")]
480pub enum AntialiasingMode {
481    Grayscale,
482    Cleartype,
483    Aliased,
484}
485
486
487#[derive(Debug, Clone, Serialize, Deserialize)]
488#[serde(untagged)]
489pub enum BellStyle {
490    Boolean(bool),
491    Array(Vec<BellStyleType>),
492    String(BellStyleType),
493}
494
495
496#[derive(Debug, Clone, Serialize, Deserialize)]
497#[serde(untagged)]
498pub enum BellSound {
499    String(String),
500    Array(Vec<String>),
501}
502
503
504#[derive(Debug, Clone, Serialize, Deserialize)]
505#[serde(rename_all = "camelCase")]
506pub enum IntenseTextStyle {
507    None,
508    Bold,
509    Bright,
510    All,
511}
512
513
514#[derive(Debug, Clone, Serialize, Deserialize)]
515#[serde(rename_all = "camelCase")]
516pub enum AdjustIndistinguishableColors {
517    Never,
518    Indexed,
519    Always,
520}
521
522
523#[derive(Debug, Clone, Serialize, Deserialize)]
524#[serde(rename_all = "camelCase")]
525pub enum ScrollbarState {
526    Visible,
527    Hidden,
528    Always,
529}
530
531
532#[derive(Debug, Clone, Serialize, Deserialize)]
533#[serde(rename_all = "camelCase")]
534pub enum PathTranslationStyle {
535    None,
536    Wsl,
537    Cygwin,
538    Msys2,
539}
540
541
542#[derive(Debug, Clone, Serialize, Deserialize)]
543#[serde(untagged)]
544pub enum ThemeValue {
545    String(String),
546    ThemePair(ThemePair),
547}
548
549
550#[derive(Debug, Clone, Serialize, Deserialize)]
551pub struct ThemePair {
552    pub light: Option<String>,
553    pub dark: Option<String>,
554}
555
556
557#[derive(Debug, Clone, Serialize, Deserialize)]
558#[serde(untagged)]
559pub enum CommandValue {
560    String(ShortcutActionName),
561    Object(serde_json::Value), // 简化为通用对象
562}
563
564
565#[derive(Debug, Clone, Serialize, Deserialize)]
566#[serde(untagged)]
567pub enum CommandName {
568    String(String),
569    Object(CommandNameObject),
570}
571
572
573#[derive(Debug, Clone, Serialize, Deserialize)]
574pub struct CommandNameObject {
575    pub key: String,
576}
577
578
579#[derive(Debug, Clone, Serialize, Deserialize)]
580#[serde(untagged)]
581pub enum KeyChordValue {
582    Single(String),
583    Multiple(Vec<String>),
584}
585
586
587#[derive(Debug, Clone, Serialize, Deserialize)]
588#[serde(rename_all = "camelCase")]
589pub enum FolderEntryInlining {
590    Never,
591    Auto,
592}
593
594
595#[derive(Debug, Clone, Serialize, Deserialize)]
596#[serde(rename_all = "camelCase")]
597pub enum SpecialThemeColor {
598    Accent,
599    TerminalBackground,
600}
601
602
603#[derive(Debug, Clone, Serialize, Deserialize)]
604#[serde(rename_all = "camelCase")]
605pub enum ShowCloseButton {
606    Always,
607    Hover,
608    Never,
609    ActiveOnly,
610}
611
612
613#[derive(Debug, Clone, Serialize, Deserialize)]
614#[serde(rename_all = "camelCase")]
615pub enum IconStyle {
616    Default,
617    Hidden,
618    Monochrome,
619}
620
621
622#[derive(Debug, Clone, Serialize, Deserialize)]
623#[serde(rename_all = "camelCase")]
624pub enum ApplicationTheme {
625    Light,
626    Dark,
627    System,
628}
629
630
631#[derive(Debug, Clone, Serialize, Deserialize)]
632#[serde(rename_all = "camelCase")]
633pub enum IterateOn {
634    Profiles,
635    Schemes,
636}
637
638
639#[derive(Debug, Clone, Serialize, Deserialize)]
640#[serde(rename_all = "lowercase")]
641pub enum CopyFormatType {
642    Html,
643    Rtf,
644    All,
645    None,
646}
647
648
649#[derive(Debug, Clone, Serialize, Deserialize)]
650#[serde(rename_all = "camelCase")]
651pub enum FontWeightString {
652    Thin,
653    ExtraLight,
654    Light,
655    SemiLight,
656    Normal,
657    Medium,
658    SemiBold,
659    Bold,
660    ExtraBold,
661    Black,
662    ExtraBlack,
663}
664
665
666#[derive(Debug, Clone, Serialize, Deserialize)]
667#[serde(rename_all = "lowercase")]
668pub enum BellStyleType {
669    Audible,
670    Window,
671    Taskbar,
672    All,
673    None,
674}
675
676
677#[derive(Debug, Clone, Serialize, Deserialize)]
678#[serde(rename_all = "camelCase")]
679pub enum ShortcutActionName {
680    AddMark,
681    AdjustFontSize,
682    AdjustOpacity,
683    ClearAllMarks,
684    ClearBuffer,
685    ClearMark,
686    CloseOtherPanes,
687    CloseOtherTabs,
688    ClosePane,
689    CloseTab,
690    CloseTabsAfter,
691    CloseWindow,
692    CommandPalette,
693    Copy,
694    DuplicateTab,
695    ExpandSelectionToWord,
696    #[serde(rename = "experimental.colorSelection")]
697    ExperimentalColorSelection,
698    ExportBuffer,
699    Find,
700    FindMatch,
701    FocusPane,
702    GlobalSummon,
703    IdentifyWindow,
704    IdentifyWindows,
705    MarkMode,
706    MoveFocus,
707    MovePane,
708    MoveTab,
709    MultipleActions,
710    NewTab,
711    NewWindow,
712    NextTab,
713    OpenAbout,
714    OpenNewTabDropdown,
715    OpenSettings,
716    OpenSystemMenu,
717    OpenTabColorPicker,
718    OpenTabRenamer,
719    OpenWindowRenamer,
720    Paste,
721    PrevTab,
722    QuakeMode,
723    Quit,
724    RenameTab,
725    RenameWindow,
726    ResetFontSize,
727    ResizePane,
728    RestoreLastClosed,
729    ScrollDown,
730    ScrollDownPage,
731    ScrollToBottom,
732    ScrollToMark,
733    ScrollToTop,
734    ScrollUp,
735    ScrollUpPage,
736    SearchWeb,
737    SelectAll,
738    SendInput,
739    SetColorScheme,
740    SetFocusMode,
741    SetFullScreen,
742    SetMaximized,
743    SetTabColor,
744    ShowSuggestions,
745    SplitPane,
746    SwapPane,
747    SwitchSelectionEndpoint,
748    SwitchToTab,
749    TabSearch,
750    ToggleAlwaysOnTop,
751    ToggleBlockSelection,
752    ToggleFocusMode,
753    ToggleFullscreen,
754    TogglePaneZoom,
755    ToggleReadOnlyMode,
756    ToggleShaderEffects,
757    ToggleSplitOrientation,
758    Wt,
759    Unbound,
760}