diff options
author | Canop <cano.petrole@gmail.com> | 2022-06-30 20:39:34 +0200 |
---|---|---|
committer | Canop <cano.petrole@gmail.com> | 2022-06-30 20:39:34 +0200 |
commit | 60c29ed5571ab3def5869af31e9410e58863f76f (patch) | |
tree | 204a80e9f946d8c06abda029b66dc83e0b60ae92 /src/app | |
parent | 03f5270cd3bf6a9a126d57e3dce1d1dcc20589d6 (diff) |
add the set_syntax_theme verb
which isn't useful right now as the theme isn't persisted.
It's an addition for a future use.
Diffstat (limited to 'src/app')
-rw-r--r-- | src/app/app.rs | 35 | ||||
-rw-r--r-- | src/app/app_context.rs | 12 | ||||
-rw-r--r-- | src/app/panel_state.rs | 13 | ||||
-rw-r--r-- | src/app/selection.rs | 2 |
4 files changed, 43 insertions, 19 deletions
diff --git a/src/app/app.rs b/src/app/app.rs index 7f75c11..0898dec 100644 --- a/src/app/app.rs +++ b/src/app/app.rs @@ -14,6 +14,7 @@ use { path::closest_dir, skin::*, stage::Stage, + syntactic::SyntaxTheme, task_sync::{Dam, Either}, verb::Internal, }, @@ -26,6 +27,7 @@ use { std::{ io::Write, path::PathBuf, + str::FromStr, sync::{Arc, Mutex}, }, strict::NonEmptyVec, @@ -252,7 +254,7 @@ impl App { cmd: Command, panel_skin: &PanelSkin, app_state: &mut AppState, - con: &AppContext, + con: &mut AppContext, ) -> Result<(), ProgramError> { use CmdResult::*; let mut error: Option<String> = None; @@ -415,6 +417,27 @@ impl App { } } } + Internal::set_syntax_theme => { + let arg = cmd + .as_verb_invocation() + .and_then(|vi| vi.args.as_ref()); + match arg { + Some(arg) => { + match SyntaxTheme::from_str(arg) { + Ok(theme) => { + con.syntax_theme = Some(theme); + self.update_preview(con, true); + } + Err(e) => { + error = Some(e.to_string()); + } + } + } + None => { + error = Some("no theme provided".to_string()); + } + } + } _ => { info!("unhandled propagated internal. cmd={:?}", &cmd); } @@ -503,18 +526,18 @@ impl App { } } - self.update_preview(con); + self.update_preview(con, false); Ok(()) } /// update the state of the preview, if there's some - fn update_preview(&mut self, con: &AppContext) { + fn update_preview(&mut self, con: &AppContext, refresh: bool) { let preview_idx = self.preview_panel.and_then(|id| self.panel_id_to_idx(id)); if let Some(preview_idx) = preview_idx { if let Some(path) = self.state().selected_path() { let old_path = self.panels[preview_idx].state().selected_path(); - if Some(path) != old_path && path.is_file() { + if (refresh || Some(path) != old_path) && path.is_file() { let path = path.to_path_buf(); self.panels[preview_idx].mut_state().set_selected_path(path, con); } @@ -595,7 +618,7 @@ impl App { ) -> Result<(), ProgramError> { while self.has_pending_task() && !dam.has_event() { let error = self.do_pending_task(app_state, con, dam).err(); - self.update_preview(con); // the selection may have changed + self.update_preview(con, false); // the selection may have changed if let Some(error) = &error { self.mut_panel().set_error(error.to_string()); } else { @@ -649,7 +672,7 @@ impl App { pub fn run( mut self, w: &mut W, - con: &AppContext, + con: &mut AppContext, conf: &Conf, ) -> Result<Option<Launchable>, ProgramError> { #[cfg(feature = "clipboard")] diff --git a/src/app/app_context.rs b/src/app/app_context.rs index 038da18..3b7418b 100644 --- a/src/app/app_context.rs +++ b/src/app/app_context.rs @@ -6,9 +6,10 @@ use { errors::*, file_sum, icon::*, - pattern::SearchModeMap, path::SpecialPath, + pattern::SearchModeMap, skin::ExtColorMap, + syntactic::SyntaxTheme, tree::TreeOptions, verb::VerbStore, }, @@ -19,9 +20,8 @@ use { }, }; -/// The immutable container that can be passed around -/// to provide the configuration things for the whole -/// life of the App +/// The container that can be passed around to provide the configuration things +/// for the whole life of the App pub struct AppContext { /// The initial tree root @@ -53,7 +53,7 @@ pub struct AppContext { pub ext_colors: ExtColorMap, /// the syntect theme to use for text files previewing - pub syntax_theme: Option<String>, + pub syntax_theme: Option<SyntaxTheme>, /// precomputed status to display in standard cases /// (ie when no verb is involved) @@ -153,7 +153,7 @@ impl AppContext { search_modes, show_selection_mark: config.show_selection_mark.unwrap_or(false), ext_colors, - syntax_theme: config.syntax_theme.clone(), + syntax_theme: config.syntax_theme, standard_status, true_colors, icons, diff --git a/src/app/panel_state.rs b/src/app/panel_state.rs index ef21a09..ebe6038 100644 --- a/src/app/panel_state.rs +++ b/src/app/panel_state.rs @@ -391,8 +391,9 @@ pub trait PanelState { } } } - Internal::print_path => print::print_paths(&self.sel_info(app_state), con)?, - Internal::print_relative_path => print::print_relative_paths(&self.sel_info(app_state), con)?, + Internal::set_syntax_theme => CmdResult::HandleInApp(Internal::set_syntax_theme), + Internal::print_path => print::print_paths(self.sel_info(app_state), con)?, + Internal::print_relative_path => print::print_relative_paths(self.sel_info(app_state), con)?, Internal::refresh => CmdResult::RefreshState { clear_cache: true }, Internal::quit => CmdResult::Quit, _ => CmdResult::Keep, @@ -511,7 +512,7 @@ pub trait PanelState { ) -> Result<CmdResult, ProgramError> { let sel_info = self.sel_info(app_state); if let Some(invocation) = &invocation { - if let Some(error) = verb.check_args(&sel_info, invocation, &app_state.other_panel_path) { + if let Some(error) = verb.check_args(sel_info, invocation, &app_state.other_panel_path) { debug!("verb.check_args prevented execution: {:?}", &error); return Ok(CmdResult::error(error)); } @@ -609,7 +610,7 @@ pub trait PanelState { let sel_info = self.sel_info(app_state); match con.verb_store.search_sel_info( &invocation.name, - &sel_info, + sel_info, ) { PrefixSearchResult::Match(_, verb) => { self.execute_verb( @@ -776,7 +777,7 @@ pub trait PanelState { let sel_info = self.sel_info(app_state); match cc.app.con.verb_store.search_sel_info( &invocation.name, - &sel_info, + sel_info, ) { PrefixSearchResult::NoMatch => { Status::new("No matching verb (*?* for the list of verbs)", true) @@ -821,7 +822,7 @@ pub trait PanelState { } // right now there's no check for sequences but they're inherently dangereous } - if let Some(err) = verb.check_args(&sel_info, invocation, &app_state.other_panel_path) { + if let Some(err) = verb.check_args(sel_info, invocation, &app_state.other_panel_path) { Status::new(err, true) } else { Status::new( diff --git a/src/app/selection.rs b/src/app/selection.rs index 0275836..e3a84f8 100644 --- a/src/app/selection.rs +++ b/src/app/selection.rs @@ -37,7 +37,7 @@ pub struct Selection<'s> { pub is_exe: bool, } -#[derive(Debug)] +#[derive(Debug, Clone, Copy)] pub enum SelInfo<'s> { None, One(Selection<'s>), |