From 93780ef0929e08f3c5212e5451152ecaf1a28813 Mon Sep 17 00:00:00 2001 From: Christian Duerr Date: Thu, 7 Jun 2018 15:52:06 +0000 Subject: Allow disabling DPI scaling This makes it possible to disable DPI scaling completely, instead the the display pixel ration will always be fixed to 1.0. By default nothing has changed and DPI is still enabled, this just seems like a better way than running `WINIT_HIDPI_FACTOR=1.0 alacritty` every time the user wants to start alacritty. It would be possible to allow specifying any DPR, however I've decided against this since I'd assume it's a very rare usecase. It's also still possible to make use of `WINIT_HIDPI_FACTOR` to do this on X11. Currently this is not updated at runtime using the live config update, there is not really much of a technical limitation why this woudn't be possible, however a solution for that issue should be first added in jwilm/alacritty#1346, once a system is established for changing DPI at runtime, porting that functionality to this PR should be simple. --- src/config.rs | 16 +++++++++++++--- src/display.rs | 11 +++++++---- 2 files changed, 20 insertions(+), 7 deletions(-) (limited to 'src') diff --git a/src/config.rs b/src/config.rs index 40c550b0..a8034139 100644 --- a/src/config.rs +++ b/src/config.rs @@ -1541,7 +1541,10 @@ pub struct Font { glyph_offset: Delta, #[serde(default="true_bool", deserialize_with = "default_true_bool")] - use_thin_strokes: bool + use_thin_strokes: bool, + + #[serde(default="true_bool", deserialize_with = "default_true_bool")] + scale_with_dpi: bool, } fn default_bold_desc() -> FontDescription { @@ -1594,6 +1597,11 @@ impl Font { .. self } } + + /// Check whether dpi should be applied + pub fn scale_with_dpi(&self) -> bool { + self.scale_with_dpi + } } #[cfg(target_os = "macos")] @@ -1605,8 +1613,9 @@ impl Default for Font { italic: FontDescription::new_with_family("Menlo"), size: Size::new(11.0), use_thin_strokes: true, + scale_with_dpi: true, + glyph_offset: Default::default(), offset: Default::default(), - glyph_offset: Default::default() } } } @@ -1620,8 +1629,9 @@ impl Default for Font { italic: FontDescription::new_with_family("monospace"), size: Size::new(11.0), use_thin_strokes: false, + scale_with_dpi: true, + glyph_offset: Default::default(), offset: Default::default(), - glyph_offset: Default::default() } } } diff --git a/src/display.rs b/src/display.rs index 733c66e8..2b87bf50 100644 --- a/src/display.rs +++ b/src/display.rs @@ -142,7 +142,11 @@ impl Display { // get window properties for initializing the other subsystems let mut viewport_size = window.inner_size_pixels() .expect("glutin returns window size"); - let dpr = window.hidpi_factor(); + let dpr = if config.font().scale_with_dpi() { + window.hidpi_factor() + } else { + 1.0 + }; info!("device_pixel_ratio: {}", dpr); @@ -150,7 +154,7 @@ impl Display { let mut renderer = QuadRenderer::new(config, viewport_size)?; let (glyph_cache, cell_width, cell_height) = - Self::new_glyph_cache(&window, &mut renderer, config)?; + Self::new_glyph_cache(dpr, &mut renderer, config)?; let dimensions = options.dimensions() @@ -211,11 +215,10 @@ impl Display { }) } - fn new_glyph_cache(window : &Window, renderer : &mut QuadRenderer, config: &Config) + fn new_glyph_cache(dpr: f32, renderer: &mut QuadRenderer, config: &Config) -> Result<(GlyphCache, f32, f32), Error> { let font = config.font().clone(); - let dpr = window.hidpi_factor(); let rasterizer = font::Rasterizer::new(dpr, config.use_thin_strokes())?; // Initialize glyph cache -- cgit From 66acf1e03da4d0206e3368bf58953b071887ccb2 Mon Sep 17 00:00:00 2001 From: Tezkerek Date: Thu, 7 Jun 2018 19:53:16 +0300 Subject: Add working --class and --title CLI parameters --- src/cli.rs | 11 +++++++++++ src/display.rs | 2 +- src/window.rs | 13 +++++++------ 3 files changed, 19 insertions(+), 7 deletions(-) (limited to 'src') diff --git a/src/cli.rs b/src/cli.rs index 532c46cd..e57caf0d 100644 --- a/src/cli.rs +++ b/src/cli.rs @@ -19,6 +19,7 @@ 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 { @@ -27,6 +28,7 @@ pub struct Options { pub ref_test: bool, pub dimensions: Option, pub title: String, + pub class: String, pub log_level: log::LevelFilter, pub command: Option>, pub working_dir: Option, @@ -41,6 +43,7 @@ impl Default for Options { ref_test: false, dimensions: None, title: DEFAULT_TITLE.to_owned(), + class: DEFAULT_CLASS.to_owned(), log_level: log::LevelFilter::Warn, command: None, working_dir: None, @@ -81,6 +84,10 @@ impl Options { .short("t") .default_value(DEFAULT_TITLE) .help("Defines the window title")) + .arg(Arg::with_name("class") + .long("class") + .default_value(DEFAULT_CLASS) + .help("Defines window class on X11")) .arg(Arg::with_name("q") .short("q") .multiple(true) @@ -136,6 +143,10 @@ impl Options { options.title = title.to_owned(); } + if let Some(class) = matches.value_of("class") { + options.class = class.to_owned(); + } + match matches.occurrences_of("q") { 0 => {}, 1 => options.log_level = log::LevelFilter::Error, diff --git a/src/display.rs b/src/display.rs index 2b87bf50..e0453f72 100644 --- a/src/display.rs +++ b/src/display.rs @@ -137,7 +137,7 @@ impl Display { let render_timer = config.render_timer(); // Create the window where Alacritty will be displayed - let mut window = Window::new(&options.title, config.window())?; + let mut window = Window::new(&options, config.window())?; // get window properties for initializing the other subsystems let mut viewport_size = window.inner_size_pixels() diff --git a/src/window.rs b/src/window.rs index 987332e0..ef0d9269 100644 --- a/src/window.rs +++ b/src/window.rs @@ -22,6 +22,7 @@ use glutin::GlContext; use MouseCursor; +use cli::Options; use config::WindowConfig; /// Window errors @@ -199,17 +200,17 @@ impl Window { /// /// This creates a window and fully initializes a window. pub fn new( - title: &str, + options: &Options, window_config: &WindowConfig, ) -> Result { let event_loop = EventsLoop::new(); let window_builder = WindowBuilder::new() - .with_title(title) + .with_title(&*options.title) .with_visibility(false) .with_transparency(true) .with_decorations(window_config.decorations()); - let window_builder = Window::platform_builder_ext(window_builder); + let window_builder = Window::platform_builder_ext(window_builder, &options.class); let window = create_gl_window(window_builder.clone(), &event_loop, false) .or_else(|_| create_gl_window(window_builder, &event_loop, true))?; window.show(); @@ -322,13 +323,13 @@ impl Window { } #[cfg(any(target_os = "linux", target_os = "freebsd", target_os = "dragonfly", target_os = "openbsd"))] - fn platform_builder_ext(window_builder: WindowBuilder) -> WindowBuilder { + fn platform_builder_ext(window_builder: WindowBuilder, wm_class: &str) -> WindowBuilder { use glutin::os::unix::WindowBuilderExt; - window_builder.with_class("alacritty".to_owned(), "Alacritty".to_owned()) + window_builder.with_class(wm_class.to_owned(), "Alacritty".to_owned()) } #[cfg(not(any(target_os = "linux", target_os = "freebsd", target_os = "dragonfly", target_os = "openbsd")))] - fn platform_builder_ext(window_builder: WindowBuilder) -> WindowBuilder { + fn platform_builder_ext(window_builder: WindowBuilder, _: &str) -> WindowBuilder { window_builder } -- cgit From 6cbae83f174fa6d114ea66b1f8dd6185950ca835 Mon Sep 17 00:00:00 2001 From: Felippe da Motta Raposo Date: Fri, 8 Jun 2018 16:32:21 -0700 Subject: Reduce Increase-/DecreaseFontSize step to 0.5 Until now the Increase-/DecreaseFontSize keybinds hand a step size of 1.0. Since the font size however is multiplied by two to allow more granular font size control, this lead to the bindings skipping one font size (incrementing/decrementing by +-2). To fix this the step size of the Increase-/DecreaseFontSize bindings has been reduced to the minimum step size that exists with the current font configuration (0.5). This should allow users to increment and decrement the font size by a single point instead of two. This also adds a few tests to make sure the methods for increasing/decreasing/resetting font size work properly. --- src/event.rs | 2 +- src/input.rs | 10 +++++--- src/term/mod.rs | 78 ++++++++++++++++++++++++++++++++++++++++++++++++++++++--- 3 files changed, 81 insertions(+), 9 deletions(-) (limited to 'src') diff --git a/src/event.rs b/src/event.rs index 4ae25860..f592da5c 100644 --- a/src/event.rs +++ b/src/event.rs @@ -106,7 +106,7 @@ impl<'a, N: Notify + 'a> input::ActionContext for ActionContext<'a, N> { self.terminal.pixels_to_coords(self.mouse.x as usize, self.mouse.y as usize) } - fn change_font_size(&mut self, delta: i8) { + fn change_font_size(&mut self, delta: f32) { self.terminal.change_font_size(delta); } diff --git a/src/input.rs b/src/input.rs index 2d603783..7afd359d 100644 --- a/src/input.rs +++ b/src/input.rs @@ -34,6 +34,8 @@ use term::SizeInfo; use term::mode::TermMode; use util::fmt::Red; +pub const FONT_SIZE_STEP: f32 = 0.5; + /// Processes input from glutin. /// /// An escape sequence may be emitted in case specific keys or key combinations @@ -62,7 +64,7 @@ pub trait ActionContext { fn received_count(&mut self) -> &mut usize; fn suppress_chars(&mut self) -> &mut bool; fn last_modifiers(&mut self) -> &mut ModifiersState; - fn change_font_size(&mut self, delta: i8); + fn change_font_size(&mut self, delta: f32); fn reset_font_size(&mut self); } @@ -227,10 +229,10 @@ impl Action { ::std::process::exit(0); }, Action::IncreaseFontSize => { - ctx.change_font_size(1); + ctx.change_font_size(FONT_SIZE_STEP); }, Action::DecreaseFontSize => { - ctx.change_font_size(-1); + ctx.change_font_size(-FONT_SIZE_STEP); } Action::ResetFontSize => { ctx.reset_font_size(); @@ -698,7 +700,7 @@ mod tests { fn last_modifiers(&mut self) -> &mut ModifiersState { &mut self.last_modifiers } - fn change_font_size(&mut self, _delta: i8) { + fn change_font_size(&mut self, _delta: f32) { } fn reset_font_size(&mut self) { } diff --git a/src/term/mod.rs b/src/term/mod.rs index 4f56e7fc..27cc9312 100644 --- a/src/term/mod.rs +++ b/src/term/mod.rs @@ -30,6 +30,7 @@ use selection::{self, Span, Selection}; use config::{Config, VisualBellAnimation}; use {MouseCursor, Rgb}; use copypasta::{Clipboard, Load, Store}; +use input::FONT_SIZE_STEP; pub mod cell; pub mod color; @@ -841,10 +842,10 @@ impl Term { } } - pub fn change_font_size(&mut self, delta: i8) { - // Saturating addition with minimum font size 1 - let new_size = self.font_size + Size::new(f32::from(delta)); - self.font_size = max(new_size, Size::new(1.)); + pub fn change_font_size(&mut self, delta: f32) { + // Saturating addition with minimum font size FONT_SIZE_STEP + let new_size = self.font_size + Size::new(delta); + self.font_size = max(new_size, Size::new(FONT_SIZE_STEP)); self.dirty = true; } @@ -1947,6 +1948,9 @@ mod tests { use ansi::{Handler, CharsetIndex, StandardCharset}; use selection::Selection; use std::mem; + use input::FONT_SIZE_STEP; + use font::Size; + use config::Config; #[test] fn semantic_selection_works() { @@ -2052,6 +2056,72 @@ mod tests { assert_eq!(term.grid()[&cursor].c, '▒'); } + + fn change_font_size_works(font_size: f32) { + let size = SizeInfo { + width: 21.0, + height: 51.0, + cell_width: 3.0, + cell_height: 3.0, + padding_x: 0.0, + padding_y: 0.0, + }; + let config: Config = Default::default(); + let mut term: Term = Term::new(&config, size); + term.change_font_size(font_size); + + let expected_font_size: Size = config.font().size() + Size::new(font_size); + assert_eq!(term.font_size, expected_font_size); + } + + #[test] + fn increase_font_size_works() { + change_font_size_works(10.0); + } + + #[test] + fn decrease_font_size_works() { + change_font_size_works(-10.0); + } + + #[test] + fn prevent_font_below_threshold_works() { + let size = SizeInfo { + width: 21.0, + height: 51.0, + cell_width: 3.0, + cell_height: 3.0, + padding_x: 0.0, + padding_y: 0.0, + }; + let config: Config = Default::default(); + let mut term: Term = Term::new(&config, size); + + term.change_font_size(-100.0); + + let expected_font_size: Size = Size::new(FONT_SIZE_STEP); + assert_eq!(term.font_size, expected_font_size); + } + + #[test] + fn reset_font_size_works() { + let size = SizeInfo { + width: 21.0, + height: 51.0, + cell_width: 3.0, + cell_height: 3.0, + padding_x: 0.0, + padding_y: 0.0, + }; + let config: Config = Default::default(); + let mut term: Term = Term::new(&config, size); + + term.change_font_size(10.0); + term.reset_font_size(); + + let expected_font_size: Size = config.font().size(); + assert_eq!(term.font_size, expected_font_size); + } } #[cfg(all(test, feature = "bench"))] -- cgit From 0f700a01bd73623cdfc0afc4a54f9e82f46d8f49 Mon Sep 17 00:00:00 2001 From: Christian Duerr Date: Sat, 16 Jun 2018 10:11:47 +0000 Subject: Add Copy/Cut/Paste keys This just adds support for the Copy/Cut/Paste keys and sets up Copy/Paste as alternative defaults for Ctrl+Shift+C/V. --- src/config.rs | 6 ++++++ 1 file changed, 6 insertions(+) (limited to 'src') diff --git a/src/config.rs b/src/config.rs index a8034139..88a14b22 100644 --- a/src/config.rs +++ b/src/config.rs @@ -1889,6 +1889,9 @@ enum Key { WebStop, Yen, Caret, + Copy, + Paste, + Cut, } impl Key { @@ -2047,6 +2050,9 @@ impl Key { Key::WebStop => WebStop, Key::Yen => Yen, Key::Caret => Caret, + Key::Copy => Copy, + Key::Paste => Paste, + Key::Cut => Cut, } } } -- cgit From 5ba34d4f9766a55a06ed5e3e44cc384af1b09f65 Mon Sep 17 00:00:00 2001 From: Christian Duerr Date: Sun, 17 Jun 2018 09:19:30 +0000 Subject: Move to cargo clippy Using clippy as a library has been deprecated, instead the `cargo clippy` command should be used instead. To comply with this change clippy has been removed from the `Cargo.toml` and is now installed with cargo when building in CI. This has also lead to a few new clippy issues to show up, this includes everything in the `font` subdirectory. This has been fixed and `font` should now be covered by clippy CI too. This also upgrades all dependencies, as a result this fixes #1341 and this fixes #1344. --- src/config.rs | 2 +- src/lib.rs | 8 ++------ src/locale.rs | 1 + src/logging.rs | 2 +- src/main.rs | 7 +------ src/tty.rs | 2 +- 6 files changed, 7 insertions(+), 15 deletions(-) (limited to 'src') diff --git a/src/config.rs b/src/config.rs index 88a14b22..ed69ec5d 100644 --- a/src/config.rs +++ b/src/config.rs @@ -1735,7 +1735,7 @@ mod tests { } } -#[cfg_attr(feature = "clippy", allow(enum_variant_names))] +#[cfg_attr(feature = "cargo-clippy", allow(enum_variant_names))] #[derive(Deserialize, Copy, Clone)] enum Key { Key1, diff --git a/src/lib.rs b/src/lib.rs index a8e18451..afbd8595 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -13,12 +13,7 @@ // limitations under the License. // //! Alacritty - The GPU Enhanced Terminal -#![cfg_attr(feature = "clippy", feature(plugin))] -#![cfg_attr(feature = "clippy", plugin(clippy))] -#![cfg_attr(feature = "clippy", deny(clippy))] -#![cfg_attr(feature = "clippy", deny(enum_glob_use))] -#![cfg_attr(feature = "clippy", deny(if_not_else))] -#![cfg_attr(feature = "clippy", deny(wrong_pub_self_convention))] +#![cfg_attr(feature = "cargo-clippy", deny(clippy, if_not_else, enum_glob_use, wrong_pub_self_convention))] #![cfg_attr(feature = "nightly", feature(core_intrinsics))] #![cfg_attr(all(test, feature = "bench"), feature(test))] @@ -121,5 +116,6 @@ impl Mul for Rgb { #[allow(unused_mut)] pub mod gl { #![allow(non_upper_case_globals)] + #![cfg_attr(feature = "cargo-clippy", allow(clippy))] include!(concat!(env!("OUT_DIR"), "/gl_bindings.rs")); } diff --git a/src/locale.rs b/src/locale.rs index 9fcd2db2..bea68cad 100644 --- a/src/locale.rs +++ b/src/locale.rs @@ -11,6 +11,7 @@ // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. // See the License for the specific language governing permissions and // limitations under the License. +#![cfg_attr(feature = "cargo-clippy", allow(let_unit_value))] #![cfg(target_os = "macos")] use libc::{LC_CTYPE, setlocale}; use std::ffi::{CString, CStr}; diff --git a/src/logging.rs b/src/logging.rs index 5691eb78..a691778a 100644 --- a/src/logging.rs +++ b/src/logging.rs @@ -29,7 +29,7 @@ pub struct Logger { impl Logger { // False positive, see: https://github.com/rust-lang-nursery/rust-clippy/issues/734 - #[cfg_attr(feature = "clippy", allow(new_ret_no_self))] + #[cfg_attr(feature = "cargo-clippy", allow(new_ret_no_self))] pub fn new(output: T, level: log::LevelFilter) -> Logger> { log::set_max_level(level); Logger { diff --git a/src/main.rs b/src/main.rs index c45dfda5..b0e507e4 100644 --- a/src/main.rs +++ b/src/main.rs @@ -13,12 +13,7 @@ // limitations under the License. // //! Alacritty - The GPU Enhanced Terminal -#![cfg_attr(feature = "clippy", feature(plugin))] -#![cfg_attr(feature = "clippy", plugin(clippy))] -#![cfg_attr(feature = "clippy", deny(clippy))] -#![cfg_attr(feature = "clippy", deny(enum_glob_use))] -#![cfg_attr(feature = "clippy", deny(if_not_else))] -#![cfg_attr(feature = "clippy", deny(wrong_pub_self_convention))] +#![cfg_attr(feature = "cargo-clippy", deny(clippy, if_not_else, enum_glob_use, wrong_pub_self_convention))] #![cfg_attr(feature = "nightly", feature(core_intrinsics))] #![cfg_attr(all(test, feature = "bench"), feature(test))] diff --git a/src/tty.rs b/src/tty.rs index 166a788e..4da11c0e 100644 --- a/src/tty.rs +++ b/src/tty.rs @@ -117,7 +117,7 @@ fn set_controlling_terminal(fd: c_int) { // based on architecture (32/64). So a generic cast is used to make sure // there are no issues. To allow such a generic cast the clippy warning // is disabled. - #[cfg_attr(feature = "clippy", allow(cast_lossless))] + #[cfg_attr(feature = "cargo-clippy", allow(cast_lossless))] libc::ioctl(fd, TIOCSCTTY as _, 0) }; -- cgit From f55252ec8537e68d0c98a1fac35728a2b596d328 Mon Sep 17 00:00:00 2001 From: Nathan Lilienthal Date: Mon, 18 Jun 2018 01:26:54 -0400 Subject: Override dynamic_title when --title is specified --- src/cli.rs | 24 ++++++++---------------- src/config.rs | 30 ++++++++++++++++++++++++++++++ src/main.rs | 4 ++-- src/window.rs | 23 +++++++++++++++++++++-- 4 files changed, 61 insertions(+), 20 deletions(-) (limited to 'src') diff --git a/src/cli.rs b/src/cli.rs index e57caf0d..92b83f6c 100644 --- a/src/cli.rs +++ b/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, pub print_events: bool, pub ref_test: bool, pub dimensions: Option, - pub title: String, - pub class: String, + pub title: Option, + pub class: Option, pub log_level: log::LevelFilter, pub command: Option>, pub working_dir: Option, @@ -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 => {}, diff --git a/src/config.rs b/src/config.rs index ed69ec5d..539edb61 100644 --- a/src/config.rs +++ b/src/config.rs @@ -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>(path: P) -> Result { 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))] diff --git a/src/main.rs b/src/main.rs index b0e507e4..652569be 100644 --- a/src/main.rs +++ b/src/main.rs @@ -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> { .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); diff --git a/src/window.rs b/src/window.rs index ef0d9269..1903360f 100644 --- a/src/window.rs +++ b/src/window.rs @@ -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 { 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(); -- cgit From 128c25ee8b31473a6514e9bcaa59d8f9e66ea3a7 Mon Sep 17 00:00:00 2001 From: asoderman <5639572+asoderman@users.noreply.github.com> Date: Tue, 19 Jun 2018 17:27:47 -0400 Subject: Change green implementation to use the macro --- src/util.rs | 18 +++--------------- 1 file changed, 3 insertions(+), 15 deletions(-) (limited to 'src') diff --git a/src/util.rs b/src/util.rs index f51a41f8..062e7651 100644 --- a/src/util.rs +++ b/src/util.rs @@ -74,24 +74,12 @@ pub mod fmt { /// Write a `Display` or `Debug` escaped with Red pub struct Red => "31"; + /// Write a `Display` or `Debug` escaped with Green + pub struct Green => "32"; + /// Write a `Display` or `Debug` escaped with Yellow pub struct Yellow => "33"; } - - /// Write a `Display` or `Debug` escaped with Red - pub struct Green(pub T); - - impl fmt::Display for Green { - fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { - write!(f, "\x1b[32m{}\x1b[0m", self.0) - } - } - - impl fmt::Debug for Green { - fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { - write!(f, "\x1b[32m{:?}\x1b[0m", self.0) - } - } } #[cfg(test)] -- cgit From caf4580daa31c4c7249331b32826124d2b2b4143 Mon Sep 17 00:00:00 2001 From: Felippe da Motta Raposo Date: Sat, 23 Jun 2018 03:13:19 -0700 Subject: Ignore mouse input if window is unfocused --- src/event.rs | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) (limited to 'src') diff --git a/src/event.rs b/src/event.rs index f592da5c..cff013e3 100644 --- a/src/event.rs +++ b/src/event.rs @@ -301,9 +301,11 @@ impl Processor { processor.received_char(c); }, MouseInput { state, button, modifiers, .. } => { - *hide_cursor = false; - processor.mouse_input(state, button, modifiers); - processor.ctx.terminal.dirty = true; + if *window_is_focused { + *hide_cursor = false; + processor.mouse_input(state, button, modifiers); + processor.ctx.terminal.dirty = true; + } }, CursorMoved { position: (x, y), modifiers, .. } => { let x = x as i32; -- cgit From 12afbd007db8a8995617b3e7ebda3840860bbadc Mon Sep 17 00:00:00 2001 From: Christian Duerr Date: Sun, 1 Jul 2018 16:31:46 +0000 Subject: Fix clippy issues --- src/ansi.rs | 8 ++++---- src/config.rs | 6 +++--- src/event.rs | 2 +- src/index.rs | 22 +++++++++++----------- src/input.rs | 28 ++++++++++++++-------------- src/renderer/mod.rs | 14 +++++++------- src/selection.rs | 8 ++++---- src/term/mod.rs | 22 +++++++++++----------- 8 files changed, 55 insertions(+), 55 deletions(-) (limited to 'src') diff --git a/src/ansi.rs b/src/ansi.rs index dbc361a8..e37e25f1 100644 --- a/src/ansi.rs +++ b/src/ansi.rs @@ -561,8 +561,8 @@ pub enum NamedColor { } impl NamedColor { - pub fn to_bright(&self) -> Self { - match *self { + pub fn to_bright(self) -> Self { + match self { NamedColor::Black => NamedColor::BrightBlack, NamedColor::Red => NamedColor::BrightRed, NamedColor::Green => NamedColor::BrightGreen, @@ -583,8 +583,8 @@ impl NamedColor { } } - pub fn to_dim(&self) -> Self { - match *self { + pub fn to_dim(self) -> Self { + match self { NamedColor::Black => NamedColor::DimBlack, NamedColor::Red => NamedColor::DimRed, NamedColor::Green => NamedColor::DimGreen, diff --git a/src/config.rs b/src/config.rs index 539edb61..cdf1dc21 100644 --- a/src/config.rs +++ b/src/config.rs @@ -242,7 +242,7 @@ impl Alpha { } #[inline] - pub fn get(&self) -> f32 { + pub fn get(self) -> f32 { self.0 } @@ -1925,10 +1925,10 @@ enum Key { } impl Key { - fn to_glutin_key(&self) -> ::glutin::VirtualKeyCode { + fn to_glutin_key(self) -> ::glutin::VirtualKeyCode { use ::glutin::VirtualKeyCode::*; // Thank you, vim macros! - match *self { + match self { Key::Key1 => Key1, Key::Key2 => Key2, Key::Key3 => Key3, diff --git a/src/event.rs b/src/event.rs index cff013e3..c10f8a72 100644 --- a/src/event.rs +++ b/src/event.rs @@ -291,7 +291,7 @@ impl Processor { }, KeyboardInput { input, .. } => { let glutin::KeyboardInput { state, virtual_keycode, modifiers, .. } = input; - processor.process_key(state, virtual_keycode, &modifiers); + processor.process_key(state, virtual_keycode, modifiers); if state == ElementState::Pressed { // Hide cursor while typing *hide_cursor = true; diff --git a/src/index.rs b/src/index.rs index 418faff2..c5ae0794 100644 --- a/src/index.rs +++ b/src/index.rs @@ -270,7 +270,7 @@ macro_rules! inclusive { match *self { Empty { .. } => (0, Some(0)), - NonEmpty { ref start, ref end } => { + NonEmpty { start, end } => { let added = $steps_add_one(start, end); match added { Some(hint) => (hint.saturating_add(1), hint.checked_add(1)), @@ -283,9 +283,9 @@ macro_rules! inclusive { } } -fn steps_add_one_u8(start: &u8, end: &u8) -> Option { - if *start < *end { - Some((*end - *start) as usize) +fn steps_add_one_u8(start: u8, end: u8) -> Option { + if start < end { + Some((end - start) as usize) } else { None } @@ -330,11 +330,11 @@ macro_rules! ops { impl $ty { #[inline] #[allow(trivial_numeric_casts)] - fn steps_between(start: &$ty, end: &$ty, by: &$ty) -> Option { - if *by == $construct(0) { return None; } - if *start < *end { + fn steps_between(start: $ty, end: $ty, by: $ty) -> Option { + if by == $construct(0) { return None; } + if start < end { // Note: We assume $t <= usize here - let diff = (*end - *start).0; + let diff = (end - start).0; let by = by.0; if diff % by > 0 { Some(diff / by + 1) @@ -347,8 +347,8 @@ macro_rules! ops { } #[inline] - fn steps_between_by_one(start: &$ty, end: &$ty) -> Option { - Self::steps_between(start, end, &$construct(1)) + fn steps_between_by_one(start: $ty, end: $ty) -> Option { + Self::steps_between(start, end, $construct(1)) } } @@ -366,7 +366,7 @@ macro_rules! ops { } #[inline] fn size_hint(&self) -> (usize, Option) { - match Self::Item::steps_between_by_one(&self.0.start, &self.0.end) { + match Self::Item::steps_between_by_one(self.0.start, self.0.end) { Some(hint) => (hint, Some(hint)), None => (0, None) } diff --git a/src/input.rs b/src/input.rs index 7afd359d..aa00ee3d 100644 --- a/src/input.rs +++ b/src/input.rs @@ -102,15 +102,15 @@ impl Binding { fn is_triggered_by( &self, mode: TermMode, - mods: &ModifiersState, + mods: ModifiersState, input: &T ) -> bool { // Check input first since bindings are stored in one big list. This is // the most likely item to fail so prioritizing it here allows more // checks to be short circuited. self.trigger == *input && - self.mode_matches(&mode) && - self.not_mode_matches(&mode) && + self.mode_matches(mode) && + self.not_mode_matches(mode) && self.mods_match(mods) } } @@ -123,12 +123,12 @@ impl Binding { } #[inline] - fn mode_matches(&self, mode: &TermMode) -> bool { + fn mode_matches(&self, mode: TermMode) -> bool { self.mode.is_empty() || mode.intersects(self.mode) } #[inline] - fn not_mode_matches(&self, mode: &TermMode) -> bool { + fn not_mode_matches(&self, mode: TermMode) -> bool { self.notmode.is_empty() || !mode.intersects(self.notmode) } @@ -136,10 +136,10 @@ impl Binding { /// /// Optimized to use single check instead of four (one per modifier) #[inline] - fn mods_match(&self, mods: &ModifiersState) -> bool { + fn mods_match(&self, mods: ModifiersState) -> bool { debug_assert!(4 == mem::size_of::()); unsafe { - mem::transmute_copy::<_, u32>(&self.mods) == mem::transmute_copy::<_, u32>(mods) + mem::transmute_copy::<_, u32>(&self.mods) == mem::transmute_copy::<_, u32>(&mods) } } } @@ -532,7 +532,7 @@ impl<'a, A: ActionContext + 'a> Processor<'a, A> { return; } - self.process_mouse_bindings(&ModifiersState::default(), button); + self.process_mouse_bindings(ModifiersState::default(), button); } /// Process key input @@ -542,11 +542,11 @@ impl<'a, A: ActionContext + 'a> Processor<'a, A> { &mut self, state: ElementState, key: Option, - mods: &ModifiersState, + mods: ModifiersState, ) { match (key, state) { (Some(key), ElementState::Pressed) => { - *self.ctx.last_modifiers() = *mods; + *self.ctx.last_modifiers() = mods; *self.ctx.received_count() = 0; *self.ctx.suppress_chars() = false; @@ -587,7 +587,7 @@ impl<'a, A: ActionContext + 'a> Processor<'a, A> { /// for its action to be executed. /// /// Returns true if an action is executed. - fn process_key_bindings(&mut self, mods: &ModifiersState, key: VirtualKeyCode) -> bool { + fn process_key_bindings(&mut self, mods: ModifiersState, key: VirtualKeyCode) -> bool { for binding in self.key_bindings { if binding.is_triggered_by(self.ctx.terminal_mode(), mods, &key) { // binding was triggered; run the action @@ -605,7 +605,7 @@ impl<'a, A: ActionContext + 'a> Processor<'a, A> { /// for its action to be executed. /// /// Returns true if an action is executed. - fn process_mouse_bindings(&mut self, mods: &ModifiersState, button: MouseButton) -> bool { + fn process_mouse_bindings(&mut self, mods: ModifiersState, button: MouseButton) -> bool { for binding in self.mouse_bindings { if binding.is_triggered_by(self.ctx.terminal_mode(), mods, &button) { // binding was triggered; run the action @@ -782,9 +782,9 @@ mod tests { #[test] fn $name() { if $triggers { - assert!($binding.is_triggered_by($mode, &$mods, &KEY)); + assert!($binding.is_triggered_by($mode, $mods, &KEY)); } else { - assert!(!$binding.is_triggered_by($mode, &$mods, &KEY)); + assert!(!$binding.is_triggered_by($mode, $mods, &KEY)); } } } diff --git a/src/renderer/mod.rs b/src/renderer/mod.rs index 0d474123..b006f566 100644 --- a/src/renderer/mod.rs +++ b/src/renderer/mod.rs @@ -183,7 +183,7 @@ impl GlyphCache { // Need to load at least one glyph for the face before calling metrics. // The glyph requested here ('m' at the time of writing) has no special // meaning. - rasterizer.get_glyph(&GlyphKey { font_key: regular, c: 'm', size: font.size() })?; + rasterizer.get_glyph(GlyphKey { font_key: regular, c: 'm', size: font.size() })?; let metrics = rasterizer.metrics(regular)?; let mut cache = GlyphCache { @@ -211,7 +211,7 @@ impl GlyphCache { ) { let size = self.font_size; for i in RangeInclusive::new(32u8, 128u8) { - self.get(&GlyphKey { + self.get(GlyphKey { font_key: font, c: i as char, size, @@ -273,14 +273,14 @@ impl GlyphCache { .expect("metrics load since font is loaded at glyph cache creation") } - pub fn get<'a, L>(&'a mut self, glyph_key: &GlyphKey, loader: &mut L) -> &'a Glyph + pub fn get<'a, L>(&'a mut self, glyph_key: GlyphKey, loader: &mut L) -> &'a Glyph where L: LoadGlyph { let glyph_offset = self.glyph_offset; let rasterizer = &mut self.rasterizer; let metrics = &self.metrics; self.cache - .entry(*glyph_key) + .entry(glyph_key) .or_insert_with(|| { let mut rasterized = rasterizer.get_glyph(glyph_key) .unwrap_or_else(|_| Default::default()); @@ -306,7 +306,7 @@ impl GlyphCache { let font = font.to_owned().with_size(size); info!("Font size changed: {:?}", font.size); let (regular, bold, italic) = Self::compute_font_keys(&font, &mut self.rasterizer)?; - self.rasterizer.get_glyph(&GlyphKey { font_key: regular, c: 'm', size: font.size() })?; + self.rasterizer.get_glyph(GlyphKey { font_key: regular, c: 'm', size: font.size() })?; let metrics = self.rasterizer.metrics(regular)?; self.font_size = font.size; @@ -842,7 +842,7 @@ impl<'a> RenderApi<'a> { // Add cell to batch { - let glyph = glyph_cache.get(&glyph_key, self); + let glyph = glyph_cache.get(glyph_key, self); self.add_render_item(&cell, glyph); } @@ -856,7 +856,7 @@ impl<'a> RenderApi<'a> { c: '_' }; - let underscore = glyph_cache.get(&glyph_key, self); + let underscore = glyph_cache.get(glyph_key, self); self.add_render_item(&cell, underscore); } } diff --git a/src/selection.rs b/src/selection.rs index cd905164..ae584025 100644 --- a/src/selection.rs +++ b/src/selection.rs @@ -152,7 +152,7 @@ impl Selection { Selection::Semantic { ref region, ref initial_expansion } => { Selection::span_semantic(grid, region, initial_expansion) }, - Selection::Lines { ref region, ref initial_line } => { + Selection::Lines { ref region, initial_line } => { Selection::span_lines(grid, region, initial_line) } } @@ -192,18 +192,18 @@ impl Selection { }) } - fn span_lines(grid: &G, region: &Region, initial_line: &Line) -> Option + fn span_lines(grid: &G, region: &Region, initial_line: Line) -> Option where G: Dimensions { // First, create start and end points based on initial line and the grid // dimensions. let mut start = Point { col: Column(0), - line: *initial_line + line: initial_line }; let mut end = Point { col: grid.dimensions().col - 1, - line: *initial_line + line: initial_line }; // Now, expand lines based on where cursor started and ended. diff --git a/src/term/mod.rs b/src/term/mod.rs index 27cc9312..d1f48c91 100644 --- a/src/term/mod.rs +++ b/src/term/mod.rs @@ -269,9 +269,9 @@ impl<'a> RenderableCellsIter<'a> { self.mode.contains(mode::TermMode::SHOW_CURSOR) && self.grid.contains(self.cursor) } - fn compute_fg_rgb(&self, fg: &Color, cell: &Cell) -> Rgb { + fn compute_fg_rgb(&self, fg: Color, cell: &Cell) -> Rgb { use self::cell::Flags; - match *fg { + match fg { Color::Spec(rgb) => rgb, Color::Named(ansi) => { match (self.config.draw_bold_text_with_bright_colors(), cell.flags & Flags::DIM_BOLD) { @@ -302,15 +302,15 @@ impl<'a> RenderableCellsIter<'a> { } #[inline] - fn compute_bg_alpha(&self, bg: &Color) -> f32 { - match *bg { + fn compute_bg_alpha(&self, bg: Color) -> f32 { + match bg { Color::Named(NamedColor::Background) => 0.0, _ => 1.0 } } - fn compute_bg_rgb(&self, bg: &Color) -> Rgb { - match *bg { + fn compute_bg_rgb(&self, bg: Color) -> Rgb { + match bg { Color::Spec(rgb) => rgb, Color::Named(ansi) => self.colors[ansi], Color::Indexed(idx) => self.colors[idx], @@ -387,13 +387,13 @@ impl<'a> Iterator for RenderableCellsIter<'a> { fg_rgb = self.colors[NamedColor::Background]; bg_alpha = 1.0 } else { - bg_rgb = self.compute_fg_rgb(&cell.fg, &cell); - fg_rgb = self.compute_bg_rgb(&cell.bg); + bg_rgb = self.compute_fg_rgb(cell.fg, &cell); + fg_rgb = self.compute_bg_rgb(cell.bg); } } else { - fg_rgb = self.compute_fg_rgb(&cell.fg, &cell); - bg_rgb = self.compute_bg_rgb(&cell.bg); - bg_alpha = self.compute_bg_alpha(&cell.bg); + fg_rgb = self.compute_fg_rgb(cell.fg, &cell); + bg_rgb = self.compute_bg_rgb(cell.bg); + bg_alpha = self.compute_bg_alpha(cell.bg); } return Some(RenderableCell { -- cgit From 12f952df42941be8a94a90f9a029e041c9281142 Mon Sep 17 00:00:00 2001 From: Christian Duerr Date: Sun, 1 Jul 2018 16:36:15 +0000 Subject: Update manpage to document all CLI options The introduction of `--class` has added a flag to the CLI without adding it to the manpage. This has been fixed by updating the manpage. This also adds the default values of `--class` and `--title` to the CLI options. --- src/cli.rs | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) (limited to 'src') diff --git a/src/cli.rs b/src/cli.rs index 92b83f6c..0a36179a 100644 --- a/src/cli.rs +++ b/src/cli.rs @@ -15,6 +15,7 @@ extern crate log; use clap::{Arg, App}; use index::{Line, Column}; use config::{Dimensions, Shell}; +use window::{DEFAULT_TITLE, DEFAULT_CLASS}; use std::path::{Path, PathBuf}; use std::borrow::Cow; @@ -80,11 +81,11 @@ impl Options { .long("title") .short("t") .takes_value(true) - .help("Defines the window title")) + .help(&format!("Defines the window title [default: {}]", DEFAULT_TITLE))) .arg(Arg::with_name("class") .long("class") .takes_value(true) - .help("Defines window class on X11")) + .help(&format!("Defines window class on X11 [default: {}]", DEFAULT_CLASS))) .arg(Arg::with_name("q") .short("q") .multiple(true) -- cgit From 985ba306c78857e07f3f267ab954ad069d30a465 Mon Sep 17 00:00:00 2001 From: Matthias Krüger Date: Sun, 1 Jul 2018 22:20:29 +0200 Subject: Remove unnecessary clippy lint annotations We moved to "cargo clippy" in 5ba34d4f9766a55a06ed5e3e44cc384af1b09f65 and removing the clippy lint annotations in `src/lib.rs` does not cause any additional warnings. This also changes `cargo clippy` to use the flags required for checking integration tests. --- src/lib.rs | 3 --- src/util.rs | 1 - 2 files changed, 4 deletions(-) (limited to 'src') diff --git a/src/lib.rs b/src/lib.rs index afbd8595..d6229ee7 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -110,9 +110,6 @@ impl Mul for Rgb { } -#[cfg_attr(feature = "clippy", allow(too_many_arguments))] -#[cfg_attr(feature = "clippy", allow(doc_markdown))] -#[cfg_attr(feature = "clippy", allow(unreadable_literal))] #[allow(unused_mut)] pub mod gl { #![allow(non_upper_case_globals)] diff --git a/src/util.rs b/src/util.rs index 062e7651..6065e01b 100644 --- a/src/util.rs +++ b/src/util.rs @@ -15,7 +15,6 @@ use std::cmp; #[cfg(not(feature = "nightly"))] #[inline(always)] -#[cfg_attr(feature = "clippy", allow(inline_always))] pub unsafe fn unlikely(x: bool) -> bool { x } -- cgit From 7433f45ff9c6efeb48e223e90dd4aa9ee135b5e8 Mon Sep 17 00:00:00 2001 From: Christian Duerr Date: Thu, 5 Jul 2018 23:05:33 +0000 Subject: Replace debug asserts with static_assertions To check that transmutes will work correctly without having to rely on error-prone runtime checking, the `static_assertions` crate has been introduced. This allows comparing the size of types at compile time, preventing potentially silent breakage. This fixes #1417. --- src/input.rs | 2 +- src/lib.rs | 1 + 2 files changed, 2 insertions(+), 1 deletion(-) (limited to 'src') diff --git a/src/input.rs b/src/input.rs index aa00ee3d..701feea1 100644 --- a/src/input.rs +++ b/src/input.rs @@ -137,7 +137,7 @@ impl Binding { /// Optimized to use single check instead of four (one per modifier) #[inline] fn mods_match(&self, mods: ModifiersState) -> bool { - debug_assert!(4 == mem::size_of::()); + assert_eq_size!(ModifiersState, u32); unsafe { mem::transmute_copy::<_, u32>(&self.mods) == mem::transmute_copy::<_, u32>(&mods) } diff --git a/src/lib.rs b/src/lib.rs index d6229ee7..d9006fe0 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -21,6 +21,7 @@ #[macro_use] extern crate clap; #[macro_use] extern crate log; #[macro_use] extern crate serde_derive; +#[macro_use] extern crate static_assertions; #[cfg(any(target_os = "linux", target_os = "freebsd", target_os="dragonfly", target_os="openbsd"))] extern crate x11_dl; -- cgit From 18f6a7814a7aff8fb06d6b9a795e0f8144954d1f Mon Sep 17 00:00:00 2001 From: Patrycja Balik Date: Sun, 15 Jul 2018 15:10:33 +0200 Subject: Add config for unfocused window cursor change --- src/config.rs | 10 ++++++++++ src/term/mod.rs | 2 +- 2 files changed, 11 insertions(+), 1 deletion(-) (limited to 'src') diff --git a/src/config.rs b/src/config.rs index cdf1dc21..95058d38 100644 --- a/src/config.rs +++ b/src/config.rs @@ -390,6 +390,10 @@ pub struct Config { #[serde(default, deserialize_with = "failure_default")] cursor_style: CursorStyle, + /// Use hollow block cursor when unfocused + #[serde(default="true_bool", deserialize_with = "default_true_bool")] + unfocused_hollow_cursor: bool, + /// Live config reload #[serde(default="true_bool", deserialize_with = "default_true_bool")] live_config_reload: bool, @@ -1363,6 +1367,12 @@ impl Config { self.cursor_style } + /// Use hollow block cursor when unfocused + #[inline] + pub fn unfocused_hollow_cursor(&self) -> bool { + self.unfocused_hollow_cursor + } + /// Live config reload #[inline] pub fn live_config_reload(&self) -> bool { diff --git a/src/term/mod.rs b/src/term/mod.rs index d1f48c91..02d846a4 100644 --- a/src/term/mod.rs +++ b/src/term/mod.rs @@ -998,7 +998,7 @@ impl Term { ) -> RenderableCellsIter { let selection = selection.and_then(|s| s.to_span(self)) .map(|span| span.to_range()); - let cursor = if window_focused { + let cursor = if window_focused || !config.unfocused_hollow_cursor() { self.cursor_style.unwrap_or(self.default_cursor_style) } else { CursorStyle::HollowBlock -- cgit From 4ae2bc66f2bd213511997addfed8b589fdc97406 Mon Sep 17 00:00:00 2001 From: Anthony Clays Date: Sun, 15 Jul 2018 18:02:44 +0200 Subject: Add support for cursor shape escape sequence --- src/ansi.rs | 15 +++++++++++++++ 1 file changed, 15 insertions(+) (limited to 'src') diff --git a/src/ansi.rs b/src/ansi.rs index e37e25f1..3fbd580d 100644 --- a/src/ansi.rs +++ b/src/ansi.rs @@ -814,6 +814,21 @@ impl<'a, H, W> vte::Perform for Performer<'a, H, W> unhandled(params); } + // Set cursor style + b"50" => { + if params.len() >= 2 && params[1].len() >= 13 && params[1][0..12] == *b"CursorShape=" { + let style = match params[1][12] as char { + '0' => CursorStyle::Block, + '1' => CursorStyle::Beam, + '2' => CursorStyle::Underline, + _ => return unhandled(params), + }; + self.handler.set_cursor_style(Some(style)); + return; + } + unhandled(params); + } + // Set clipboard b"52" => { if params.len() < 3 { -- cgit From 96b3d737a8ee1805ec548671a6ba8f219b2c2934 Mon Sep 17 00:00:00 2001 From: Christian Duerr Date: Sun, 15 Jul 2018 19:47:07 +0000 Subject: Add bright foreground color option It was requested in jwilm/alacritty#825 that it should be possible to add an optional bright foreground color. This is now added to the primary colors structure and allows the user to set a foreground color for bold normal text. This has no effect unless the draw_bold_text_with_bright_colors option is also enabled. If the color is not specified, the bright foreground color will fall back to the normal foreground color. This fixes #825. --- src/ansi.rs | 3 +++ src/config.rs | 19 +++++++++++++++++++ src/term/color.rs | 7 ++++++- 3 files changed, 28 insertions(+), 1 deletion(-) (limited to 'src') diff --git a/src/ansi.rs b/src/ansi.rs index 3fbd580d..726550a0 100644 --- a/src/ansi.rs +++ b/src/ansi.rs @@ -558,11 +558,14 @@ pub enum NamedColor { DimCyan, /// Dim white DimWhite, + /// The bright foreground color + BrightForeground, } impl NamedColor { pub fn to_bright(self) -> Self { match self { + NamedColor::Foreground => NamedColor::BrightForeground, NamedColor::Black => NamedColor::BrightBlack, NamedColor::Red => NamedColor::BrightRed, NamedColor::Green => NamedColor::BrightGreen, diff --git a/src/config.rs b/src/config.rs index 95058d38..8d63a9c0 100644 --- a/src/config.rs +++ b/src/config.rs @@ -1022,6 +1022,24 @@ pub struct PrimaryColors { pub background: Rgb, #[serde(deserialize_with = "rgb_from_hex")] pub foreground: Rgb, + #[serde(default, deserialize_with = "deserialize_bright_foreground")] + pub bright_foreground: Option, +} + +fn deserialize_bright_foreground<'a, D>(deserializer: D) -> ::std::result::Result, D::Error> + where D: de::Deserializer<'a> +{ + match Option::deserialize(deserializer) { + Ok(Some(color)) => { + let color: serde_yaml::Value = color; + Ok(Some(rgb_from_hex(color).unwrap())) + }, + Ok(None) => Ok(None), + Err(err) => { + eprintln!("problem with config: {}; Using standard foreground color", err); + Ok(None) + }, + } } impl Default for PrimaryColors { @@ -1029,6 +1047,7 @@ impl Default for PrimaryColors { PrimaryColors { background: Rgb { r: 0, g: 0, b: 0 }, foreground: Rgb { r: 0xea, g: 0xea, b: 0xea }, + bright_foreground: None, } } } diff --git a/src/term/color.rs b/src/term/color.rs index d25f2f3d..b84f11bd 100644 --- a/src/term/color.rs +++ b/src/term/color.rs @@ -4,7 +4,7 @@ use std::fmt; use {Rgb, ansi}; use config::Colors; -pub const COUNT: usize = 268; +pub const COUNT: usize = 269; /// List of indexed colors /// @@ -13,6 +13,7 @@ pub const COUNT: usize = 268; /// the configured foreground color, item 257 is the configured background /// color, item 258 is the cursor foreground color, item 259 is the cursor /// background color. Following that are 8 positions for dim colors. +/// Item 268 is the bright foreground color. #[derive(Copy, Clone)] pub struct List([Rgb; COUNT]); @@ -50,6 +51,10 @@ impl List { self[ansi::NamedColor::BrightMagenta] = colors.bright.magenta; self[ansi::NamedColor::BrightCyan] = colors.bright.cyan; self[ansi::NamedColor::BrightWhite] = colors.bright.white; + self[ansi::NamedColor::BrightForeground] = colors + .primary + .bright_foreground + .unwrap_or(colors.primary.foreground); // Foreground and background self[ansi::NamedColor::Foreground] = colors.primary.foreground; -- cgit From 5153c20ace96ea12f0a2714dc33d777c16ac2808 Mon Sep 17 00:00:00 2001 From: Christian Duerr Date: Fri, 20 Jul 2018 18:03:37 +0000 Subject: Switch from deprecated `std::env::home_dir` to `dirs::home_dir` --- src/main.rs | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) (limited to 'src') diff --git a/src/main.rs b/src/main.rs index 652569be..f7a1fa1a 100644 --- a/src/main.rs +++ b/src/main.rs @@ -22,6 +22,8 @@ extern crate alacritty; #[macro_use] extern crate log; +#[cfg(target_os = "macos")] +extern crate dirs; use std::error::Error; use std::sync::Arc; @@ -48,7 +50,7 @@ fn main() { // Switch to home directory #[cfg(target_os = "macos")] - env::set_current_dir(env::home_dir().unwrap()).unwrap(); + env::set_current_dir(dirs::home_dir().unwrap()).unwrap(); // Set locale #[cfg(target_os = "macos")] locale::set_locale_environment(); -- cgit From 48c0a7b067a48a77e0b925dc0e75b04422e04a92 Mon Sep 17 00:00:00 2001 From: Christian Duerr Date: Sat, 21 Jul 2018 17:37:13 +0000 Subject: Allow specifying modifiers for mouse bindings --- src/input.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src') diff --git a/src/input.rs b/src/input.rs index 701feea1..bc33094a 100644 --- a/src/input.rs +++ b/src/input.rs @@ -532,7 +532,7 @@ impl<'a, A: ActionContext + 'a> Processor<'a, A> { return; } - self.process_mouse_bindings(ModifiersState::default(), button); + self.process_mouse_bindings(modifiers, button); } /// Process key input -- cgit From dbcb5885adb1f0b23c29838ef8dd837212322409 Mon Sep 17 00:00:00 2001 From: Josh Leeb-du Toit Date: Sun, 22 Jul 2018 10:38:53 +1000 Subject: Add binding action for hiding the window --- src/config.rs | 3 ++- src/event.rs | 36 ++++++++++++++++++++++++++++++++++++ src/input.rs | 13 ++++++++++++- src/window.rs | 5 +++++ 4 files changed, 55 insertions(+), 2 deletions(-) (limited to 'src') diff --git a/src/config.rs b/src/config.rs index 8d63a9c0..76daee05 100644 --- a/src/config.rs +++ b/src/config.rs @@ -549,7 +549,7 @@ impl<'a> de::Deserialize<'a> for ActionWrapper { type Value = ActionWrapper; fn expecting(&self, f: &mut fmt::Formatter) -> fmt::Result { - f.write_str("Paste, Copy, PasteSelection, IncreaseFontSize, DecreaseFontSize, ResetFontSize, or Quit") + f.write_str("Paste, Copy, PasteSelection, IncreaseFontSize, DecreaseFontSize, ResetFontSize, Hide, or Quit") } fn visit_str(self, value: &str) -> ::std::result::Result @@ -562,6 +562,7 @@ impl<'a> de::Deserialize<'a> for ActionWrapper { "IncreaseFontSize" => Action::IncreaseFontSize, "DecreaseFontSize" => Action::DecreaseFontSize, "ResetFontSize" => Action::ResetFontSize, + "Hide" => Action::Hide, "Quit" => Action::Quit, _ => return Err(E::invalid_value(Unexpected::Str(value), &self)), })) diff --git a/src/event.rs b/src/event.rs index c10f8a72..7e8a955c 100644 --- a/src/event.rs +++ b/src/event.rs @@ -40,6 +40,7 @@ pub struct ActionContext<'a, N: 'a> { pub received_count: &'a mut usize, pub suppress_chars: &'a mut bool, pub last_modifiers: &'a mut ModifiersState, + pub window_changes: &'a mut WindowChanges, } impl<'a, N: Notify + 'a> input::ActionContext for ActionContext<'a, N> { @@ -133,6 +134,33 @@ impl<'a, N: Notify + 'a> input::ActionContext for ActionContext<'a, N> { fn last_modifiers(&mut self) -> &mut ModifiersState { &mut self.last_modifiers } + + #[inline] + fn hide_window(&mut self) { + self.window_changes.hide = true; + } +} + +/// The ActionContext can't really have direct access to the Window +/// with the current design. Event handlers that want to change the +/// window must set these flags instead. The processor will trigger +/// the actual changes. +pub struct WindowChanges { + pub hide: bool, +} + +impl WindowChanges { + fn clear(&mut self) { + self.hide = false; + } +} + +impl Default for WindowChanges { + fn default() -> WindowChanges { + WindowChanges { + hide: false, + } + } } pub enum ClickState { @@ -199,6 +227,7 @@ pub struct Processor { suppress_chars: bool, last_modifiers: ModifiersState, pending_events: Vec, + window_changes: WindowChanges, } /// Notify that the terminal was resized @@ -242,6 +271,7 @@ impl Processor { suppress_chars: false, last_modifiers: Default::default(), pending_events: Vec::with_capacity(4), + window_changes: Default::default(), } } @@ -401,6 +431,7 @@ impl Processor { received_count: &mut self.received_count, suppress_chars: &mut self.suppress_chars, last_modifiers: &mut self.last_modifiers, + window_changes: &mut self.window_changes, }; processor = input::Processor { @@ -448,6 +479,11 @@ impl Processor { } } + if self.window_changes.hide { + window.hide(); + } + + self.window_changes.clear(); self.wait_for_event = !terminal.dirty; terminal diff --git a/src/input.rs b/src/input.rs index bc33094a..52775678 100644 --- a/src/input.rs +++ b/src/input.rs @@ -66,6 +66,7 @@ pub trait ActionContext { fn last_modifiers(&mut self) -> &mut ModifiersState; fn change_font_size(&mut self, delta: f32); fn reset_font_size(&mut self); + fn hide_window(&mut self); } /// Describes a state and action to take in that state @@ -170,6 +171,9 @@ pub enum Action { /// Run given command Command(String, Vec), + /// Hides the Alacritty window + Hide, + /// Quits Alacritty. Quit, } @@ -224,6 +228,9 @@ impl Action { }, } }, + Action::Hide => { + ctx.hide_window(); + }, Action::Quit => { // FIXME should do a more graceful shutdown ::std::process::exit(0); @@ -626,7 +633,7 @@ mod tests { use glutin::{VirtualKeyCode, Event, WindowEvent, ElementState, MouseButton, ModifiersState}; use term::{SizeInfo, Term, TermMode}; - use event::{Mouse, ClickState}; + use event::{Mouse, ClickState, WindowChanges}; use config::{self, Config, ClickHandler}; use index::{Point, Side}; use selection::Selection; @@ -651,6 +658,7 @@ mod tests { pub received_count: usize, pub suppress_chars: bool, pub last_modifiers: ModifiersState, + pub window_changes: &'a mut WindowChanges, } impl <'a>super::ActionContext for ActionContext<'a> { @@ -704,6 +712,8 @@ mod tests { } fn reset_font_size(&mut self) { } + fn hide_window(&mut self) { + } } macro_rules! test_clickstate { @@ -742,6 +752,7 @@ mod tests { received_count: 0, suppress_chars: false, last_modifiers: ModifiersState::default(), + window_changes: &mut WindowChanges::default(), }; let mut processor = Processor { diff --git a/src/window.rs b/src/window.rs index 1903360f..51a42232 100644 --- a/src/window.rs +++ b/src/window.rs @@ -379,6 +379,11 @@ impl Window { pub fn get_window_id(&self) -> Option { None } + + /// Hide the window + pub fn hide(&self) { + self.window.hide(); + } } pub trait OsExtensions { -- cgit From d25134bc6b8b13d5ff550c950c65b6e9c4a7a267 Mon Sep 17 00:00:00 2001 From: Rémi Garde Date: Mon, 23 Jul 2018 18:48:27 +0200 Subject: Add optional dim foreground color Add optional color for the dim foreground (`\e[2m;`) Defaults to 2/3 of the foreground color. (same as other colors). If a bright color is dimmed, it's displayed as the normal color. The exception for this is when the bright foreground is dimmed when no bright foreground color is set. In that case it's treated as a normal foreground color and dimmed to DimForeground. To minimize the surprise for the user, the bright and dim colors have been completely removed from the default configuration file. Some documentation has also been added to make it clear to users what these options can be used for. This fixes #1448. --- src/ansi.rs | 5 +++++ src/config.rs | 7 +++++-- src/term/color.rs | 8 ++++++-- src/term/mod.rs | 13 ++++++++++--- 4 files changed, 26 insertions(+), 7 deletions(-) (limited to 'src') diff --git a/src/ansi.rs b/src/ansi.rs index 726550a0..f1ca759a 100644 --- a/src/ansi.rs +++ b/src/ansi.rs @@ -560,6 +560,8 @@ pub enum NamedColor { DimWhite, /// The bright foreground color BrightForeground, + /// Dim foreground + DimForeground, } impl NamedColor { @@ -574,6 +576,7 @@ impl NamedColor { NamedColor::Magenta => NamedColor::BrightMagenta, NamedColor::Cyan => NamedColor::BrightCyan, NamedColor::White => NamedColor::BrightWhite, + NamedColor::DimForeground => NamedColor::Foreground, NamedColor::DimBlack => NamedColor::Black, NamedColor::DimRed => NamedColor::Red, NamedColor::DimGreen => NamedColor::Green, @@ -596,6 +599,7 @@ impl NamedColor { NamedColor::Magenta => NamedColor::DimMagenta, NamedColor::Cyan => NamedColor::DimCyan, NamedColor::White => NamedColor::DimWhite, + NamedColor::Foreground => NamedColor::DimForeground, NamedColor::BrightBlack => NamedColor::Black, NamedColor::BrightRed => NamedColor::Red, NamedColor::BrightGreen => NamedColor::Green, @@ -604,6 +608,7 @@ impl NamedColor { NamedColor::BrightMagenta => NamedColor::Magenta, NamedColor::BrightCyan => NamedColor::Cyan, NamedColor::BrightWhite => NamedColor::White, + NamedColor::BrightForeground => NamedColor::Foreground, val => val } } diff --git a/src/config.rs b/src/config.rs index 76daee05..b50e3243 100644 --- a/src/config.rs +++ b/src/config.rs @@ -1023,11 +1023,13 @@ pub struct PrimaryColors { pub background: Rgb, #[serde(deserialize_with = "rgb_from_hex")] pub foreground: Rgb, - #[serde(default, deserialize_with = "deserialize_bright_foreground")] + #[serde(default, deserialize_with = "deserialize_optional_color")] pub bright_foreground: Option, + #[serde(default, deserialize_with = "deserialize_optional_color")] + pub dim_foreground: Option, } -fn deserialize_bright_foreground<'a, D>(deserializer: D) -> ::std::result::Result, D::Error> +fn deserialize_optional_color<'a, D>(deserializer: D) -> ::std::result::Result, D::Error> where D: de::Deserializer<'a> { match Option::deserialize(deserializer) { @@ -1049,6 +1051,7 @@ impl Default for PrimaryColors { background: Rgb { r: 0, g: 0, b: 0 }, foreground: Rgb { r: 0xea, g: 0xea, b: 0xea }, bright_foreground: None, + dim_foreground: None, } } } diff --git a/src/term/color.rs b/src/term/color.rs index b84f11bd..6acd092a 100644 --- a/src/term/color.rs +++ b/src/term/color.rs @@ -4,7 +4,7 @@ use std::fmt; use {Rgb, ansi}; use config::Colors; -pub const COUNT: usize = 269; +pub const COUNT: usize = 270; /// List of indexed colors /// @@ -13,7 +13,7 @@ pub const COUNT: usize = 269; /// the configured foreground color, item 257 is the configured background /// color, item 258 is the cursor foreground color, item 259 is the cursor /// background color. Following that are 8 positions for dim colors. -/// Item 268 is the bright foreground color. +/// Item 268 is the bright foreground color, 269 the dim foreground. #[derive(Copy, Clone)] pub struct List([Rgb; COUNT]); @@ -65,6 +65,10 @@ impl List { self[ansi::NamedColor::Cursor] = colors.cursor.cursor; // Dims + self[ansi::NamedColor::DimForeground] = colors + .primary + .dim_foreground + .unwrap_or(colors.primary.foreground * 0.66); match colors.dim { Some(ref dim) => { trace!("Using config-provided dim colors"); diff --git a/src/term/mod.rs b/src/term/mod.rs index 02d846a4..fd22fe54 100644 --- a/src/term/mod.rs +++ b/src/term/mod.rs @@ -275,11 +275,18 @@ impl<'a> RenderableCellsIter<'a> { Color::Spec(rgb) => rgb, Color::Named(ansi) => { match (self.config.draw_bold_text_with_bright_colors(), cell.flags & Flags::DIM_BOLD) { + // If no bright foreground is set, treat it like the BOLD flag doesn't exist + (_, self::cell::Flags::DIM_BOLD) + if ansi == NamedColor::Foreground + && self.config.colors().primary.bright_foreground.is_none() => + { + self.colors[NamedColor::DimForeground] + } // Draw bold text in bright colors *and* contains bold flag. - (true, self::cell::Flags::DIM_BOLD) | - (true, self::cell::Flags::BOLD) => self.colors[ansi.to_bright()], + (true, self::cell::Flags::BOLD) => self.colors[ansi.to_bright()], // Cell is marked as dim and not bold - (_, self::cell::Flags::DIM) => self.colors[ansi.to_dim()], + (_, self::cell::Flags::DIM) | + (false, self::cell::Flags::DIM_BOLD) => self.colors[ansi.to_dim()], // None of the above, keep original color. _ => self.colors[ansi] } -- cgit From ddb9a558170ad16f19135b2f6a5a7a7e8ac61c3c Mon Sep 17 00:00:00 2001 From: Matthias Krüger Date: Wed, 25 Jul 2018 21:46:45 +0200 Subject: Fix clippy lints and run font tests on travis This fixes some existing clippy issues and runs the `font` tests through travis. Testing of copypasta crate was omitted due to problens when running on headless travis-ci environment (x11 clipboard would fail). --- src/main.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src') diff --git a/src/main.rs b/src/main.rs index f7a1fa1a..fc6b0821 100644 --- a/src/main.rs +++ b/src/main.rs @@ -180,7 +180,7 @@ fn run(mut config: Config, options: &cli::Options) -> Result<(), Box> { .as_ref() .and_then(|monitor| monitor.pending_config()) { - config = new_config.update_dynamic_title(&options); + config = new_config.update_dynamic_title(options); display.update_config(&config); processor.update_config(&config); terminal.update_config(&config); -- cgit From 57a455e5f209dd965fd6b495d7f2b033fd5288c0 Mon Sep 17 00:00:00 2001 From: Christian Duerr Date: Wed, 25 Jul 2018 21:05:49 +0000 Subject: Ignore errors when logger can't write to output The (e)print macro will panic when there is no output available to write to, however in our scenario where we only log user errors to stderr, the better choice would be to ignore when writing to stdout or stderr is not possible. This changes the (e)print macro to make use of `write` and ignore any potential errors. Since (e)println rely on (e)print, this also solves potential failuers when calling (e)println. With this change implemented, all of logging, (e)println and (e)print should never fail even if the stdout/stderr is not available. --- src/logging.rs | 2 +- src/macros.rs | 16 ++++++++++++++++ 2 files changed, 17 insertions(+), 1 deletion(-) (limited to 'src') diff --git a/src/logging.rs b/src/logging.rs index a691778a..10929980 100644 --- a/src/logging.rs +++ b/src/logging.rs @@ -47,7 +47,7 @@ impl log::Log for Logger { fn log(&self, record: &log::Record) { if self.enabled(record.metadata()) && record.target().starts_with("alacritty") { if let Ok(ref mut writer) = self.output.lock() { - writer.write_all(format!("{}\n", record.args()).as_ref()).expect("Error while logging!"); + let _ = writer.write_all(format!("{}\n", record.args()).as_ref()); } } } diff --git a/src/macros.rs b/src/macros.rs index 35e69f2d..464110e6 100644 --- a/src/macros.rs +++ b/src/macros.rs @@ -29,3 +29,19 @@ macro_rules! maybe { } } } + +#[macro_export] +macro_rules! print { + ($($arg:tt)*) => {{ + use std::io::Write; + let _ = write!(::std::io::stdout(), $($arg)*); + }}; +} + +#[macro_export] +macro_rules! eprint { + ($($arg:tt)*) => {{ + use std::io::Write; + let _ = write!(::std::io::stderr(), $($arg)*); + }}; +} -- cgit