mirror of
https://github.com/alacritty/alacritty.git
synced 2024-11-11 13:51:01 -05:00
Override dynamic_title when --title is specified
This commit is contained in:
parent
5ba34d4f97
commit
f55252ec85
4 changed files with 61 additions and 20 deletions
24
src/cli.rs
24
src/cli.rs
|
@ -18,17 +18,14 @@ use config::{Dimensions, Shell};
|
|||
use std::path::{Path, PathBuf};
|
||||
use std::borrow::Cow;
|
||||
|
||||
const DEFAULT_TITLE: &str = "Alacritty";
|
||||
const DEFAULT_CLASS: &str = "Alacritty";
|
||||
|
||||
/// Options specified on the command line
|
||||
pub struct Options {
|
||||
pub live_config_reload: Option<bool>,
|
||||
pub print_events: bool,
|
||||
pub ref_test: bool,
|
||||
pub dimensions: Option<Dimensions>,
|
||||
pub title: String,
|
||||
pub class: String,
|
||||
pub title: Option<String>,
|
||||
pub class: Option<String>,
|
||||
pub log_level: log::LevelFilter,
|
||||
pub command: Option<Shell<'static>>,
|
||||
pub working_dir: Option<PathBuf>,
|
||||
|
@ -42,8 +39,8 @@ impl Default for Options {
|
|||
print_events: false,
|
||||
ref_test: false,
|
||||
dimensions: None,
|
||||
title: DEFAULT_TITLE.to_owned(),
|
||||
class: DEFAULT_CLASS.to_owned(),
|
||||
title: None,
|
||||
class: None,
|
||||
log_level: log::LevelFilter::Warn,
|
||||
command: None,
|
||||
working_dir: None,
|
||||
|
@ -82,11 +79,11 @@ impl Options {
|
|||
.arg(Arg::with_name("title")
|
||||
.long("title")
|
||||
.short("t")
|
||||
.default_value(DEFAULT_TITLE)
|
||||
.takes_value(true)
|
||||
.help("Defines the window title"))
|
||||
.arg(Arg::with_name("class")
|
||||
.long("class")
|
||||
.default_value(DEFAULT_CLASS)
|
||||
.takes_value(true)
|
||||
.help("Defines window class on X11"))
|
||||
.arg(Arg::with_name("q")
|
||||
.short("q")
|
||||
|
@ -139,13 +136,8 @@ impl Options {
|
|||
}
|
||||
}
|
||||
|
||||
if let Some(title) = matches.value_of("title") {
|
||||
options.title = title.to_owned();
|
||||
}
|
||||
|
||||
if let Some(class) = matches.value_of("class") {
|
||||
options.class = class.to_owned();
|
||||
}
|
||||
options.class = matches.value_of("class").map(|c| c.to_owned());
|
||||
options.title = matches.value_of("title").map(|t| t.to_owned());
|
||||
|
||||
match matches.occurrences_of("q") {
|
||||
0 => {},
|
||||
|
|
|
@ -23,6 +23,7 @@ use notify::{Watcher, watcher, DebouncedEvent, RecursiveMode};
|
|||
|
||||
use glutin::ModifiersState;
|
||||
|
||||
use cli::Options;
|
||||
use input::{Action, Binding, MouseBinding, KeyBinding};
|
||||
use index::{Line, Column};
|
||||
use ansi::CursorStyle;
|
||||
|
@ -1383,6 +1384,14 @@ impl Config {
|
|||
Ok(config)
|
||||
}
|
||||
|
||||
/// Overrides the `dynamic_title` configuration based on `--title`.
|
||||
pub fn update_dynamic_title(mut self, options: &Options) -> Self {
|
||||
if options.title.is_some() {
|
||||
self.dynamic_title = false;
|
||||
}
|
||||
self
|
||||
}
|
||||
|
||||
fn read_file<P: AsRef<Path>>(path: P) -> Result<String> {
|
||||
let mut f = fs::File::open(path)?;
|
||||
let mut contents = String::new();
|
||||
|
@ -1713,6 +1722,7 @@ impl Monitor {
|
|||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use cli::Options;
|
||||
use super::Config;
|
||||
|
||||
#[cfg(target_os="macos")]
|
||||
|
@ -1733,6 +1743,26 @@ mod tests {
|
|||
// Sanity check that key bindings are being parsed
|
||||
assert!(!config.key_bindings.is_empty());
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn dynamic_title_ignoring_options_by_default() {
|
||||
let config: Config = ::serde_yaml::from_str(ALACRITTY_YML)
|
||||
.expect("deserialize config");
|
||||
let old_dynamic_title = config.dynamic_title;
|
||||
let options = Options::default();
|
||||
let config = config.update_dynamic_title(&options);
|
||||
assert_eq!(old_dynamic_title, config.dynamic_title);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn dynamic_title_overridden_by_options() {
|
||||
let config: Config = ::serde_yaml::from_str(ALACRITTY_YML)
|
||||
.expect("deserialize config");
|
||||
let mut options = Options::default();
|
||||
options.title = Some("foo".to_owned());
|
||||
let config = config.update_dynamic_title(&options);
|
||||
assert!(!config.dynamic_title);
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg_attr(feature = "cargo-clippy", allow(enum_variant_names))]
|
||||
|
|
|
@ -44,7 +44,7 @@ use alacritty::util::fmt::Red;
|
|||
fn main() {
|
||||
// Load command line options and config
|
||||
let options = cli::Options::load();
|
||||
let config = load_config(&options);
|
||||
let config = load_config(&options).update_dynamic_title(&options);
|
||||
|
||||
// Switch to home directory
|
||||
#[cfg(target_os = "macos")]
|
||||
|
@ -178,7 +178,7 @@ fn run(mut config: Config, options: &cli::Options) -> Result<(), Box<Error>> {
|
|||
.as_ref()
|
||||
.and_then(|monitor| monitor.pending_config())
|
||||
{
|
||||
config = new_config;
|
||||
config = new_config.update_dynamic_title(&options);
|
||||
display.update_config(&config);
|
||||
processor.update_config(&config);
|
||||
terminal.update_config(&config);
|
||||
|
|
|
@ -25,6 +25,23 @@ use MouseCursor;
|
|||
use cli::Options;
|
||||
use config::WindowConfig;
|
||||
|
||||
/// Default text for the window's title bar, if not overriden.
|
||||
///
|
||||
/// In X11, this the default value for the `WM_NAME` property.
|
||||
pub const DEFAULT_TITLE: &str = "Alacritty";
|
||||
|
||||
/// Default text for general window class, X11 specific.
|
||||
///
|
||||
/// In X11, this is the default value for the `WM_CLASS` property. The
|
||||
/// second value of `WM_CLASS` is **never** changed to anything but
|
||||
/// the default value.
|
||||
///
|
||||
/// ```ignore
|
||||
/// $ xprop | grep WM_CLASS
|
||||
/// WM_CLASS(STRING) = "Alacritty", "Alacritty"
|
||||
/// ```
|
||||
pub const DEFAULT_CLASS: &str = "Alacritty";
|
||||
|
||||
/// Window errors
|
||||
#[derive(Debug)]
|
||||
pub enum Error {
|
||||
|
@ -205,12 +222,14 @@ impl Window {
|
|||
) -> Result<Window> {
|
||||
let event_loop = EventsLoop::new();
|
||||
|
||||
let title = options.title.as_ref().map_or(DEFAULT_TITLE, |t| t);
|
||||
let class = options.class.as_ref().map_or(DEFAULT_CLASS, |c| c);
|
||||
let window_builder = WindowBuilder::new()
|
||||
.with_title(&*options.title)
|
||||
.with_title(title)
|
||||
.with_visibility(false)
|
||||
.with_transparency(true)
|
||||
.with_decorations(window_config.decorations());
|
||||
let window_builder = Window::platform_builder_ext(window_builder, &options.class);
|
||||
let window_builder = Window::platform_builder_ext(window_builder, &class);
|
||||
let window = create_gl_window(window_builder.clone(), &event_loop, false)
|
||||
.or_else(|_| create_gl_window(window_builder, &event_loop, true))?;
|
||||
window.show();
|
||||
|
|
Loading…
Reference in a new issue