mirror of
https://github.com/wez/wezterm.git
synced 2024-11-23 06:54:45 +03:00
remove Mux::config in favor of config::configuration()
The idea is to centralize accessing the config to that function so that we can implement config reloading.
This commit is contained in:
parent
72b55d3982
commit
8996f897b9
@ -28,14 +28,13 @@ pub mod fontloader;
|
||||
#[cfg(any(target_os = "macos", windows))]
|
||||
pub mod fontloader_and_freetype;
|
||||
|
||||
use super::config::{Config, TextStyle};
|
||||
use super::config::{configuration, Config, TextStyle};
|
||||
use term::CellAttributes;
|
||||
|
||||
type FontPtr = Rc<RefCell<Box<dyn NamedFont>>>;
|
||||
|
||||
/// Matches and loads fonts for a given input style
|
||||
pub struct FontConfiguration {
|
||||
config: Arc<Config>,
|
||||
fonts: RefCell<HashMap<TextStyle, FontPtr>>,
|
||||
system: Rc<dyn FontSystem>,
|
||||
metrics: RefCell<Option<FontMetrics>>,
|
||||
@ -129,9 +128,8 @@ impl std::str::FromStr for FontSystemSelection {
|
||||
|
||||
impl FontConfiguration {
|
||||
/// Create a new empty configuration
|
||||
pub fn new(config: Arc<Config>, system: FontSystemSelection) -> Self {
|
||||
pub fn new(system: FontSystemSelection) -> Self {
|
||||
Self {
|
||||
config,
|
||||
fonts: RefCell::new(HashMap::new()),
|
||||
system: system.new_font_system(),
|
||||
metrics: RefCell::new(None),
|
||||
@ -151,7 +149,7 @@ impl FontConfiguration {
|
||||
|
||||
let scale = *self.dpi_scale.borrow() * *self.font_scale.borrow();
|
||||
let font = Rc::new(RefCell::new(self.system.load_font(
|
||||
&self.config,
|
||||
&configuration(),
|
||||
style,
|
||||
scale,
|
||||
)?));
|
||||
@ -168,7 +166,7 @@ impl FontConfiguration {
|
||||
|
||||
/// Returns the baseline font specified in the configuration
|
||||
pub fn default_font(&self) -> Result<Rc<RefCell<Box<dyn NamedFont>>>, Error> {
|
||||
self.cached_font(&self.config.font)
|
||||
self.cached_font(&configuration().font)
|
||||
}
|
||||
|
||||
pub fn get_font_scale(&self) -> f64 {
|
||||
@ -194,7 +192,11 @@ impl FontConfiguration {
|
||||
/// Apply the defined font_rules from the user configuration to
|
||||
/// produce the text style that best matches the supplied input
|
||||
/// cell attributes.
|
||||
pub fn match_style(&self, attrs: &CellAttributes) -> &TextStyle {
|
||||
pub fn match_style<'a>(
|
||||
&self,
|
||||
config: &'a Arc<Config>,
|
||||
attrs: &CellAttributes,
|
||||
) -> &'a TextStyle {
|
||||
// a little macro to avoid boilerplate for matching the rules.
|
||||
// If the rule doesn't specify a value for an attribute then
|
||||
// it will implicitly match. If it specifies an attribute
|
||||
@ -211,7 +213,7 @@ impl FontConfiguration {
|
||||
};
|
||||
};
|
||||
|
||||
for rule in &self.config.font_rules {
|
||||
for rule in &config.font_rules {
|
||||
attr_match!(intensity, &rule);
|
||||
attr_match!(underline, &rule);
|
||||
attr_match!(italic, &rule);
|
||||
@ -224,7 +226,7 @@ impl FontConfiguration {
|
||||
// so we therefore assume that it did match overall.
|
||||
return &rule.font;
|
||||
}
|
||||
&self.config.font
|
||||
&config.font
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -1,4 +1,4 @@
|
||||
use crate::config::Config;
|
||||
use crate::config::configuration;
|
||||
use crate::font::FontConfiguration;
|
||||
use crate::frontend::FrontEnd;
|
||||
use crate::mux::tab::Tab;
|
||||
@ -121,11 +121,10 @@ impl FrontEnd for GuiFrontEnd {
|
||||
|
||||
fn spawn_new_window(
|
||||
&self,
|
||||
config: &Arc<Config>,
|
||||
fontconfig: &Rc<FontConfiguration>,
|
||||
tab: &Rc<dyn Tab>,
|
||||
window_id: MuxWindowId,
|
||||
) -> Fallible<()> {
|
||||
termwindow::TermWindow::new_window(config, fontconfig, tab, window_id)
|
||||
termwindow::TermWindow::new_window(&configuration(), fontconfig, tab, window_id)
|
||||
}
|
||||
}
|
||||
|
@ -2,7 +2,7 @@ use super::quad::*;
|
||||
use super::renderstate::*;
|
||||
use super::utilsprites::RenderMetrics;
|
||||
use crate::clipboard::SystemClipboard;
|
||||
use crate::config::Config;
|
||||
use crate::config::{configuration, Config};
|
||||
use crate::font::{FontConfiguration, FontSystemSelection};
|
||||
use crate::frontend::gui::tabbar::{TabBarItem, TabBarState};
|
||||
use crate::frontend::{executor, front_end};
|
||||
@ -27,7 +27,6 @@ use termwiz::color::RgbColor;
|
||||
pub struct TermWindow {
|
||||
window: Option<Window>,
|
||||
fonts: Rc<FontConfiguration>,
|
||||
config: Arc<Config>,
|
||||
dimensions: Dimensions,
|
||||
mux_window_id: MuxWindowId,
|
||||
render_metrics: RenderMetrics,
|
||||
@ -256,7 +255,7 @@ impl WindowCallbacks for TermWindow {
|
||||
return true;
|
||||
}
|
||||
|
||||
if !self.config.send_composed_key_when_alt_is_pressed
|
||||
if !configuration().send_composed_key_when_alt_is_pressed
|
||||
&& modifiers.contains(::termwiz::input::Modifiers::ALT)
|
||||
&& tab.key_down(key, modifiers).is_ok()
|
||||
{
|
||||
@ -388,7 +387,6 @@ impl TermWindow {
|
||||
Box::new(Self {
|
||||
window: None,
|
||||
mux_window_id,
|
||||
config: Arc::clone(config),
|
||||
fonts: Rc::clone(fontconfig),
|
||||
render_metrics,
|
||||
dimensions: Dimensions {
|
||||
@ -475,14 +473,14 @@ impl TermWindow {
|
||||
WK::Char('\r') => KC::Enter,
|
||||
WK::Char('\t') => KC::Tab,
|
||||
WK::Char('\u{08}') => {
|
||||
if self.config.swap_backspace_and_delete {
|
||||
if configuration().swap_backspace_and_delete {
|
||||
KC::Delete
|
||||
} else {
|
||||
KC::Backspace
|
||||
}
|
||||
}
|
||||
WK::Char('\u{7f}') => {
|
||||
if self.config.swap_backspace_and_delete {
|
||||
if configuration().swap_backspace_and_delete {
|
||||
KC::Backspace
|
||||
} else {
|
||||
KC::Delete
|
||||
@ -596,7 +594,10 @@ impl TermWindow {
|
||||
None
|
||||
},
|
||||
&window,
|
||||
self.config.colors.as_ref().and_then(|c| c.tab_bar.as_ref()),
|
||||
configuration()
|
||||
.colors
|
||||
.as_ref()
|
||||
.and_then(|c| c.tab_bar.as_ref()),
|
||||
);
|
||||
if new_tab_bar != self.tab_bar {
|
||||
self.tab_bar = new_tab_bar;
|
||||
@ -778,16 +779,13 @@ impl TermWindow {
|
||||
pub fn spawn_new_window(&mut self) {
|
||||
promise::Future::with_executor(executor(), move || {
|
||||
let mux = Mux::get().unwrap();
|
||||
let fonts = Rc::new(FontConfiguration::new(
|
||||
Arc::clone(mux.config()),
|
||||
FontSystemSelection::get_default(),
|
||||
));
|
||||
let fonts = Rc::new(FontConfiguration::new(FontSystemSelection::get_default()));
|
||||
let window_id = mux.new_empty_window();
|
||||
let tab =
|
||||
mux.default_domain()
|
||||
.spawn(portable_pty::PtySize::default(), None, window_id)?;
|
||||
let front_end = front_end().expect("to be called on gui thread");
|
||||
front_end.spawn_new_window(mux.config(), &fonts, &tab, window_id)?;
|
||||
front_end.spawn_new_window(&fonts, &tab, window_id)?;
|
||||
Ok(())
|
||||
});
|
||||
}
|
||||
@ -1049,13 +1047,14 @@ impl TermWindow {
|
||||
// Break the line into clusters of cells with the same attributes
|
||||
let cell_clusters = line.cluster();
|
||||
let mut last_cell_idx = 0;
|
||||
let config = configuration();
|
||||
for cluster in cell_clusters {
|
||||
let attrs = &cluster.attrs;
|
||||
let is_highlited_hyperlink = match (&attrs.hyperlink, ¤t_highlight) {
|
||||
(&Some(ref this), &Some(ref highlight)) => this == highlight,
|
||||
_ => false,
|
||||
};
|
||||
let style = self.fonts.match_style(attrs);
|
||||
let style = self.fonts.match_style(&config, attrs);
|
||||
|
||||
let bg_color = palette.resolve_bg(attrs.background);
|
||||
let fg_color = match attrs.foreground {
|
||||
@ -1269,6 +1268,8 @@ impl TermWindow {
|
||||
terminal: &dyn Renderable,
|
||||
palette: &ColorPalette,
|
||||
) -> Fallible<()> {
|
||||
let config = configuration();
|
||||
|
||||
let (_num_rows, num_cols) = terminal.physical_dimensions();
|
||||
let current_highlight = terminal.current_highlight();
|
||||
|
||||
@ -1281,7 +1282,7 @@ impl TermWindow {
|
||||
(&Some(ref this), &Some(ref highlight)) => this == highlight,
|
||||
_ => false,
|
||||
};
|
||||
let style = self.fonts.match_style(attrs);
|
||||
let style = self.fonts.match_style(&config, attrs);
|
||||
|
||||
let bg_color = palette.resolve_bg(attrs.background);
|
||||
let fg_color = match attrs.foreground {
|
||||
|
@ -1,4 +1,3 @@
|
||||
use crate::config::Config;
|
||||
use crate::font::FontConfiguration;
|
||||
use crate::mux::tab::Tab;
|
||||
use crate::mux::window::WindowId;
|
||||
@ -9,7 +8,7 @@ use promise::Executor;
|
||||
use serde_derive::*;
|
||||
use std::cell::RefCell;
|
||||
use std::rc::Rc;
|
||||
use std::sync::{Arc, Mutex};
|
||||
use std::sync::Mutex;
|
||||
|
||||
pub mod gui;
|
||||
pub mod muxserver;
|
||||
@ -111,7 +110,6 @@ pub trait FrontEnd: Downcast {
|
||||
|
||||
fn spawn_new_window(
|
||||
&self,
|
||||
config: &Arc<Config>,
|
||||
fontconfig: &Rc<FontConfiguration>,
|
||||
tab: &Rc<dyn Tab>,
|
||||
window_id: WindowId,
|
||||
|
@ -1,5 +1,4 @@
|
||||
//! Implements the multiplexer server frontend
|
||||
use crate::config::Config;
|
||||
use crate::font::FontConfiguration;
|
||||
use crate::frontend::FrontEnd;
|
||||
use crate::mux::tab::Tab;
|
||||
@ -11,7 +10,6 @@ use log::info;
|
||||
use promise::*;
|
||||
use std::rc::Rc;
|
||||
use std::sync::mpsc::{self, Receiver, Sender};
|
||||
use std::sync::Arc;
|
||||
|
||||
#[derive(Clone)]
|
||||
struct MuxExecutor {
|
||||
@ -43,8 +41,7 @@ impl MuxServerFrontEnd {
|
||||
let (tx, rx) = mpsc::channel();
|
||||
|
||||
if start_listener {
|
||||
let mux = Mux::get().unwrap();
|
||||
spawn_listener(mux.config())?;
|
||||
spawn_listener()?;
|
||||
}
|
||||
Ok(Rc::new(Self { tx, rx }))
|
||||
}
|
||||
@ -85,7 +82,6 @@ impl FrontEnd for MuxServerFrontEnd {
|
||||
|
||||
fn spawn_new_window(
|
||||
&self,
|
||||
_config: &Arc<Config>,
|
||||
_fontconfig: &Rc<FontConfiguration>,
|
||||
_tab: &Rc<dyn Tab>,
|
||||
_window_id: WindowId,
|
||||
|
@ -1,5 +1,5 @@
|
||||
use crate::config::configuration;
|
||||
use crate::mux::domain::DomainId;
|
||||
use crate::mux::Mux;
|
||||
use std::collections::HashMap;
|
||||
use term::{KeyCode, KeyModifiers};
|
||||
|
||||
@ -40,9 +40,7 @@ pub struct KeyMap(HashMap<(KeyCode, KeyModifiers), KeyAssignment>);
|
||||
|
||||
impl KeyMap {
|
||||
pub fn new() -> Self {
|
||||
let mux = Mux::get().unwrap();
|
||||
let mut map = mux
|
||||
.config()
|
||||
let mut map = configuration()
|
||||
.key_bindings()
|
||||
.expect("keys section of config to be valid");
|
||||
|
||||
|
32
src/main.rs
32
src/main.rs
@ -352,7 +352,7 @@ fn run_ssh(config: Arc<config::Config>, opts: &SshCommand) -> Fallible<()> {
|
||||
// Set up the mux with no default domain; there's a good chance that
|
||||
// we'll need to show authentication UI and we don't want its domain
|
||||
// to become the default domain.
|
||||
let mux = Rc::new(mux::Mux::new(&config, None));
|
||||
let mux = Rc::new(mux::Mux::new(None));
|
||||
Mux::set_mux(&mux);
|
||||
|
||||
// Initiate an ssh connection; since that is a blocking process with
|
||||
@ -379,7 +379,7 @@ fn run_ssh(config: Arc<config::Config>, opts: &SshCommand) -> Fallible<()> {
|
||||
let font_system = opts.font_system.unwrap_or(config.font_system);
|
||||
font_system.set_default();
|
||||
|
||||
let fontconfig = Rc::new(FontConfiguration::new(Arc::clone(&config), font_system));
|
||||
let fontconfig = Rc::new(FontConfiguration::new(font_system));
|
||||
let cmd = if !opts.prog.is_empty() {
|
||||
let argv: Vec<&std::ffi::OsStr> = opts.prog.iter().map(|x| x.as_os_str()).collect();
|
||||
let mut builder = CommandBuilder::new(&argv[0]);
|
||||
@ -392,7 +392,6 @@ fn run_ssh(config: Arc<config::Config>, opts: &SshCommand) -> Fallible<()> {
|
||||
let pty_system = Box::new(portable_pty::ssh::SshSession::new(sess, &config.term));
|
||||
let domain: Arc<dyn Domain> = Arc::new(ssh::RemoteSshDomain::with_pty_system(
|
||||
&opts.user_at_host_and_port,
|
||||
&config,
|
||||
pty_system,
|
||||
));
|
||||
|
||||
@ -403,7 +402,7 @@ fn run_ssh(config: Arc<config::Config>, opts: &SshCommand) -> Fallible<()> {
|
||||
|
||||
let window_id = mux.new_empty_window();
|
||||
let tab = domain.spawn(PtySize::default(), cmd, window_id)?;
|
||||
gui.spawn_new_window(mux.config(), &fontconfig, &tab, window_id)?;
|
||||
gui.spawn_new_window(&fontconfig, &tab, window_id)?;
|
||||
Ok(())
|
||||
});
|
||||
});
|
||||
@ -415,7 +414,7 @@ fn run_serial(config: Arc<config::Config>, opts: &SerialCommand) -> Fallible<()>
|
||||
let font_system = opts.font_system.unwrap_or(config.font_system);
|
||||
font_system.set_default();
|
||||
|
||||
let fontconfig = Rc::new(FontConfiguration::new(Arc::clone(&config), font_system));
|
||||
let fontconfig = Rc::new(FontConfiguration::new(font_system));
|
||||
|
||||
let mut serial = portable_pty::serial::SerialTty::new(&opts.port);
|
||||
if let Some(baud) = opts.baud {
|
||||
@ -423,9 +422,8 @@ fn run_serial(config: Arc<config::Config>, opts: &SerialCommand) -> Fallible<()>
|
||||
}
|
||||
|
||||
let pty_system = Box::new(portable_pty::serial::SerialTty::new(&opts.port));
|
||||
let domain: Arc<dyn Domain> =
|
||||
Arc::new(LocalDomain::with_pty_system("local", &config, pty_system));
|
||||
let mux = Rc::new(mux::Mux::new(&config, Some(domain.clone())));
|
||||
let domain: Arc<dyn Domain> = Arc::new(LocalDomain::with_pty_system("local", pty_system));
|
||||
let mux = Rc::new(mux::Mux::new(Some(domain.clone())));
|
||||
Mux::set_mux(&mux);
|
||||
|
||||
let front_end = opts.front_end.unwrap_or(config.front_end);
|
||||
@ -434,7 +432,7 @@ fn run_serial(config: Arc<config::Config>, opts: &SerialCommand) -> Fallible<()>
|
||||
|
||||
let window_id = mux.new_empty_window();
|
||||
let tab = domain.spawn(PtySize::default(), None, window_id)?;
|
||||
gui.spawn_new_window(mux.config(), &fontconfig, &tab, window_id)?;
|
||||
gui.spawn_new_window(&fontconfig, &tab, window_id)?;
|
||||
|
||||
gui.run_forever()
|
||||
}
|
||||
@ -469,10 +467,10 @@ fn run_mux_client(config: Arc<config::Config>, opts: &ConnectCommand) -> Fallibl
|
||||
let font_system = opts.font_system.unwrap_or(config.font_system);
|
||||
font_system.set_default();
|
||||
|
||||
let fontconfig = Rc::new(FontConfiguration::new(Arc::clone(&config), font_system));
|
||||
let fontconfig = Rc::new(FontConfiguration::new(font_system));
|
||||
|
||||
let domain: Arc<dyn Domain> = Arc::new(ClientDomain::new(client_config));
|
||||
let mux = Rc::new(mux::Mux::new(&config, Some(domain.clone())));
|
||||
let mux = Rc::new(mux::Mux::new(Some(domain.clone())));
|
||||
Mux::set_mux(&mux);
|
||||
|
||||
let front_end = opts.front_end.unwrap_or(config.front_end);
|
||||
@ -492,7 +490,7 @@ fn run_mux_client(config: Arc<config::Config>, opts: &ConnectCommand) -> Fallibl
|
||||
let tab = mux
|
||||
.default_domain()
|
||||
.spawn(PtySize::default(), cmd, window_id)?;
|
||||
gui.spawn_new_window(mux.config(), &fontconfig, &tab, window_id)?;
|
||||
gui.spawn_new_window(&fontconfig, &tab, window_id)?;
|
||||
}
|
||||
|
||||
for dom in mux.iter_domains() {
|
||||
@ -543,7 +541,7 @@ fn run_terminal_gui(config: Arc<config::Config>, opts: &StartCommand) -> Fallibl
|
||||
let font_system = opts.font_system.unwrap_or(config.font_system);
|
||||
font_system.set_default();
|
||||
|
||||
let fontconfig = Rc::new(FontConfiguration::new(Arc::clone(&config), font_system));
|
||||
let fontconfig = Rc::new(FontConfiguration::new(font_system));
|
||||
|
||||
let cmd = if !opts.prog.is_empty() {
|
||||
let argv: Vec<&std::ffi::OsStr> = opts.prog.iter().map(|x| x.as_os_str()).collect();
|
||||
@ -554,8 +552,8 @@ fn run_terminal_gui(config: Arc<config::Config>, opts: &StartCommand) -> Fallibl
|
||||
None
|
||||
};
|
||||
|
||||
let domain: Arc<dyn Domain> = Arc::new(LocalDomain::new("local", &config)?);
|
||||
let mux = Rc::new(mux::Mux::new(&config, Some(domain.clone())));
|
||||
let domain: Arc<dyn Domain> = Arc::new(LocalDomain::new("local")?);
|
||||
let mux = Rc::new(mux::Mux::new(Some(domain.clone())));
|
||||
Mux::set_mux(&mux);
|
||||
|
||||
let front_end = opts.front_end.unwrap_or(config.front_end);
|
||||
@ -583,7 +581,7 @@ fn run_terminal_gui(config: Arc<config::Config>, opts: &StartCommand) -> Fallibl
|
||||
let tab = mux
|
||||
.default_domain()
|
||||
.spawn(PtySize::default(), cmd, window_id)?;
|
||||
gui.spawn_new_window(mux.config(), &fontconfig, &tab, window_id)?;
|
||||
gui.spawn_new_window(&fontconfig, &tab, window_id)?;
|
||||
}
|
||||
|
||||
for dom in mux.iter_domains() {
|
||||
@ -658,7 +656,7 @@ fn run() -> Result<(), Error> {
|
||||
SubCommand::ImageCat(cmd) => cmd.run(),
|
||||
SubCommand::Cli(cli) => {
|
||||
let initial = true;
|
||||
let client = Client::new_default_unix_domain(&config, initial)?;
|
||||
let client = Client::new_default_unix_domain(initial)?;
|
||||
match cli.sub {
|
||||
CliSubCommand::List => {
|
||||
let cols = vec![
|
||||
|
@ -5,7 +5,7 @@
|
||||
//! container or actually remote, running on the other end
|
||||
//! of an ssh session somewhere.
|
||||
|
||||
use crate::config::Config;
|
||||
use crate::config::configuration;
|
||||
use crate::localtab::LocalTab;
|
||||
use crate::mux::tab::Tab;
|
||||
use crate::mux::window::WindowId;
|
||||
@ -16,7 +16,6 @@ use log::info;
|
||||
use portable_pty::cmdbuilder::CommandBuilder;
|
||||
use portable_pty::{PtySize, PtySystem};
|
||||
use std::rc::Rc;
|
||||
use std::sync::Arc;
|
||||
|
||||
static DOMAIN_ID: ::std::sync::atomic::AtomicUsize = ::std::sync::atomic::AtomicUsize::new(0);
|
||||
pub type DomainId = usize;
|
||||
@ -60,27 +59,20 @@ impl_downcast!(Domain);
|
||||
|
||||
pub struct LocalDomain {
|
||||
pty_system: Box<dyn PtySystem>,
|
||||
config: Arc<Config>,
|
||||
id: DomainId,
|
||||
name: String,
|
||||
}
|
||||
|
||||
impl LocalDomain {
|
||||
pub fn new(name: &str, config: &Arc<Config>) -> Result<Self, Error> {
|
||||
let pty_system = config.pty.get()?;
|
||||
Ok(Self::with_pty_system(name, config, pty_system))
|
||||
pub fn new(name: &str) -> Result<Self, Error> {
|
||||
let pty_system = configuration().pty.get()?;
|
||||
Ok(Self::with_pty_system(name, pty_system))
|
||||
}
|
||||
|
||||
pub fn with_pty_system(
|
||||
name: &str,
|
||||
config: &Arc<Config>,
|
||||
pty_system: Box<dyn PtySystem>,
|
||||
) -> Self {
|
||||
let config = Arc::clone(config);
|
||||
pub fn with_pty_system(name: &str, pty_system: Box<dyn PtySystem>) -> Self {
|
||||
let id = alloc_domain_id();
|
||||
Self {
|
||||
pty_system,
|
||||
config,
|
||||
id,
|
||||
name: name.to_string(),
|
||||
}
|
||||
@ -94,9 +86,10 @@ impl Domain for LocalDomain {
|
||||
command: Option<CommandBuilder>,
|
||||
window: WindowId,
|
||||
) -> Result<Rc<dyn Tab>, Error> {
|
||||
let config = configuration();
|
||||
let cmd = match command {
|
||||
Some(c) => c,
|
||||
None => self.config.build_prog(None)?,
|
||||
None => config.build_prog(None)?,
|
||||
};
|
||||
let pair = self.pty_system.openpty(size)?;
|
||||
let child = pair.slave.spawn_command(cmd)?;
|
||||
@ -107,13 +100,13 @@ impl Domain for LocalDomain {
|
||||
size.cols as usize,
|
||||
size.pixel_width as usize,
|
||||
size.pixel_height as usize,
|
||||
self.config.scrollback_lines.unwrap_or(3500),
|
||||
self.config.hyperlink_rules.clone(),
|
||||
config.scrollback_lines.unwrap_or(3500),
|
||||
config.hyperlink_rules.clone(),
|
||||
);
|
||||
|
||||
let mux = Mux::get().unwrap();
|
||||
|
||||
if let Some(palette) = mux.config().colors.as_ref() {
|
||||
if let Some(palette) = config.colors.as_ref() {
|
||||
*terminal.palette_mut() = palette.clone().into();
|
||||
}
|
||||
|
||||
|
@ -1,4 +1,4 @@
|
||||
use crate::config::Config;
|
||||
use crate::config::configuration;
|
||||
use crate::frontend::{executor, low_pri_executor};
|
||||
use crate::mux::tab::{Tab, TabId};
|
||||
use crate::mux::window::{Window, WindowId};
|
||||
@ -38,18 +38,17 @@ pub type MuxSubscriber = PollableReceiver<MuxNotification>;
|
||||
pub struct Mux {
|
||||
tabs: RefCell<HashMap<TabId, Rc<dyn Tab>>>,
|
||||
windows: RefCell<HashMap<WindowId, Window>>,
|
||||
config: Arc<Config>,
|
||||
default_domain: RefCell<Option<Arc<dyn Domain>>>,
|
||||
domains: RefCell<HashMap<DomainId, Arc<dyn Domain>>>,
|
||||
domains_by_name: RefCell<HashMap<String, Arc<dyn Domain>>>,
|
||||
subscribers: RefCell<HashMap<usize, PollableSender<MuxNotification>>>,
|
||||
}
|
||||
|
||||
fn read_from_tab_pty(config: Arc<Config>, tab_id: TabId, mut reader: Box<dyn std::io::Read>) {
|
||||
fn read_from_tab_pty(tab_id: TabId, mut reader: Box<dyn std::io::Read>) {
|
||||
const BUFSIZE: usize = 32 * 1024;
|
||||
let mut buf = [0; BUFSIZE];
|
||||
|
||||
let mut lim = RateLimiter::new(config.ratelimit_output_bytes_per_second);
|
||||
let mut lim = RateLimiter::new(configuration().ratelimit_output_bytes_per_second);
|
||||
|
||||
loop {
|
||||
match reader.read(&mut buf) {
|
||||
@ -133,7 +132,7 @@ thread_local! {
|
||||
}
|
||||
|
||||
impl Mux {
|
||||
pub fn new(config: &Arc<Config>, default_domain: Option<Arc<dyn Domain>>) -> Self {
|
||||
pub fn new(default_domain: Option<Arc<dyn Domain>>) -> Self {
|
||||
let mut domains = HashMap::new();
|
||||
let mut domains_by_name = HashMap::new();
|
||||
if let Some(default_domain) = default_domain.as_ref() {
|
||||
@ -148,7 +147,6 @@ impl Mux {
|
||||
Self {
|
||||
tabs: RefCell::new(HashMap::new()),
|
||||
windows: RefCell::new(HashMap::new()),
|
||||
config: Arc::clone(config),
|
||||
default_domain: RefCell::new(default_domain),
|
||||
domains_by_name: RefCell::new(domains_by_name),
|
||||
domains: RefCell::new(domains),
|
||||
@ -200,10 +198,6 @@ impl Mux {
|
||||
.insert(domain.domain_name().to_string(), Arc::clone(domain));
|
||||
}
|
||||
|
||||
pub fn config(&self) -> &Arc<Config> {
|
||||
&self.config
|
||||
}
|
||||
|
||||
pub fn set_mux(mux: &Rc<Mux>) {
|
||||
MUX.with(|m| {
|
||||
*m.borrow_mut() = Some(Rc::clone(mux));
|
||||
@ -229,8 +223,7 @@ impl Mux {
|
||||
|
||||
let reader = tab.reader()?;
|
||||
let tab_id = tab.tab_id();
|
||||
let config = Arc::clone(&self.config);
|
||||
thread::spawn(move || read_from_tab_pty(config, tab_id, reader));
|
||||
thread::spawn(move || read_from_tab_pty(tab_id, reader));
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
@ -1,4 +1,4 @@
|
||||
use crate::config::{Config, SshDomain, TlsDomainClient, UnixDomain};
|
||||
use crate::config::{configuration, SshDomain, TlsDomainClient, UnixDomain};
|
||||
use crate::frontend::executor;
|
||||
use crate::mux::domain::alloc_domain_id;
|
||||
use crate::mux::domain::DomainId;
|
||||
@ -18,7 +18,6 @@ use std::collections::HashMap;
|
||||
use std::io::{Read, Write};
|
||||
use std::net::TcpStream;
|
||||
use std::path::Path;
|
||||
use std::sync::Arc;
|
||||
use std::thread;
|
||||
use std::time::Duration;
|
||||
|
||||
@ -567,17 +566,17 @@ impl Client {
|
||||
self.local_domain_id
|
||||
}
|
||||
|
||||
pub fn new_default_unix_domain(config: &Arc<Config>, initial: bool) -> Fallible<Self> {
|
||||
pub fn new_default_unix_domain(initial: bool) -> Fallible<Self> {
|
||||
let config = configuration();
|
||||
let unix_dom = config
|
||||
.unix_domains
|
||||
.first()
|
||||
.ok_or_else(|| err_msg("no default unix domain is configured"))?;
|
||||
Self::new_unix_domain(alloc_domain_id(), config, unix_dom, initial)
|
||||
Self::new_unix_domain(alloc_domain_id(), unix_dom, initial)
|
||||
}
|
||||
|
||||
pub fn new_unix_domain(
|
||||
local_domain_id: DomainId,
|
||||
_config: &Arc<Config>,
|
||||
unix_dom: &UnixDomain,
|
||||
initial: bool,
|
||||
) -> Fallible<Self> {
|
||||
@ -587,22 +586,14 @@ impl Client {
|
||||
Ok(Self::new(local_domain_id, reconnectable))
|
||||
}
|
||||
|
||||
pub fn new_tls(
|
||||
local_domain_id: DomainId,
|
||||
_config: &Arc<Config>,
|
||||
tls_client: &TlsDomainClient,
|
||||
) -> Fallible<Self> {
|
||||
pub fn new_tls(local_domain_id: DomainId, tls_client: &TlsDomainClient) -> Fallible<Self> {
|
||||
let mut reconnectable =
|
||||
Reconnectable::new(ClientDomainConfig::Tls(tls_client.clone()), None);
|
||||
reconnectable.connect(true)?;
|
||||
Ok(Self::new(local_domain_id, reconnectable))
|
||||
}
|
||||
|
||||
pub fn new_ssh(
|
||||
local_domain_id: DomainId,
|
||||
_config: &Arc<Config>,
|
||||
ssh_dom: &SshDomain,
|
||||
) -> Fallible<Self> {
|
||||
pub fn new_ssh(local_domain_id: DomainId, ssh_dom: &SshDomain) -> Fallible<Self> {
|
||||
let mut reconnectable = Reconnectable::new(ClientDomainConfig::Ssh(ssh_dom.clone()), None);
|
||||
reconnectable.connect(true)?;
|
||||
Ok(Self::new(local_domain_id, reconnectable))
|
||||
|
@ -192,14 +192,10 @@ impl Domain for ClientDomain {
|
||||
let client = match &self.config {
|
||||
ClientDomainConfig::Unix(unix) => {
|
||||
let initial = true;
|
||||
Client::new_unix_domain(self.local_domain_id, mux.config(), unix, initial)?
|
||||
}
|
||||
ClientDomainConfig::Tls(tls) => {
|
||||
Client::new_tls(self.local_domain_id, mux.config(), tls)?
|
||||
}
|
||||
ClientDomainConfig::Ssh(ssh) => {
|
||||
Client::new_ssh(self.local_domain_id, mux.config(), ssh)?
|
||||
Client::new_unix_domain(self.local_domain_id, unix, initial)?
|
||||
}
|
||||
ClientDomainConfig::Tls(tls) => Client::new_tls(self.local_domain_id, tls)?,
|
||||
ClientDomainConfig::Ssh(ssh) => Client::new_ssh(self.local_domain_id, ssh)?,
|
||||
};
|
||||
|
||||
let inner = Arc::new(ClientInner::new(self.local_domain_id, client));
|
||||
@ -226,17 +222,14 @@ impl Domain for ClientDomain {
|
||||
window.push(&tab);
|
||||
} else {
|
||||
log::error!("spawn new local window");
|
||||
let fonts = Rc::new(FontConfiguration::new(
|
||||
Arc::clone(mux.config()),
|
||||
FontSystemSelection::get_default(),
|
||||
));
|
||||
let fonts = Rc::new(FontConfiguration::new(FontSystemSelection::get_default()));
|
||||
let local_window_id = mux.new_empty_window();
|
||||
inner.record_remote_to_local_window_mapping(entry.window_id, local_window_id);
|
||||
mux.add_tab_to_window(&tab, local_window_id)?;
|
||||
|
||||
front_end()
|
||||
.unwrap()
|
||||
.spawn_new_window(mux.config(), &fonts, &tab, local_window_id)
|
||||
.spawn_new_window(&fonts, &tab, local_window_id)
|
||||
.unwrap();
|
||||
}
|
||||
}
|
||||
|
@ -1,4 +1,4 @@
|
||||
use crate::config::{Config, TlsDomainServer, UnixDomain};
|
||||
use crate::config::{configuration, TlsDomainServer, UnixDomain};
|
||||
use crate::create_user_owned_dirs;
|
||||
use crate::frontend::executor;
|
||||
use crate::mux::tab::{Tab, TabId};
|
||||
@ -200,7 +200,7 @@ mod not_ossl {
|
||||
}
|
||||
}
|
||||
|
||||
pub fn spawn_tls_listener(_config: &Arc<Config>, tls_server: &TlsDomainServer) -> Fallible<()> {
|
||||
pub fn spawn_tls_listener(tls_server: &TlsDomainServer) -> Fallible<()> {
|
||||
let identity = IdentitySource::PemFiles {
|
||||
key: tls_server
|
||||
.pem_private_key
|
||||
@ -328,10 +328,7 @@ mod ossl {
|
||||
}
|
||||
}
|
||||
|
||||
pub fn spawn_tls_listener(
|
||||
_config: &Arc<Config>,
|
||||
tls_server: &TlsDomainServer,
|
||||
) -> Result<(), Error> {
|
||||
pub fn spawn_tls_listener(tls_server: &TlsDomainServer) -> Result<(), Error> {
|
||||
openssl::init();
|
||||
|
||||
let mut acceptor = SslAcceptor::mozilla_modern(SslMethod::tls())?;
|
||||
@ -428,9 +425,9 @@ struct ClientSurfaceState {
|
||||
|
||||
impl ClientSurfaceState {
|
||||
fn new(cols: usize, rows: usize) -> Self {
|
||||
let mux = Mux::get().expect("to be running on gui thread");
|
||||
let push_limiter = RateLimiter::new(mux.config().ratelimit_mux_output_pushes_per_second);
|
||||
let update_limiter = RateLimiter::new(mux.config().ratelimit_mux_output_scans_per_second);
|
||||
let push_limiter = RateLimiter::new(configuration().ratelimit_mux_output_pushes_per_second);
|
||||
let update_limiter =
|
||||
RateLimiter::new(configuration().ratelimit_mux_output_scans_per_second);
|
||||
let surface = Surface::new(cols, rows);
|
||||
Self {
|
||||
surface,
|
||||
@ -890,16 +887,17 @@ fn safely_create_sock_path(unix_dom: &UnixDomain) -> Result<UnixListener, Error>
|
||||
}
|
||||
|
||||
#[cfg(any(feature = "openssl", unix))]
|
||||
fn spawn_tls_listener(config: &Arc<Config>, tls_server: &TlsDomainServer) -> Fallible<()> {
|
||||
ossl::spawn_tls_listener(config, tls_server)
|
||||
fn spawn_tls_listener(tls_server: &TlsDomainServer) -> Fallible<()> {
|
||||
ossl::spawn_tls_listener(tls_server)
|
||||
}
|
||||
|
||||
#[cfg(not(any(feature = "openssl", unix)))]
|
||||
fn spawn_tls_listener(config: &Arc<Config>, tls_server: &TlsDomainServer) -> Fallible<()> {
|
||||
not_ossl::spawn_tls_listener(config, tls_server)
|
||||
fn spawn_tls_listener(tls_server: &TlsDomainServer) -> Fallible<()> {
|
||||
not_ossl::spawn_tls_listener(tls_server)
|
||||
}
|
||||
|
||||
pub fn spawn_listener(config: &Arc<Config>) -> Fallible<()> {
|
||||
pub fn spawn_listener() -> Fallible<()> {
|
||||
let config = configuration();
|
||||
for unix_dom in &config.unix_domains {
|
||||
let mut listener = LocalListener::new(safely_create_sock_path(unix_dom)?);
|
||||
thread::spawn(move || {
|
||||
@ -908,7 +906,7 @@ pub fn spawn_listener(config: &Arc<Config>) -> Fallible<()> {
|
||||
}
|
||||
|
||||
for tls_server in &config.tls_servers {
|
||||
spawn_tls_listener(config, tls_server)?;
|
||||
spawn_tls_listener(tls_server)?;
|
||||
}
|
||||
Ok(())
|
||||
}
|
||||
|
20
src/ssh.rs
20
src/ssh.rs
@ -1,4 +1,4 @@
|
||||
use crate::config::Config;
|
||||
use crate::config::configuration;
|
||||
use crate::localtab::LocalTab;
|
||||
use crate::mux::domain::{alloc_domain_id, Domain, DomainId, DomainState};
|
||||
use crate::mux::tab::Tab;
|
||||
@ -14,7 +14,6 @@ use std::io::Write;
|
||||
use std::net::TcpStream;
|
||||
use std::path::Path;
|
||||
use std::rc::Rc;
|
||||
use std::sync::Arc;
|
||||
use termwiz::cell::{unicode_column_width, AttributeChange, Intensity};
|
||||
use termwiz::lineedit::*;
|
||||
use termwiz::surface::Change;
|
||||
@ -316,22 +315,15 @@ pub fn ssh_connect(remote_address: &str, username: &str) -> Fallible<ssh2::Sessi
|
||||
|
||||
pub struct RemoteSshDomain {
|
||||
pty_system: Box<dyn PtySystem>,
|
||||
config: Arc<Config>,
|
||||
id: DomainId,
|
||||
name: String,
|
||||
}
|
||||
|
||||
impl RemoteSshDomain {
|
||||
pub fn with_pty_system(
|
||||
name: &str,
|
||||
config: &Arc<Config>,
|
||||
pty_system: Box<dyn PtySystem>,
|
||||
) -> Self {
|
||||
let config = Arc::clone(config);
|
||||
pub fn with_pty_system(name: &str, pty_system: Box<dyn PtySystem>) -> Self {
|
||||
let id = alloc_domain_id();
|
||||
Self {
|
||||
pty_system,
|
||||
config,
|
||||
id,
|
||||
name: name.to_string(),
|
||||
}
|
||||
@ -353,18 +345,20 @@ impl Domain for RemoteSshDomain {
|
||||
let child = pair.slave.spawn_command(cmd)?;
|
||||
log::info!("spawned: {:?}", child);
|
||||
|
||||
let config = configuration();
|
||||
|
||||
let mut terminal = term::Terminal::new(
|
||||
size.rows as usize,
|
||||
size.cols as usize,
|
||||
size.pixel_width as usize,
|
||||
size.pixel_height as usize,
|
||||
self.config.scrollback_lines.unwrap_or(3500),
|
||||
self.config.hyperlink_rules.clone(),
|
||||
config.scrollback_lines.unwrap_or(3500),
|
||||
config.hyperlink_rules.clone(),
|
||||
);
|
||||
|
||||
let mux = Mux::get().unwrap();
|
||||
|
||||
if let Some(palette) = mux.config().colors.as_ref() {
|
||||
if let Some(palette) = configuration().colors.as_ref() {
|
||||
*terminal.palette_mut() = palette.clone().into();
|
||||
}
|
||||
|
||||
|
@ -432,12 +432,11 @@ pub fn run<T: Send + 'static, F: Send + 'static + Fn(TermWizTerminal) -> Fallibl
|
||||
mux.add_tab_to_window(&tab, window_id)?;
|
||||
|
||||
let fontconfig = Rc::new(FontConfiguration::new(
|
||||
Arc::clone(mux.config()),
|
||||
crate::font::FontSystemSelection::get_default(),
|
||||
));
|
||||
|
||||
let gui = front_end().unwrap();
|
||||
gui.spawn_new_window(mux.config(), &fontconfig, &tab, window_id)?;
|
||||
gui.spawn_new_window(&fontconfig, &tab, window_id)?;
|
||||
|
||||
Ok(())
|
||||
});
|
||||
|
Loading…
Reference in New Issue
Block a user