diff options
author | Anders Rasmussen <divinegod@gmail.com> | 2017-02-05 21:01:26 +1100 |
---|---|---|
committer | Joe Wilm <jwilm@users.noreply.github.com> | 2017-02-06 20:45:17 -0800 |
commit | edc2c7f5b9784310f150724a786ae3bc3be74490 (patch) | |
tree | 42b6c6dfdf5f4d202f8ec02b309637586ab9e2a8 | |
parent | 9d44526bf9ac8f20b090cc8a9279e527ec07d189 (diff) |
Configurable window dimensions
Adds a configuration option `dimensions` which will set initial
window size by columns and lines. Changes to the config file will
require restart.
resolves #370
-rw-r--r-- | README.md | 6 | ||||
-rw-r--r-- | alacritty.yml | 5 | ||||
-rw-r--r-- | alacritty_macos.yml | 5 | ||||
-rw-r--r-- | src/cli.rs | 23 | ||||
-rw-r--r-- | src/config.rs | 51 | ||||
-rw-r--r-- | src/display.rs | 6 |
6 files changed, 78 insertions, 18 deletions
@@ -171,9 +171,9 @@ is created once alacritty is first run. On most systems this often defaults to `$HOME/.config/alacritty/alacritty.yml`. Many configuration options will take effect immediately upon saving changes to -the config file. The only exception is the `font` and `dpi` section which -requires Alacritty to be restarted. For further explanation of the config file, -please consult the comments in the default config file. +the config file. The only exception is the `font`, `dimensions` and `dpi` sections +which requires Alacritty to be restarted. For further explanation of the config +file, please consult the comments in the default config file. ## Issues (known, unknown, feature requests, etc) diff --git a/alacritty.yml b/alacritty.yml index 83b120f2..3ffd59a4 100644 --- a/alacritty.yml +++ b/alacritty.yml @@ -1,4 +1,9 @@ # Configuration for Alacritty, the GPU enhanced terminal emulator +# Window dimensions in character columns and lines +# (changes require restart) +dimensions: + columns: 80 + lines: 40 # The FreeType rasterizer needs to know the device DPI for best results # (changes require restart) diff --git a/alacritty_macos.yml b/alacritty_macos.yml index a3d8df86..d6b89f77 100644 --- a/alacritty_macos.yml +++ b/alacritty_macos.yml @@ -1,4 +1,9 @@ # Configuration for Alacritty, the GPU enhanced terminal emulator +# Window dimensions in character columns and lines +# (changes require restart) +dimensions: + columns: 80 + lines: 40 # The FreeType rasterizer needs to know the device DPI for best results # (changes require restart) @@ -14,7 +14,7 @@ extern crate log; use clap::{Arg, App}; use index::{Line, Column}; -use config::Shell; +use config::{Dimensions, Shell}; const DEFAULT_TITLE: &'static str = "Alacritty"; @@ -22,8 +22,7 @@ const DEFAULT_TITLE: &'static str = "Alacritty"; pub struct Options { pub print_events: bool, pub ref_test: bool, - pub columns: Column, - pub lines: Line, + pub dimensions: Option<Dimensions>, pub title: String, pub log_level: log::LogLevelFilter, pub shell: Option<Shell<'static>>, @@ -34,8 +33,7 @@ impl Default for Options { Options { print_events: false, ref_test: false, - columns: Column(80), - lines: Line(24), + dimensions: None, title: DEFAULT_TITLE.to_owned(), log_level: log::LogLevelFilter::Warn, shell: None, @@ -95,8 +93,11 @@ impl Options { } if let Some(mut dimensions) = matches.values_of("dimensions") { - dimensions.next().map(|w| w.parse().map(|w| options.columns = Column(w))); - dimensions.next().map(|h| h.parse().map(|h| options.lines = Line(h))); + let width = dimensions.next().map(|w| w.parse().map(|w| Column(w))); + let height = dimensions.next().map(|h| h.parse().map(|h| Line(h))); + if let (Some(Ok(width)), Some(Ok(height))) = (width, height) { + options.dimensions = Some(Dimensions::new(width, height)); + } } if let Some(title) = matches.value_of("title") { @@ -128,12 +129,8 @@ impl Options { options } - pub fn lines_u32(&self) -> u32 { - self.lines.0 as u32 - } - - pub fn columns_u32(&self) -> u32 { - self.columns.0 as u32 + pub fn dimensions(&self) -> Option<Dimensions> { + self.dimensions } pub fn shell(&self) -> Option<&Shell> { diff --git a/src/config.rs b/src/config.rs index d08b801b..362fe645 100644 --- a/src/config.rs +++ b/src/config.rs @@ -23,6 +23,7 @@ use serde::de::{Visitor, MapVisitor, Unexpected}; use notify::{Watcher as WatcherApi, RecommendedWatcher as FileWatcher, op}; use input::{Action, Binding, MouseBinding, KeyBinding}; +use index::{Line, Column}; use ansi; @@ -212,6 +213,10 @@ impl<'a> Shell<'a> { /// Top-level config type #[derive(Debug, Deserialize)] pub struct Config { + /// Initial dimensions + #[serde(default)] + dimensions: Dimensions, + /// Pixels per inch #[serde(default)] dpi: Dpi, @@ -273,6 +278,7 @@ impl Default for Config { fn default() -> Config { Config { draw_bold_text_with_bright_colors: true, + dimensions: Default::default(), dpi: Default::default(), font: Default::default(), render_timer: Default::default(), @@ -969,6 +975,12 @@ impl Config { &self.font } + /// Get window dimensions + #[inline] + pub fn dimensions(&self) -> Dimensions { + self.dimensions + } + /// Get dpi config #[inline] pub fn dpi(&self) -> &Dpi { @@ -1020,6 +1032,45 @@ impl Config { } } +/// Window Dimensions +/// +/// Newtype to avoid passing values incorrectly +#[derive(Debug, Copy, Clone, Deserialize)] +pub struct Dimensions { + /// Window width in character columns + columns: Column, + + /// Window Height in character lines + lines: Line, +} + +impl Default for Dimensions { + fn default() -> Dimensions { + Dimensions::new(Column(80), Line(24)) + } +} + +impl Dimensions { + pub fn new(columns: Column, lines: Line) -> Self { + Dimensions { + columns: columns, + lines: lines + } + } + + /// Get lines + #[inline] + pub fn lines_u32(&self) -> u32 { + self.lines.0 as u32 + } + + /// Get columns + #[inline] + pub fn columns_u32(&self) -> u32 { + self.columns.0 as u32 + } +} + /// Pixels per inch /// /// This is only used on `FreeType` systems diff --git a/src/display.rs b/src/display.rs index b1ab3ed9..0b242b33 100644 --- a/src/display.rs +++ b/src/display.rs @@ -177,8 +177,10 @@ impl Display { let cell_height = (metrics.line_height + font.offset().y() as f64) as u32; // Resize window to specified dimensions - let width = cell_width * options.columns_u32() + 4; - let height = cell_height * options.lines_u32() + 4; + let dimensions = options.dimensions() + .unwrap_or_else(|| config.dimensions()); + let width = cell_width * dimensions.columns_u32() + 4; + let height = cell_height * dimensions.lines_u32() + 4; let size = Size { width: Pixels(width), height: Pixels(height) }; info!("set_inner_size: {}", size); |