Simplify settings (#3082)

This commit is contained in:
MinusGix 2024-03-17 16:05:26 -05:00 committed by GitHub
parent a7b76414e4
commit b9d21e6003
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
6 changed files with 168 additions and 333 deletions

View File

@ -4,6 +4,140 @@
name = "Lapce Codicons"
[icon-theme.ui]
"logo" = "lapce_logo.svg"
"menu" = "menu.svg"
"link" = "link.svg"
"error" = "error.svg"
"add" = "add.svg"
"close" = "close.svg"
"remote" = "remote.svg"
"unsaved" = "circle-filled.svg"
"warning" = "warning.svg"
"problem" = "problem.svg"
"debug" = "debug.svg"
"debug_breakpoint" = "circle-filled.svg"
"debug_alt" = "debug-alt.svg"
"debug_small" = "debug-alt-small.svg"
"debug_restart" = "debug-restart.svg"
"debug_continue" = "debug-continue.svg"
"debug_step_over" = "debug-step-over.svg"
"debug_step_into" = "debug-step-into.svg"
"debug_step_out" = "debug-step-out.svg"
"debug_pause" = "debug-pause.svg"
"debug_stop" = "debug-stop.svg"
"debug_console" = "debug-console.svg"
"debug_disconnect" = "debug-disconnect.svg"
"start" = "debug-start.svg"
"run_errors" = "run-errors.svg"
"settings" = "settings-gear.svg"
"terminal" = "terminal.svg"
"lightbulb" = "lightbulb.svg"
"extensions" = "extensions.svg"
"keyboard" = "keyboard.svg"
"breadcrumb_separator" = "chevron-right.svg"
"symbol_color" = "symbol-color.svg"
"window.close" = "chrome-close.svg"
"window.restore" = "chrome-restore.svg"
"window.maximize" = "chrome-maximize.svg"
"window.minimize" = "chrome-minimize.svg"
"file" = "file.svg"
"file_explorer" = "files.svg"
"file_picker_up" = "arrow-up.svg"
"image_loading" = "refresh.svg"
"image_error" = "error.svg"
"scm.icon" = "source-control.svg"
"scm.diff.modified" = "diff-modified.svg"
"scm.diff.added" = "diff-added.svg"
"scm.diff.removed" = "diff-removed.svg"
"scm.diff.renamed" = "diff-renamed.svg"
"scm.change.add" = "add.svg"
"scm.change.remove" = "remove.svg"
"palette.menu" = "chevron-down.svg"
"fold" = "fold.svg"
"fold.up" = "fold-up.svg"
"fold.down" = "fold-down.svg"
"dropdown.arrow" = "chevron-down.svg"
"location.forward" = "arrow-right.svg"
"location.backward" = "arrow-left.svg"
"item.opened" = "chevron-down.svg"
"item.closed" = "chevron-right.svg"
"directory.closed" = "folder.svg"
"directory.opened" = "folder-opened.svg"
"panel.restore" = "chevron-down.svg"
"panel.maximise" = "chevron-right.svg"
"split.horizontal" = "split-horizontal.svg"
"tab.previous" = "chevron-left.svg"
"tab.next" = "chevron-right.svg"
"sidebar.left.on" = "layout-sidebar-left.svg"
"sidebar.left.off" = "layout-sidebar-left-off.svg"
"sidebar.right.on" = "layout-sidebar-right.svg"
"sidebar.right.off" = "layout-sidebar-right-off.svg"
"layout.panel.on" = "layout-panel.svg"
"layout.panel.off" = "layout-panel-off.svg"
"search.icon" = "search.svg"
"search.clear" = "close.svg"
"search.forward" = "arrow-down.svg"
"search.backward" = "arrow-up.svg"
"search.case_sensitive" = "case-sensitive.svg"
"search.whole_word" = "whole-word.svg"
"search.regex" = "regex.svg"
"search.replace" = "replace.svg"
"search.replace_all" = "replace-all.svg"
"symbol_kind.array" = "symbol-array.svg"
"symbol_kind.boolean" = "symbol-boolean.svg"
"symbol_kind.class" = "symbol-class.svg"
"symbol_kind.constant" = "symbol-constant.svg"
"symbol_kind.enum_member" = "symbol-enum-member.svg"
"symbol_kind.enum" = "symbol-enum.svg"
"symbol_kind.event" = "symbol-event.svg"
"symbol_kind.field" = "symbol-field.svg"
"symbol_kind.file" = "symbol-file.svg"
"symbol_kind.function" = "symbol-method.svg"
"symbol_kind.interface" = "symbol-interface.svg"
"symbol_kind.key" = "symbol-key.svg"
"symbol_kind.method" = "symbol-method.svg"
"symbol_kind.namespace" = "symbol-namespace.svg"
"symbol_kind.number" = "symbol-numeric.svg"
"symbol_kind.object" = "symbol-namespace.svg"
"symbol_kind.operator" = "symbol-operator.svg"
"symbol_kind.property" = "symbol-property.svg"
"symbol_kind.string" = "symbol-string.svg"
"symbol_kind.struct" = "symbol-structure.svg"
"symbol_kind.type_parameter" = "symbol-parameter.svg"
"symbol_kind.variable" = "symbol-variable.svg"
"completion_item_kind.class" = "symbol-class.svg"
"completion_item_kind.constant" = "symbol-constant.svg"
"completion_item_kind.enum_member" = "symbol-enum-member.svg"
"completion_item_kind.enum" = "symbol-enum.svg"
"completion_item_kind.field" = "symbol-field.svg"
"completion_item_kind.function" = "symbol-method.svg"
"completion_item_kind.interface" = "symbol-interface.svg"
"completion_item_kind.keyword" = "symbol-keyword.svg"
"completion_item_kind.method" = "symbol-method.svg"
"completion_item_kind.module" = "symbol-namespace.svg"
"completion_item_kind.property" = "symbol-property.svg"
"completion_item_kind.snippet" = "symbol-snippet.svg"
"completion_item_kind.string" = "symbol-string.svg"
"completion_item_kind.struct" = "symbol-structure.svg"
"completion_item_kind.variable" = "symbol-variable.svg"
[icon-theme.foldername]

View File

@ -89,321 +89,3 @@ hover-font-size = 0
trim-search-results-whitespace = true
list-line-height = 25
tab-close-button = "Right"
[color-theme]
name = ""
[color-theme.base]
white = "#ABB2BF"
black = "#282C34"
grey = "#3E4451"
blue = "#61AFEF"
red = "#E06C75"
yellow = "#E5C07B"
orange = "#D19A66"
green = "#98C379"
purple = "#C678DD"
cyan = "#56B6C2"
magenta = "#C678DD"
[color-theme.syntax]
"comment" = "#5C6370"
"constant" = "$yellow"
"type" = "$yellow"
"typeAlias" = "$yellow"
"number" = "$yellow"
"enum" = "$yellow"
"struct" = "$yellow"
"structure" = "$yellow"
"interface" = "$yellow"
"attribute" = "$yellow"
"constructor" = "$yellow"
"function" = "$blue"
"method" = "$blue"
"function.method" = "$blue"
"keyword" = "$purple"
"keyword.control" = "$purple"
"selfKeyword" = "$purple"
"field" = "$red"
"property" = "$red"
"enumMember" = "$red"
"enum-member" = "$red"
"variable.other.member" = "$red"
"string" = "$green"
"type.builtin" = "$cyan"
"builtinType" = "$cyan"
"escape" = "$cyan"
"embedded" = "$cyan"
"symbol" = "$yellow"
[color-theme.ui]
"lapce.error" = "$red"
"lapce.warn" = "$yellow"
"lapce.dropdown_shadow" = "#000000"
"lapce.border" = "#000000"
"lapce.scroll_bar" = "#3E4451BB"
"lapce.button.primary.background" = "#50a14f"
"lapce.button.primary.foreground" = "$black"
# tab
"lapce.tab.active.background" = "$black"
"lapce.tab.active.foreground" = "$white"
"lapce.tab.active.underline" = "#528BFF"
"lapce.tab.inactive.background" = "#21252b"
"lapce.tab.inactive.foreground" = "$white"
"lapce.tab.inactive.underline" = "#528BFF77"
"lapce.tab.separator" = "#000000"
"lapce.icon.active" = "$white"
"lapce.icon.inactive" = "#5C6370"
"lapce.remote.icon" = "$black"
"lapce.remote.local" = "#4078F2"
"lapce.remote.connected" = "#50A14F"
"lapce.remote.connecting" = "#C18401"
"lapce.remote.disconnected" = "#E45649"
"lapce.plugin.name" = "#DDDDDD"
"lapce.plugin.description" = "$white"
"lapce.plugin.author" = "#B0B0B0"
"editor.background" = "$black"
"editor.foreground" = "$white"
"editor.dim" = "#5C6370"
"editor.focus" = "#CCCCCC"
"editor.caret" = "#528bFF"
"editor.selection" = "$grey"
"editor.current_line" = "#2C313C"
"editor.link" = "$blue"
"editor.visible_whitespace" = "#5C6370"
"editor.indent_guide" = "$grey"
"editor.drag_drop_background" = "#79c1fc55"
"editor.drag_drop_tab_background" = "#0b0e1455"
"editor.sticky_header_background" = "$black"
"inlay_hint.foreground" = "$white"
"inlay_hint.background" = "#528bFF88"
"error_lens.error.foreground" = "$red"
"error_lens.error.background" = "#E06C7520"
"error_lens.warning.foreground" = "$yellow"
"error_lens.warning.background" = "#E5C07B20"
"error_lens.other.foreground" = "#5C6370"
"error_lens.other.background" = "#5C637020"
"completion_lens.foreground" = "#5C6370"
"source_control.added" = "#50A14FCC"
"source_control.removed" = "#FF5266CC"
"source_control.modified" = "#0184BCCC"
"tooltip.background" = "#4B4D51"
"tooltip.foreground" = "$white"
"palette.background" = "#21252B"
"palette.foreground" = "$white"
"palette.current.background" = "#2C313A"
"palette.current.foreground" = "$white"
"completion.background" = "#21252B"
"completion.current" = "#2C313A"
"hover.background" = "#21252B"
"activity.background" = "#21252B"
"activity.current" = "$black"
"debug.breakpoint" = "$red"
"debug.breakpoint.hover" = "#E06C7566"
"panel.background" = "#21252B"
"panel.foreground" = "$white"
"panel.foreground.dim" = "#5C6370"
"panel.current.background" = "#2C313A"
"panel.current.foreground" = "$white"
"panel.current.foreground.dim" = "#5C6370"
"panel.hovered.background" = "#343A45"
"panel.hovered.active.background" = "#5C6370"
"panel.hovered.foreground" = "$white"
"panel.hovered.foreground.dim" = "#5C6370"
"status.background" = "#21252B"
"status.foreground" = "$white"
"status.modal.normal.background" = "$blue"
"status.modal.normal.foreground" = "$black"
"status.modal.insert.background" = "$red"
"status.modal.insert.foreground" = "$black"
"status.modal.visual.background" = "$yellow"
"status.modal.visual.foreground" = "$black"
"status.modal.terminal.background" = "$purple"
"status.modal.terminal.foreground" = "$black"
"markdown.blockquote" = "#898989"
"terminal.cursor" = "$white"
"terminal.foreground" = "$white"
"terminal.background" = "$black"
"terminal.white" = "$white"
"terminal.black" = "$black"
"terminal.red" = "$red"
"terminal.blue" = "$blue"
"terminal.green" = "$green"
"terminal.yellow" = "$yellow"
"terminal.cyan" = "$cyan"
"terminal.magenta" = "$magenta"
"terminal.bright_white" = "#C8CCD4"
"terminal.bright_red" = "$red"
"terminal.bright_blue" = "$blue"
"terminal.bright_green" = "$green"
"terminal.bright_yellow" = "$yellow"
"terminal.bright_cyan" = "$cyan"
"terminal.bright_magenta" = "$magenta"
"terminal.bright_black" = "#545862"
[icon-theme]
name = ""
[icon-theme.ui]
"logo" = "lapce_logo.svg"
"menu" = "menu.svg"
"link" = "link.svg"
"error" = "error.svg"
"add" = "add.svg"
"close" = "close.svg"
"remote" = "remote.svg"
"unsaved" = "circle-filled.svg"
"warning" = "warning.svg"
"problem" = "problem.svg"
"debug" = "debug.svg"
"debug_breakpoint" = "circle-filled.svg"
"debug_alt" = "debug-alt.svg"
"debug_small" = "debug-alt-small.svg"
"debug_restart" = "debug-restart.svg"
"debug_continue" = "debug-continue.svg"
"debug_step_over" = "debug-step-over.svg"
"debug_step_into" = "debug-step-into.svg"
"debug_step_out" = "debug-step-out.svg"
"debug_pause" = "debug-pause.svg"
"debug_stop" = "debug-stop.svg"
"debug_console" = "debug-console.svg"
"debug_disconnect" = "debug-disconnect.svg"
"start" = "debug-start.svg"
"run_errors" = "run-errors.svg"
"settings" = "settings-gear.svg"
"terminal" = "terminal.svg"
"lightbulb" = "lightbulb.svg"
"extensions" = "extensions.svg"
"keyboard" = "keyboard.svg"
"breadcrumb_separator" = "chevron-right.svg"
"symbol_color" = "symbol-color.svg"
"window.close" = "chrome-close.svg"
"window.restore" = "chrome-restore.svg"
"window.maximize" = "chrome-maximize.svg"
"window.minimize" = "chrome-minimize.svg"
"file" = "file.svg"
"file_explorer" = "files.svg"
"file_picker_up" = "arrow-up.svg"
"image_loading" = "refresh.svg"
"image_error" = "error.svg"
"scm.icon" = "source-control.svg"
"scm.diff.modified" = "diff-modified.svg"
"scm.diff.added" = "diff-added.svg"
"scm.diff.removed" = "diff-removed.svg"
"scm.diff.renamed" = "diff-renamed.svg"
"scm.change.add" = "add.svg"
"scm.change.remove" = "remove.svg"
"palette.menu" = "chevron-down.svg"
"fold" = "fold.svg"
"fold.up" = "fold-up.svg"
"fold.down" = "fold-down.svg"
"dropdown.arrow" = "chevron-down.svg"
"location.forward" = "arrow-right.svg"
"location.backward" = "arrow-left.svg"
"item.opened" = "chevron-down.svg"
"item.closed" = "chevron-right.svg"
"directory.closed" = "folder.svg"
"directory.opened" = "folder-opened.svg"
"panel.restore" = "chevron-down.svg"
"panel.maximise" = "chevron-right.svg"
"split.horizontal" = "split-horizontal.svg"
"tab.previous" = "chevron-left.svg"
"tab.next" = "chevron-right.svg"
"sidebar.left.on" = "layout-sidebar-left.svg"
"sidebar.left.off" = "layout-sidebar-left-off.svg"
"sidebar.right.on" = "layout-sidebar-right.svg"
"sidebar.right.off" = "layout-sidebar-right-off.svg"
"layout.panel.on" = "layout-panel.svg"
"layout.panel.off" = "layout-panel-off.svg"
"search.icon" = "search.svg"
"search.clear" = "close.svg"
"search.forward" = "arrow-down.svg"
"search.backward" = "arrow-up.svg"
"search.case_sensitive" = "case-sensitive.svg"
"search.whole_word" = "whole-word.svg"
"search.regex" = "regex.svg"
"search.replace" = "replace.svg"
"search.replace_all" = "replace-all.svg"
"symbol_kind.array" = "symbol-array.svg"
"symbol_kind.boolean" = "symbol-boolean.svg"
"symbol_kind.class" = "symbol-class.svg"
"symbol_kind.constant" = "symbol-constant.svg"
"symbol_kind.enum_member" = "symbol-enum-member.svg"
"symbol_kind.enum" = "symbol-enum.svg"
"symbol_kind.event" = "symbol-event.svg"
"symbol_kind.field" = "symbol-field.svg"
"symbol_kind.file" = "symbol-file.svg"
"symbol_kind.function" = "symbol-method.svg"
"symbol_kind.interface" = "symbol-interface.svg"
"symbol_kind.key" = "symbol-key.svg"
"symbol_kind.method" = "symbol-method.svg"
"symbol_kind.namespace" = "symbol-namespace.svg"
"symbol_kind.number" = "symbol-numeric.svg"
"symbol_kind.object" = "symbol-namespace.svg"
"symbol_kind.operator" = "symbol-operator.svg"
"symbol_kind.property" = "symbol-property.svg"
"symbol_kind.string" = "symbol-string.svg"
"symbol_kind.struct" = "symbol-structure.svg"
"symbol_kind.type_parameter" = "symbol-parameter.svg"
"symbol_kind.variable" = "symbol-variable.svg"
"completion_item_kind.class" = "symbol-class.svg"
"completion_item_kind.constant" = "symbol-constant.svg"
"completion_item_kind.enum_member" = "symbol-enum-member.svg"
"completion_item_kind.enum" = "symbol-enum.svg"
"completion_item_kind.field" = "symbol-field.svg"
"completion_item_kind.function" = "symbol-method.svg"
"completion_item_kind.interface" = "symbol-interface.svg"
"completion_item_kind.keyword" = "symbol-keyword.svg"
"completion_item_kind.method" = "symbol-method.svg"
"completion_item_kind.module" = "symbol-namespace.svg"
"completion_item_kind.property" = "symbol-property.svg"
"completion_item_kind.snippet" = "symbol-snippet.svg"
"completion_item_kind.string" = "symbol-string.svg"
"completion_item_kind.struct" = "symbol-structure.svg"
"completion_item_kind.variable" = "symbol-variable.svg"
[icon-theme.foldername]
[icon-theme.filename]
[icon-theme.extension]

View File

@ -50,6 +50,21 @@
static DEFAULT_LAPCE_CONFIG: Lazy<LapceConfig> =
Lazy::new(LapceConfig::default_lapce_config);
// static DEFAULT_DARK_THEME_CONFIG = Lazy
/// The default theme is the dark theme.
static DEFAULT_DARK_THEME_COLOR_CONFIG: Lazy<ColorThemeConfig> = Lazy::new(|| {
let (_, theme) =
LapceConfig::load_color_theme_from_str(DEFAULT_DARK_THEME).unwrap();
theme.get::<ColorThemeConfig>("color-theme")
.expect("Failed to load default dark theme. This is likely due to a missing or misnamed field in dark-theme.toml")
});
static DEFAULT_ICON_THEME_CONFIG: Lazy<IconThemeConfig> = Lazy::new(|| {
let (_, theme) =
LapceConfig::load_icon_theme_from_str(DEFAULT_ICON_THEME).unwrap();
theme.get::<IconThemeConfig>("icon-theme")
.expect("Failed to load default icon theme. This is likely due to a missing or misnamed field in icon-theme.toml")
});
/// Used for creating a `DropdownData` for a setting
#[derive(Debug, Clone)]
pub struct DropdownInfo {
@ -67,15 +82,13 @@ pub struct LapceConfig {
pub ui: UIConfig,
pub editor: EditorConfig,
pub terminal: TerminalConfig,
#[serde(default)]
pub color_theme: ColorThemeConfig,
#[serde(default)]
pub icon_theme: IconThemeConfig,
#[serde(flatten)]
pub plugins: HashMap<String, HashMap<String, serde_json::Value>>,
#[serde(skip)]
pub default_color_theme: ColorThemeConfig,
#[serde(skip)]
pub default_icon_theme: IconThemeConfig,
#[serde(skip)]
pub color: ThemeColor,
#[serde(skip)]
pub available_color_themes: HashMap<String, (String, config::Config)>,
@ -213,6 +226,8 @@ fn default_config() -> config::Config {
fn default_lapce_config() -> LapceConfig {
let mut default_lapce_config: LapceConfig =
DEFAULT_CONFIG.clone().try_deserialize().expect("Failed to deserialize default config, this likely indicates a missing or misnamed field in settings.toml");
default_lapce_config.color_theme = DEFAULT_DARK_THEME_COLOR_CONFIG.clone();
default_lapce_config.icon_theme = DEFAULT_ICON_THEME_CONFIG.clone();
default_lapce_config.resolve_colors(None);
default_lapce_config
}
@ -273,8 +288,6 @@ fn resolve_theme(&mut self, workspace: &LapceWorkspace) {
}
}
self.resolve_colors(Some(&default_lapce_config));
self.default_color_theme = default_lapce_config.color_theme.clone();
self.default_icon_theme = default_lapce_config.icon_theme.clone();
self.update_id();
}
@ -300,6 +313,10 @@ fn load_color_themes(
themes
}
pub fn default_color_theme(&self) -> &ColorThemeConfig {
&DEFAULT_DARK_THEME_COLOR_CONFIG
}
/// Set the active color theme.
/// Note that this does not save the config.
pub fn set_color_theme(&mut self, workspace: &LapceWorkspace, theme: &str) {
@ -415,6 +432,8 @@ fn load_color_theme(path: &Path) -> Option<(String, (String, config::Config))> {
Some((name.to_lowercase(), (name, config)))
}
/// Load the given theme by its contents.
/// Returns `(name, theme fields)`
fn load_color_theme_from_str(s: &str) -> Option<(String, config::Config)> {
let config = config::Config::builder()
.add_source(config::File::from_str(s, config::FileFormat::Toml))
@ -563,7 +582,7 @@ pub fn ui_svg(&self, icon: &'static str) -> String {
});
svg.unwrap_or_else(|| {
let name = self.default_icon_theme.ui.get(icon).unwrap();
let name = DEFAULT_ICON_THEME_CONFIG.ui.get(icon).unwrap();
self.svg_store.write().get_default_svg(name)
})
}

View File

@ -125,7 +125,7 @@ pub fn key_values(&self) -> BTreeMap<String, String> {
}
#[derive(Debug, Clone, Deserialize, Serialize, Default)]
#[serde(rename_all = "kebab-case")]
#[serde(rename_all = "kebab-case", default)]
pub struct ColorThemeConfig {
#[serde(skip)]
pub path: PathBuf,

View File

@ -20,7 +20,7 @@ fn try_all_equal_value<T: PartialEq, I: IntoIterator<Item = Option<T>>>(
}
#[derive(Debug, Clone, Deserialize, Serialize, Default)]
#[serde(rename_all = "kebab-case")]
#[serde(rename_all = "kebab-case", default)]
pub struct IconThemeConfig {
#[serde(skip)]
pub path: PathBuf,

View File

@ -974,15 +974,15 @@ fn color_section_list(
let config = config.get_untracked();
let default = match kind.as_str() {
"base" => config
.default_color_theme
.default_color_theme()
.base
.get(&field),
"ui" => config
.default_color_theme
.default_color_theme()
.ui
.get(&field),
"syntax" => config
.default_color_theme
.default_color_theme()
.syntax
.get(&field),
_ => None,
@ -1072,15 +1072,15 @@ fn color_section_list(
let same = match kind.as_str() {
"base" => {
config.default_color_theme.base.get(&key)
config.default_color_theme().base.get(&key)
== Some(&content)
}
"ui" => {
config.default_color_theme.ui.get(&key)
config.default_color_theme().ui.get(&key)
== Some(&content)
}
"syntax" => {
config.default_color_theme.syntax.get(&key)
config.default_color_theme().syntax.get(&key)
== Some(&content)
}
_ => false,