Skip to content

Commit

Permalink
Adding dynamic_title property to configuration (alacritty#819)
Browse files Browse the repository at this point in the history
This logic is applied in Term's ansi::Handler implementation
to avoid unnecessary allocations.
  • Loading branch information
Wesley Gahr authored and chrisduerr committed Jan 18, 2018
1 parent 50253fa commit aa96cd3
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 1 deletion.
2 changes: 2 additions & 0 deletions alacritty.yml
Original file line number Diff line number Diff line change
Expand Up @@ -204,6 +204,8 @@ mouse:
selection:
semantic_escape_chars: ",│`|:\"' ()[]{}<>"

dynamic_title: true

hide_cursor_when_typing: false

# Style of the cursor
Expand Down
2 changes: 2 additions & 0 deletions alacritty_macos.yml
Original file line number Diff line number Diff line change
Expand Up @@ -185,6 +185,8 @@ mouse:
selection:
semantic_escape_chars: ",│`|:\"' ()[]{}<>"

dynamic_title: true

hide_cursor_when_typing: false

# Style of the cursor
Expand Down
10 changes: 10 additions & 0 deletions src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -322,6 +322,10 @@ pub struct Config {
#[serde(default)]
visual_bell: VisualBellConfig,

/// Use dynamic title
#[serde(default="true_bool")]
dynamic_title: bool,

/// Hide cursor when typing
#[serde(default)]
hide_cursor_when_typing: bool,
Expand Down Expand Up @@ -386,6 +390,7 @@ impl Default for Config {
env: Default::default(),
hide_cursor_when_typing: Default::default(),
cursor_style: Default::default(),
dynamic_title: Default::default(),
live_config_reload: true,
window: Default::default(),
}
Expand Down Expand Up @@ -1255,6 +1260,11 @@ impl Config {
self.live_config_reload
}

#[inline]
pub fn dynamic_title(&self) -> bool {
self.dynamic_title
}

pub fn load_from<P: Into<PathBuf>>(path: P) -> Result<Config> {
let path = path.into();
let raw = Config::read_file(path.as_path())?;
Expand Down
8 changes: 7 additions & 1 deletion src/term/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -703,6 +703,8 @@ pub struct Term {

/// Default style for resetting the cursor
default_cursor_style: CursorStyle,

dynamic_title: bool,
}

/// Terminal size info
Expand Down Expand Up @@ -806,6 +808,7 @@ impl Term {
semantic_escape_chars: config.selection().semantic_escape_chars.clone(),
cursor_style: None,
default_cursor_style: config.cursor_style(),
dynamic_title: config.dynamic_title(),
}
}

Expand All @@ -831,6 +834,7 @@ impl Term {
}
self.visual_bell.update_config(config);
self.default_cursor_style = config.cursor_style();
self.dynamic_title = config.dynamic_title();
}

#[inline]
Expand Down Expand Up @@ -1159,7 +1163,9 @@ impl ansi::Handler for Term {
/// Set the window title
#[inline]
fn set_title(&mut self, title: &str) {
self.next_title = Some(title.to_owned());
if self.dynamic_title {
self.next_title = Some(title.to_owned());
}
}

/// A character to be displayed
Expand Down

0 comments on commit aa96cd3

Please sign in to comment.