1
0
Fork 0
mirror of https://github.com/alacritty/alacritty.git synced 2024-11-18 13:55:23 -05:00

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
This commit is contained in:
Anders Rasmussen 2017-02-05 21:01:26 +11:00 committed by Joe Wilm
parent 9d44526bf9
commit edc2c7f5b9
6 changed files with 78 additions and 18 deletions

View file

@ -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)

View file

@ -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)

View file

@ -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)

View file

@ -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> {

View file

@ -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

View file

@ -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);