diff --git a/src/main.rs b/src/main.rs index 0da8c04..2de524d 100644 --- a/src/main.rs +++ b/src/main.rs @@ -92,6 +92,36 @@ fn main() -> Result<(), Box> { } }; + let mut shell_program_opt = None; + let mut shell_args = Vec::new(); + let mut parse_flags = true; + for arg in env::args().skip(1) { + if parse_flags { + match arg.as_str() { + // These flags indicate the end of parsing flags + "-e" | "--command" | "--" => { + parse_flags = false; + } + _ => { + //TODO: should this throw an error? + log::warn!("ignored argument {:?}", arg); + } + } + } else if shell_program_opt.is_none() { + shell_program_opt = Some(arg); + } else { + shell_args.push(arg); + } + } + + let startup_options = if let Some(shell_program) = shell_program_opt { + let mut options = tty::Options::default(); + options.shell = Some(tty::Shell::new(shell_program, shell_args)); + Some(options) + } else { + None + }; + let term_config = TermConfig::default(); // Set up environmental variables for terminal tty::setup_env(); @@ -113,6 +143,7 @@ fn main() -> Result<(), Box> { let flags = Flags { config_handler, config, + startup_options, term_config, }; cosmic::app::run::(settings, flags)?; @@ -124,6 +155,7 @@ fn main() -> Result<(), Box> { pub struct Flags { config_handler: Option, config: Config, + startup_options: Option, term_config: TermConfig, } @@ -232,6 +264,7 @@ pub struct App { find_search_id: widget::Id, find_search_value: String, term_event_tx_opt: Option>, + startup_options: Option, term_config: TermConfig, show_advanced_font_settings: bool, modifiers: Modifiers, @@ -357,7 +390,6 @@ impl App { self.config.dim_font_weight = Weight::NORMAL.0; } - if !self .curr_font_weights .contains(&self.config.bold_font_weight) @@ -688,6 +720,7 @@ impl Application for App { find: false, find_search_id: widget::Id::unique(), find_search_value: String::new(), + startup_options: flags.startup_options, term_config: flags.term_config, term_event_tx_opt: None, show_advanced_font_settings: false, @@ -971,10 +1004,13 @@ impl Application for App { .closable() .activate() .id(); + // Use the startup options, or defaults + let options = self.startup_options.take().unwrap_or_default(); let mut terminal = Terminal::new( entity, term_event_tx.clone(), self.term_config.clone(), + options, &self.config, colors.clone(), ); diff --git a/src/terminal.rs b/src/terminal.rs index 617633d..a512008 100644 --- a/src/terminal.rs +++ b/src/terminal.rs @@ -154,6 +154,7 @@ impl Terminal { entity: segmented_button::Entity, event_tx: mpsc::Sender<(segmented_button::Entity, Event)>, config: Config, + options: Options, app_config: &AppConfig, colors: Colors, ) -> Self { @@ -198,8 +199,6 @@ impl Terminal { ))); let window_id = 0; - let options = Options::default(); - let pty = tty::new(&options, size.into(), window_id).unwrap(); let pty_event_loop = EventLoop::new(term.clone(), event_proxy, pty, options.hold, false); diff --git a/src/terminal_theme.rs b/src/terminal_theme.rs index f7814e0..7490432 100644 --- a/src/terminal_theme.rs +++ b/src/terminal_theme.rs @@ -3,7 +3,7 @@ use alacritty_terminal::{ vte::ansi::{NamedColor, Rgb}, }; -use palette::{encoding::Srgb, rgb::Rgb as PRgb, Okhsl, FromColor, num::Abs}; +use palette::{encoding::Srgb, rgb::Rgb as PRgb, FromColor, Okhsl}; use std::collections::HashMap; // Fill missing dim/bright colors with derived values from normal ones. @@ -29,31 +29,28 @@ impl ColorDerive { } fn with_dim_lightness_adjustment(self, dim_lightness_adjustment: f32) -> Self { - Self { dim_lightness_adjustment, ..self } + Self { + dim_lightness_adjustment, + ..self + } } fn rgb_to_okhsl(c: Rgb) -> Okhsl { - let p_rgb = PRgb::::new(c.r, c.g, c.b) - .into_format::(); + let p_rgb = PRgb::::new(c.r, c.g, c.b).into_format::(); Okhsl::from_color(p_rgb) } fn okhsl_to_rgb(c: Okhsl) -> Rgb { - let p_rgb = PRgb::::from_color(c) - .into_format::(); + let p_rgb = PRgb::::from_color(c).into_format::(); let (r, g, b) = p_rgb.into_components(); - Rgb{r, g, b} + Rgb { r, g, b } } fn color_adj(rgb: Rgb, saturation_adj: f32, lightness_adj: f32) -> Rgb { let mut okhsl = Self::rgb_to_okhsl(rgb); - okhsl.saturation = (okhsl.saturation + saturation_adj) - .max(0.0) - .min(1.0); - okhsl.lightness = (okhsl.lightness + lightness_adj) - .max(0.0) - .min(1.0); + okhsl.saturation = (okhsl.saturation + saturation_adj).max(0.0).min(1.0); + okhsl.lightness = (okhsl.lightness + lightness_adj).max(0.0).min(1.0); Self::okhsl_to_rgb(okhsl) } @@ -86,7 +83,7 @@ impl ColorDerive { }; } - populate!{ Foreground, Black, Red, Green, Yellow, Blue, Magenta, Cyan, White }; + populate! { Foreground, Black, Red, Green, Yellow, Blue, Magenta, Cyan, White }; } fn fill_missing_dims(&self, colors: &mut Colors) { @@ -105,7 +102,7 @@ impl ColorDerive { }; } - populate!{ Foreground, Black, Red, Green, Yellow, Blue, Magenta, Cyan, White }; + populate! { Foreground, Black, Red, Green, Yellow, Blue, Magenta, Cyan, White }; } }