From 1cbcc1e7956483d780af866c13d34f620c3103f8 Mon Sep 17 00:00:00 2001 From: Jeremy Soller Date: Thu, 21 Dec 2023 10:14:57 -0700 Subject: [PATCH] Share terminal config between tabs --- src/main.rs | 25 +++++++++++++++---------- src/terminal.rs | 2 +- 2 files changed, 16 insertions(+), 11 deletions(-) diff --git a/src/main.rs b/src/main.rs index aa0bad3..4ce11b9 100644 --- a/src/main.rs +++ b/src/main.rs @@ -35,12 +35,10 @@ fn main() -> Result<(), Box> { env_logger::init(); // Set up environmental variables for terminal - { - let mut term_config = TermConfig::default(); - // Override TERM for better compatibility - term_config.env.insert("TERM".to_string(), "xterm-256color".to_string()); - tty::setup_env(&term_config); - } + let mut term_config = TermConfig::default(); + // Override TERM for better compatibility + term_config.env.insert("TERM".to_string(), "xterm-256color".to_string()); + tty::setup_env(&term_config); let settings = Settings::default() .antialiasing(true) @@ -52,7 +50,7 @@ fn main() -> Result<(), Box> { .size(Size::new(1024., 768.)) .theme(cosmic::Theme::dark()); - cosmic::app::run::(settings, ())?; + cosmic::app::run::(settings, term_config)?; Ok(()) } @@ -72,6 +70,7 @@ pub struct App { core: Core, tab_model: segmented_button::Model, term_event_tx_opt: Option>, + term_config: TermConfig, terminal_theme: String, terminal_themes: HashMap, } @@ -82,7 +81,7 @@ impl cosmic::Application for App { type Executor = executor::Default; /// Argument received [`cosmic::Application::new`]. - type Flags = (); + type Flags = TermConfig; /// Message type specific to our [`App`]. type Message = Message; @@ -99,11 +98,12 @@ impl cosmic::Application for App { } /// Creates the application, and optionally emits command on initialize. - fn init(core: Core, _flags: Self::Flags) -> (Self, Command) { + fn init(core: Core, term_config: Self::Flags) -> (Self, Command) { let mut app = App { core, tab_model: segmented_button::ModelBuilder::default().build(), term_event_tx_opt: None, + term_config, terminal_theme: "OneHalfDark".to_string(), terminal_themes: terminal_theme::terminal_themes(), }; @@ -150,7 +150,12 @@ impl cosmic::Application for App { .closable() .activate() .id(); - let terminal = Terminal::new(entity, term_event_tx.clone(), colors.clone()); + let terminal = Terminal::new( + entity, + term_event_tx.clone(), + &self.term_config, + colors.clone(), + ); self.tab_model .data_set::>(entity, Mutex::new(terminal)); } diff --git a/src/terminal.rs b/src/terminal.rs index 0f2a098..7a96e2c 100644 --- a/src/terminal.rs +++ b/src/terminal.rs @@ -106,6 +106,7 @@ impl Terminal { pub fn new( entity: segmented_button::Entity, event_tx: mpsc::Sender<(segmented_button::Entity, Event)>, + config: &Config, colors: Colors, ) -> Self { let metrics = Metrics::new(14.0, 20.0); @@ -127,7 +128,6 @@ impl Terminal { (layout[0].w, metrics.line_height) }; - let config = Config::default(); let size = Size { width: (80.0 * cell_width).ceil() as u32, height: (24.0 * cell_height).ceil() as u32,