Allow specifying startup command with -e, --command, or --
This commit is contained in:
parent
7fc962b93a
commit
7f37ede453
3 changed files with 50 additions and 18 deletions
38
src/main.rs
38
src/main.rs
|
|
@ -92,6 +92,36 @@ fn main() -> Result<(), Box<dyn std::error::Error>> {
|
|||
}
|
||||
};
|
||||
|
||||
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<dyn std::error::Error>> {
|
|||
let flags = Flags {
|
||||
config_handler,
|
||||
config,
|
||||
startup_options,
|
||||
term_config,
|
||||
};
|
||||
cosmic::app::run::<App>(settings, flags)?;
|
||||
|
|
@ -124,6 +155,7 @@ fn main() -> Result<(), Box<dyn std::error::Error>> {
|
|||
pub struct Flags {
|
||||
config_handler: Option<cosmic_config::Config>,
|
||||
config: Config,
|
||||
startup_options: Option<tty::Options>,
|
||||
term_config: TermConfig,
|
||||
}
|
||||
|
||||
|
|
@ -232,6 +264,7 @@ pub struct App {
|
|||
find_search_id: widget::Id,
|
||||
find_search_value: String,
|
||||
term_event_tx_opt: Option<mpsc::Sender<(segmented_button::Entity, TermEvent)>>,
|
||||
startup_options: Option<tty::Options>,
|
||||
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(),
|
||||
);
|
||||
|
|
|
|||
|
|
@ -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);
|
||||
|
|
|
|||
|
|
@ -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::<Srgb, u8>::new(c.r, c.g, c.b)
|
||||
.into_format::<f32>();
|
||||
let p_rgb = PRgb::<Srgb, u8>::new(c.r, c.g, c.b).into_format::<f32>();
|
||||
Okhsl::from_color(p_rgb)
|
||||
}
|
||||
|
||||
fn okhsl_to_rgb(c: Okhsl) -> Rgb {
|
||||
let p_rgb = PRgb::<Srgb, _>::from_color(c)
|
||||
.into_format::<u8>();
|
||||
let p_rgb = PRgb::<Srgb, _>::from_color(c).into_format::<u8>();
|
||||
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 };
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue