From 06812ccea1322511208253864bf2ff435209da28 Mon Sep 17 00:00:00 2001 From: Joe Wilm Date: Fri, 22 Dec 2017 12:47:14 -0800 Subject: [PATCH] Deprecate config top-level dimensions and padding --- src/config.rs | 30 +++++++++++++++++++++++++++--- 1 file changed, 27 insertions(+), 3 deletions(-) diff --git a/src/config.rs b/src/config.rs index 96d3ee49..3bbbedcd 100644 --- a/src/config.rs +++ b/src/config.rs @@ -211,7 +211,6 @@ impl Default for Alpha { #[derive(Debug, Copy, Clone, Deserialize)] pub struct WindowConfig { - /// Initial dimensions #[serde(default)] dimensions: Dimensions, @@ -244,6 +243,14 @@ impl Default for WindowConfig { /// Top-level config type #[derive(Debug, Deserialize)] pub struct Config { + /// Initial dimensions + #[serde(default)] + dimensions: Option, + + /// Pixel padding + #[serde(default)] + padding: Option, + /// TERM env variable #[serde(default)] env: HashMap, @@ -347,6 +354,8 @@ impl Default for Config { fn default() -> Config { Config { draw_bold_text_with_bright_colors: true, + dimensions: None, + padding: None, font: Default::default(), render_timer: Default::default(), custom_cursor_colors: false, @@ -1149,7 +1158,8 @@ impl Config { } pub fn padding(&self) -> &Delta { - &self.window.padding + self.padding.as_ref() + .unwrap_or(&self.window.padding) } #[inline] @@ -1166,7 +1176,7 @@ impl Config { /// Get window dimensions #[inline] pub fn dimensions(&self) -> Dimensions { - self.window.dimensions + self.dimensions.unwrap_or(self.window.dimensions) } /// Get window config @@ -1235,6 +1245,7 @@ impl Config { let raw = Config::read_file(path.as_path())?; let mut config: Config = serde_yaml::from_str(&raw)?; config.config_path = Some(path); + config.print_deprecation_warnings(); Ok(config) } @@ -1249,6 +1260,19 @@ impl Config { Ok(contents) } + + fn print_deprecation_warnings(&self) { + use ::util::fmt; + if self.dimensions.is_some() { + eprintln!("{}", fmt::Yellow("Config `dimensions` is deprecated. \ + Please use `window.dimensions` instead.")); + } + + if self.padding.is_some() { + eprintln!("{}", fmt::Yellow("Config `padding` is deprecated. \ + Please use `window.padding` instead.")); + } + } } /// Window Dimensions