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 /src/config.rs | |
parent | 9d44526bf9ac8f20b090cc8a9279e527ec07d189 (diff) | |
download | alacritty-edc2c7f5b9784310f150724a786ae3bc3be74490.tar.gz alacritty-edc2c7f5b9784310f150724a786ae3bc3be74490.zip |
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
Diffstat (limited to 'src/config.rs')
-rw-r--r-- | src/config.rs | 51 |
1 files changed, 51 insertions, 0 deletions
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 |