Share terminal config between tabs
This commit is contained in:
parent
51818a34f5
commit
1cbcc1e795
2 changed files with 16 additions and 11 deletions
25
src/main.rs
25
src/main.rs
|
|
@ -35,12 +35,10 @@ fn main() -> Result<(), Box<dyn std::error::Error>> {
|
||||||
env_logger::init();
|
env_logger::init();
|
||||||
|
|
||||||
// Set up environmental variables for terminal
|
// Set up environmental variables for terminal
|
||||||
{
|
let mut term_config = TermConfig::default();
|
||||||
let mut term_config = TermConfig::default();
|
// Override TERM for better compatibility
|
||||||
// Override TERM for better compatibility
|
term_config.env.insert("TERM".to_string(), "xterm-256color".to_string());
|
||||||
term_config.env.insert("TERM".to_string(), "xterm-256color".to_string());
|
tty::setup_env(&term_config);
|
||||||
tty::setup_env(&term_config);
|
|
||||||
}
|
|
||||||
|
|
||||||
let settings = Settings::default()
|
let settings = Settings::default()
|
||||||
.antialiasing(true)
|
.antialiasing(true)
|
||||||
|
|
@ -52,7 +50,7 @@ fn main() -> Result<(), Box<dyn std::error::Error>> {
|
||||||
.size(Size::new(1024., 768.))
|
.size(Size::new(1024., 768.))
|
||||||
.theme(cosmic::Theme::dark());
|
.theme(cosmic::Theme::dark());
|
||||||
|
|
||||||
cosmic::app::run::<App>(settings, ())?;
|
cosmic::app::run::<App>(settings, term_config)?;
|
||||||
|
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
@ -72,6 +70,7 @@ pub struct App {
|
||||||
core: Core,
|
core: Core,
|
||||||
tab_model: segmented_button::Model<segmented_button::SingleSelect>,
|
tab_model: segmented_button::Model<segmented_button::SingleSelect>,
|
||||||
term_event_tx_opt: Option<mpsc::Sender<(segmented_button::Entity, TermEvent)>>,
|
term_event_tx_opt: Option<mpsc::Sender<(segmented_button::Entity, TermEvent)>>,
|
||||||
|
term_config: TermConfig,
|
||||||
terminal_theme: String,
|
terminal_theme: String,
|
||||||
terminal_themes: HashMap<String, TermColors>,
|
terminal_themes: HashMap<String, TermColors>,
|
||||||
}
|
}
|
||||||
|
|
@ -82,7 +81,7 @@ impl cosmic::Application for App {
|
||||||
type Executor = executor::Default;
|
type Executor = executor::Default;
|
||||||
|
|
||||||
/// Argument received [`cosmic::Application::new`].
|
/// Argument received [`cosmic::Application::new`].
|
||||||
type Flags = ();
|
type Flags = TermConfig;
|
||||||
|
|
||||||
/// Message type specific to our [`App`].
|
/// Message type specific to our [`App`].
|
||||||
type Message = Message;
|
type Message = Message;
|
||||||
|
|
@ -99,11 +98,12 @@ impl cosmic::Application for App {
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Creates the application, and optionally emits command on initialize.
|
/// Creates the application, and optionally emits command on initialize.
|
||||||
fn init(core: Core, _flags: Self::Flags) -> (Self, Command<Self::Message>) {
|
fn init(core: Core, term_config: Self::Flags) -> (Self, Command<Self::Message>) {
|
||||||
let mut app = App {
|
let mut app = App {
|
||||||
core,
|
core,
|
||||||
tab_model: segmented_button::ModelBuilder::default().build(),
|
tab_model: segmented_button::ModelBuilder::default().build(),
|
||||||
term_event_tx_opt: None,
|
term_event_tx_opt: None,
|
||||||
|
term_config,
|
||||||
terminal_theme: "OneHalfDark".to_string(),
|
terminal_theme: "OneHalfDark".to_string(),
|
||||||
terminal_themes: terminal_theme::terminal_themes(),
|
terminal_themes: terminal_theme::terminal_themes(),
|
||||||
};
|
};
|
||||||
|
|
@ -150,7 +150,12 @@ impl cosmic::Application for App {
|
||||||
.closable()
|
.closable()
|
||||||
.activate()
|
.activate()
|
||||||
.id();
|
.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
|
self.tab_model
|
||||||
.data_set::<Mutex<Terminal>>(entity, Mutex::new(terminal));
|
.data_set::<Mutex<Terminal>>(entity, Mutex::new(terminal));
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -106,6 +106,7 @@ impl Terminal {
|
||||||
pub fn new(
|
pub fn new(
|
||||||
entity: segmented_button::Entity,
|
entity: segmented_button::Entity,
|
||||||
event_tx: mpsc::Sender<(segmented_button::Entity, Event)>,
|
event_tx: mpsc::Sender<(segmented_button::Entity, Event)>,
|
||||||
|
config: &Config,
|
||||||
colors: Colors,
|
colors: Colors,
|
||||||
) -> Self {
|
) -> Self {
|
||||||
let metrics = Metrics::new(14.0, 20.0);
|
let metrics = Metrics::new(14.0, 20.0);
|
||||||
|
|
@ -127,7 +128,6 @@ impl Terminal {
|
||||||
(layout[0].w, metrics.line_height)
|
(layout[0].w, metrics.line_height)
|
||||||
};
|
};
|
||||||
|
|
||||||
let config = Config::default();
|
|
||||||
let size = Size {
|
let size = Size {
|
||||||
width: (80.0 * cell_width).ceil() as u32,
|
width: (80.0 * cell_width).ceil() as u32,
|
||||||
height: (24.0 * cell_height).ceil() as u32,
|
height: (24.0 * cell_height).ceil() as u32,
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue