colors #6

Merged
candle merged 11 commits from colors into master 2025-07-26 15:58:05 +00:00
4 changed files with 69 additions and 69 deletions
Showing only changes of commit fd26344b5f - Show all commits

View File

@ -1,4 +1,5 @@
use eframe::egui;
use egui_extras::syntax_highlighting::CodeTheme;
#[derive(Debug, Clone, Copy, PartialEq, serde::Serialize, serde::Deserialize, Default)]
pub enum Theme {
@ -194,3 +195,12 @@ fn detect_system_dark_mode() -> bool {
true
}
}
pub fn create_code_theme_from_visuals(visuals: &egui::Visuals, font_size: f32) -> CodeTheme {
if visuals.dark_mode {
CodeTheme::dark(font_size)
} else {
CodeTheme::light(font_size)
}
}

View File

@ -1,6 +1,7 @@
mod editor;
mod find_highlight;
mod line_numbers;
mod languages;
use crate::app::TextEditor;
use eframe::egui;

View File

@ -1,75 +1,9 @@
use crate::app::TextEditor;
use eframe::egui;
use egui_extras::syntax_highlighting::{self, CodeTheme};
use egui_extras::syntax_highlighting::{self};
use super::find_highlight;
fn get_language_from_extension(file_path: Option<&std::path::Path>) -> String {
if let Some(path) = file_path {
if let Some(extension) = path.extension().and_then(|ext| ext.to_str()) {
match extension.to_lowercase().as_str() {
"rs" => "rs".to_string(),
"py" => "py".to_string(),
"js" => "js".to_string(),
"ts" => "ts".to_string(),
"tsx" => "tsx".to_string(),
"jsx" => "jsx".to_string(),
"c" => "c".to_string(),
"cpp" | "cc" | "cxx" => "cpp".to_string(),
"h" | "hpp" => "cpp".to_string(),
"java" => "java".to_string(),
"go" => "go".to_string(),
"php" => "php".to_string(),
"rb" => "rb".to_string(),
"cs" => "cs".to_string(),
"swift" => "swift".to_string(),
"kt" => "kt".to_string(),
"scala" => "scala".to_string(),
"sh" | "bash" | "zsh" | "fish" => "sh".to_string(),
"html" | "htm" => "html".to_string(),
"xml" => "xml".to_string(),
"css" => "css".to_string(),
"scss" | "sass" => "scss".to_string(),
"json" => "json".to_string(),
"yaml" | "yml" => "yaml".to_string(),
"toml" => "toml".to_string(),
"md" | "markdown" => "md".to_string(),
"sql" => "sql".to_string(),
"lua" => "lua".to_string(),
"vim" => "vim".to_string(),
"dockerfile" => "dockerfile".to_string(),
"makefile" => "makefile".to_string(),
_ => "txt".to_string(),
}
} else {
// Check filename for special cases
if let Some(filename) = path.file_name().and_then(|name| name.to_str()) {
match filename.to_lowercase().as_str() {
"dockerfile" => "dockerfile".to_string(),
"makefile" => "makefile".to_string(),
"cargo.toml" | "pyproject.toml" => "toml".to_string(),
"package.json" => "json".to_string(),
_ => "txt".to_string(),
}
} else {
"txt".to_string()
}
}
} else {
"txt".to_string()
}
}
fn create_code_theme_from_visuals(visuals: &egui::Visuals, font_size: f32) -> CodeTheme {
// For now, just use the appropriate base theme (dark/light)
// The base themes should automatically work well with the system colors
// since egui's syntax highlighting respects the overall UI theme
if visuals.dark_mode {
CodeTheme::dark(font_size)
} else {
CodeTheme::light(font_size)
}
}
pub(super) fn editor_view_ui(ui: &mut egui::Ui, app: &mut TextEditor) -> egui::Response {
let _current_match_position = app.get_current_match_position();
@ -166,8 +100,8 @@ pub(super) fn editor_view_ui(ui: &mut egui::Ui, app: &mut TextEditor) -> egui::R
f32::INFINITY
};
let language = get_language_from_extension(active_tab.file_path.as_deref());
let theme = create_code_theme_from_visuals(ui.visuals(), font_size);
let language = super::languages::get_language_from_extension(active_tab.file_path.as_deref());
let theme = crate::app::theme::create_code_theme_from_visuals(ui.visuals(), font_size);
let mut layouter = |ui: &egui::Ui, string: &dyn egui::TextBuffer, wrap_width: f32| {
let text = string.as_str();

View File

@ -0,0 +1,55 @@
pub fn get_language_from_extension(file_path: Option<&std::path::Path>) -> String {
if let Some(path) = file_path {
if let Some(extension) = path.extension().and_then(|ext| ext.to_str()) {
match extension.to_lowercase().as_str() {
"rs" => "rs".to_string(),
"py" => "py".to_string(),
"js" => "js".to_string(),
"ts" => "ts".to_string(),
"tsx" => "tsx".to_string(),
"jsx" => "jsx".to_string(),
"c" => "c".to_string(),
"cpp" | "cc" | "cxx" => "cpp".to_string(),
"h" | "hpp" => "cpp".to_string(),
"java" => "java".to_string(),
"go" => "go".to_string(),
"php" => "php".to_string(),
"rb" => "rb".to_string(),
"cs" => "cs".to_string(),
"swift" => "swift".to_string(),
"kt" => "kt".to_string(),
"scala" => "scala".to_string(),
"sh" | "bash" | "zsh" | "fish" => "sh".to_string(),
"html" | "htm" => "html".to_string(),
"xml" => "xml".to_string(),
"css" => "css".to_string(),
"scss" | "sass" => "scss".to_string(),
"json" => "json".to_string(),
"yaml" | "yml" => "yaml".to_string(),
"toml" => "toml".to_string(),
"md" | "markdown" => "md".to_string(),
"sql" => "sql".to_string(),
"lua" => "lua".to_string(),
"vim" => "vim".to_string(),
"dockerfile" => "dockerfile".to_string(),
"makefile" => "makefile".to_string(),
_ => "txt".to_string(),
}
} else {
// Check filename for special cases
if let Some(filename) = path.file_name().and_then(|name| name.to_str()) {
match filename.to_lowercase().as_str() {
"dockerfile" => "dockerfile".to_string(),
"makefile" => "makefile".to_string(),
"cargo.toml" | "pyproject.toml" => "toml".to_string(),
"package.json" => "json".to_string(),
_ => "txt".to_string(),
}
} else {
"txt".to_string()
}
}
} else {
"txt".to_string()
}
}