diff --git a/CHANGELOG.md b/CHANGELOG.md index b472f60..b48a10b 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -9,6 +9,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ### Packaging - Minimum Rust version has been bumped to 1.36.0 +- Config is not generated anymore, please consider distributing the alacritty.yml as documentation ### Added @@ -70,6 +71,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ### Removed - Bindings for Super/Command + F1-F12 +- Automatic config generation ## 0.3.3 diff --git a/README.md b/README.md index cfb506b..12e8524 100644 --- a/README.md +++ b/README.md @@ -152,25 +152,16 @@ properly. ## Configuration -Although it's possible the default configuration would work on your system, -you'll probably end up wanting to customize it anyhow. There is a default -`alacritty.yml` at the Git repository root. Alacritty looks for the -configuration file at the following paths: +You can find the default configuration file with documentation for all available +fields on the [GitHub releases page](https://github.com/jwilm/alacritty/releases) for each release. + +Alacritty looks for the configuration file at the following paths: 1. `$XDG_CONFIG_HOME/alacritty/alacritty.yml` 2. `$XDG_CONFIG_HOME/alacritty.yml` 3. `$HOME/.config/alacritty/alacritty.yml` 4. `$HOME/.alacritty.yml` -If none of these paths are found then -`$XDG_CONFIG_HOME/alacritty/alacritty.yml` 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. For more information about the config file structure, refer to -the default config file. - ### Windows On Windows the config file is located at: diff --git a/alacritty.yml b/alacritty.yml index 8729a33..1b709d6 100644 --- a/alacritty.yml +++ b/alacritty.yml @@ -12,14 +12,14 @@ # available, otherwise `xterm-256color` is used. #TERM: xterm-256color -window: +#window: # Window dimensions (changes require restart) # # Specified in number of columns/lines, not pixels. # If both are `0`, this setting is ignored. - dimensions: - columns: 0 - lines: 0 + #dimensions: + # columns: 0 + # lines: 0 # Window position (changes require restart) # @@ -33,12 +33,12 @@ window: # # Blank space added around the window in pixels. This padding is scaled # by DPI and the specified value is always added at both opposing sides. - padding: - x: 0 - y: 0 + #padding: + # x: 0 + # y: 0 # Spread additional padding evenly around the terminal content. - dynamic_padding: false + #dynamic_padding: false # Window decorations # @@ -49,7 +49,7 @@ window: # Values for `decorations` (macOS only): # - transparent: Title bar, transparent background and title bar buttons # - buttonless: Title bar, transparent background, but no title bar buttons - decorations: full + #decorations: full # Startup Mode (changes require restart) # @@ -60,32 +60,32 @@ window: # # Values for `startup_mode` (macOS only): # - SimpleFullscreen - startup_mode: Windowed + #startup_mode: Windowed # Window title #title: Alacritty # Window class (Linux only): - class: + #class: # Application instance name - instance: Alacritty + #instance: Alacritty # General application class - general: Alacritty + #general: Alacritty # GTK theme variant (Linux only) # # Override the variant of the GTK theme. Commonly supported values are `dark` and `light`. # Set this to `None` to use the default theme variant. - gtk_theme_variant: None + #gtk_theme_variant: None -scrolling: +#scrolling: # Maximum number of lines in the scrollback buffer. # Specifying '0' will disable scrolling. - history: 10000 + #history: 10000 # Number of lines the viewport will move for every line scrolled when # scrollback is enabled (history > 0). - multiplier: 3 + #multiplier: 3 # Faux Scrolling # @@ -94,10 +94,10 @@ scrolling: # to allow mouse scrolling for applications like `man`. # # Specifying `0` will disable faux scrolling. - faux_multiplier: 3 + #faux_multiplier: 3 # Scroll to the bottom when new text is written to the terminal. - auto_scroll: false + #auto_scroll: false # Spaces per Tab (changes require restart) # @@ -106,10 +106,10 @@ scrolling: # Some applications, like Emacs, rely on knowing about the width of a tab. # To prevent unexpected behavior in these applications, it's also required to # change the `it` value in terminfo when altering this setting. -tabspaces: 8 +#tabspaces: 8 # Font configuration (changes require restart) -font: +#font: # Normal (roman) font face #normal: # Font family @@ -157,20 +157,20 @@ font: #style: Bold Italic # Point size - size: 11.0 + #size: 11.0 # Offset is the extra space around each character. `offset.y` can be thought of # as modifying the line spacing, and `offset.x` as modifying the letter spacing. - offset: - x: 0 - y: 0 + #offset: + # x: 0 + # y: 0 # Glyph offset determines the locations of the glyphs within their cells with # the default being at the bottom. Increasing `x` moves the glyph to the right, # increasing `y` moves the glyph upwards. - glyph_offset: - x: 0 - y: 0 + #glyph_offset: + # x: 0 + # y: 0 # Thin stroke font rendering (macOS only) # @@ -186,17 +186,17 @@ font: # # This is a global setting and will require a log out or restart to take # effect. - use_thin_strokes: true + #use_thin_strokes: true # If `true`, bold text is drawn using the bright color variants. -draw_bold_text_with_bright_colors: true +#draw_bold_text_with_bright_colors: true # Colors (Tomorrow Night Bright) -colors: +#colors: # Default colors - primary: - background: '0x000000' - foreground: '0xeaeaea' + #primary: + # background: '0x000000' + # foreground: '0xeaeaea' # Bright and dim foreground colors # @@ -224,26 +224,26 @@ colors: # background: '0x404040' # Normal colors - normal: - black: '0x000000' - red: '0xd54e53' - green: '0xb9ca4a' - yellow: '0xe6c547' - blue: '0x7aa6da' - magenta: '0xc397d8' - cyan: '0x70c0ba' - white: '0xeaeaea' + #normal: + # black: '0x000000' + # red: '0xd54e53' + # green: '0xb9ca4a' + # yellow: '0xe6c547' + # blue: '0x7aa6da' + # magenta: '0xc397d8' + # cyan: '0x70c0ba' + # white: '0xeaeaea' # Bright colors - bright: - black: '0x666666' - red: '0xff3334' - green: '0x9ec400' - yellow: '0xe7c547' - blue: '0x7aa6da' - magenta: '0xb77ee0' - cyan: '0x54ced6' - white: '0xffffff' + #bright: + # black: '0x666666' + # red: '0xff3334' + # green: '0x9ec400' + # yellow: '0xe7c547' + # blue: '0x7aa6da' + # magenta: '0xb77ee0' + # cyan: '0x54ced6' + # white: '0xffffff' # Dim colors # @@ -267,7 +267,7 @@ colors: # Example: # `- { index: 16, color: '0xff00ff' }` # - indexed_colors: [] + #indexed_colors: [] # Visual Bell # @@ -290,41 +290,41 @@ colors: # - Linear # # Specifying a `duration` of `0` will disable the visual bell. -visual_bell: - animation: EaseOutExpo - duration: 0 - color: '0xffffff' +#visual_bell: +# animation: EaseOutExpo +# duration: 0 +# color: '0xffffff' # Background opacity # # Window opacity as a floating point number from `0.0` to `1.0`. # The value `0.0` is completely transparent and `1.0` is opaque. -background_opacity: 1.0 +#background_opacity: 1.0 -selection: - semantic_escape_chars: ",│`|:\"' ()[]{}<>\t" +#selection: + #semantic_escape_chars: ",│`|:\"' ()[]{}<>\t" # When set to `true`, selected text will be copied to the primary clipboard. - save_to_clipboard: false + #save_to_clipboard: false # Allow terminal applications to change Alacritty's window title. -dynamic_title: true +#dynamic_title: true -cursor: +#cursor: # Cursor style # # Values for `style`: # - ▇ Block # - _ Underline # - | Beam - style: Block + #style: Block # If this is `true`, the cursor will be rendered as a hollow box when the # window is not focused. - unfocused_hollow: true + #unfocused_hollow: true # Live config reload (changes require restart) -live_config_reload: true +#live_config_reload: true # Shell # @@ -344,7 +344,7 @@ live_config_reload: true # # Directory the shell is started in. If this is unset, or `None`, the working # directory of the parent process will be used. -working_directory: None +#working_directory: None # Windows 10 ConPTY backend (Windows only) # @@ -355,17 +355,17 @@ working_directory: None # # Alacritty will fall back to the WinPTY automatically if the ConPTY # backend cannot be initialized. -enable_experimental_conpty_backend: false +#enable_experimental_conpty_backend: false # Send ESC (\x1b) before characters when alt is pressed. -alt_send_esc: true +#alt_send_esc: true -debug: +#debug: # Display the time it takes to redraw each frame. - render_timer: false + #render_timer: false # Keep the log file after quitting Alacritty. - persistent_logging: false + #persistent_logging: false # Log level # @@ -376,27 +376,27 @@ debug: # - Info # - Debug # - Trace - log_level: Warn + #log_level: Warn # Print all received window events. - print_events: false + #print_events: false # Record all characters and escape sequences as test data. - ref_test: false + #ref_test: false -mouse: +#mouse: # Click settings # # The `double_click` and `triple_click` settings control the time # alacritty should wait for accepting multiple clicks as one double # or triple click. - double_click: { threshold: 300 } - triple_click: { threshold: 300 } + #double_click: { threshold: 300 } + #triple_click: { threshold: 300 } # If this is `true`, the cursor is temporarily hidden when typing. - hide_when_typing: false + #hide_when_typing: false - url: + #url: # URL launcher # # This program is executed when clicking on a text which is recognized as a URL. @@ -416,7 +416,7 @@ mouse: # # These are the modifiers that need to be held down for opening URLs when clicking # on them. The available modifiers are documented in the key binding section. - modifiers: None + #modifiers: None # Mouse bindings # @@ -437,8 +437,8 @@ mouse: # And optionally: # # - `mods` (see key bindings) -mouse_bindings: - - { mouse: Middle, action: PasteSelection } +#mouse_bindings: +# - { mouse: Middle, action: PasteSelection } # Key bindings # @@ -539,7 +539,7 @@ mouse_bindings: # binding with the same triggers is defined. To unset a default binding, it can # be mapped to the `ReceiveChar` action. Alternatively, you can use `None` for # a no-op if you do not wish to receive input characters for that binding. -key_bindings: +#key_bindings: # (Windows/Linux only) #- { key: V, mods: Control|Shift, action: Paste } #- { key: C, mods: Control|Shift, action: Copy } @@ -565,11 +565,11 @@ key_bindings: #- { key: W, mods: Command, action: Quit } #- { key: F, mods: Command|Control, action: ToggleFullscreen } - - { key: Paste, action: Paste } - - { key: Copy, action: Copy } - - { key: L, mods: Control, action: ClearLogNotice } - - { key: L, mods: Control, chars: "\x0c" } - - { key: PageUp, mods: Shift, action: ScrollPageUp, mode: ~Alt } - - { key: PageDown, mods: Shift, action: ScrollPageDown, mode: ~Alt } - - { key: Home, mods: Shift, action: ScrollToTop, mode: ~Alt } - - { key: End, mods: Shift, action: ScrollToBottom, mode: ~Alt } + #- { key: Paste, action: Paste } + #- { key: Copy, action: Copy } + #- { key: L, mods: Control, action: ClearLogNotice } + #- { key: L, mods: Control, chars: "\x0c" } + #- { key: PageUp, mods: Shift, action: ScrollPageUp, mode: ~Alt } + #- { key: PageDown, mods: Shift, action: ScrollPageDown, mode: ~Alt } + #- { key: Home, mods: Shift, action: ScrollToTop, mode: ~Alt } + #- { key: End, mods: Shift, action: ScrollToBottom, mode: ~Alt } diff --git a/alacritty/src/cli.rs b/alacritty/src/cli.rs index d5eb12d..aabcdee 100644 --- a/alacritty/src/cli.rs +++ b/alacritty/src/cli.rs @@ -12,9 +12,8 @@ // See the License for the specific language governing permissions and // limitations under the License. -use std::borrow::Cow; use std::cmp::max; -use std::path::{Path, PathBuf}; +use std::path::PathBuf; use clap::{crate_authors, crate_description, crate_name, crate_version, App, Arg}; use log::{self, LevelFilter}; @@ -242,8 +241,8 @@ impl Options { options } - pub fn config_path(&self) -> Option> { - self.config.as_ref().map(|p| Cow::Borrowed(p.as_path())) + pub fn config_path(&self) -> Option { + self.config.clone() } pub fn into_config(self, mut config: Config) -> Config { @@ -284,15 +283,12 @@ impl Options { #[cfg(test)] mod test { - use alacritty_terminal::config::DEFAULT_ALACRITTY_CONFIG; - use crate::cli::Options; use crate::config::Config; #[test] fn dynamic_title_ignoring_options_by_default() { - let config: Config = - ::serde_yaml::from_str(DEFAULT_ALACRITTY_CONFIG).expect("deserialize config"); + let config = Config::default(); let old_dynamic_title = config.dynamic_title(); let config = Options::default().into_config(config); @@ -302,8 +298,7 @@ mod test { #[test] fn dynamic_title_overridden_by_options() { - let config: Config = - ::serde_yaml::from_str(DEFAULT_ALACRITTY_CONFIG).expect("deserialize config"); + let config = Config::default(); let mut options = Options::default(); options.title = Some("foo".to_owned()); @@ -314,8 +309,7 @@ mod test { #[test] fn dynamic_title_overridden_by_config() { - let mut config: Config = - ::serde_yaml::from_str(DEFAULT_ALACRITTY_CONFIG).expect("deserialize config"); + let mut config = Config::default(); config.window.title = Some("foo".to_owned()); let config = Options::default().into_config(config); diff --git a/alacritty/src/config/mod.rs b/alacritty/src/config/mod.rs index fe0ee7a..8b881fc 100644 --- a/alacritty/src/config/mod.rs +++ b/alacritty/src/config/mod.rs @@ -1,8 +1,6 @@ -use std::borrow::Cow; use std::env; -use std::fs::File; -use std::io::{self, Read, Write}; -use std::path::{Path, PathBuf}; +use std::io; +use std::path::PathBuf; #[cfg(windows)] use dirs; @@ -11,15 +9,11 @@ use serde_yaml; #[cfg(not(windows))] use xdg; -use alacritty_terminal::config::{ - Config as TermConfig, DEFAULT_ALACRITTY_CONFIG, LOG_TARGET_CONFIG, -}; +use alacritty_terminal::config::{Config as TermConfig, LOG_TARGET_CONFIG}; mod bindings; pub mod monitor; mod mouse; -#[cfg(test)] -mod test; mod ui_config; pub use crate::config::bindings::{Action, Binding, Key, RelaxedEq}; @@ -48,7 +42,7 @@ pub enum Error { Yaml(serde_yaml::Error), } -impl ::std::error::Error for Error { +impl std::error::Error for Error { fn cause(&self) -> Option<&dyn (::std::error::Error)> { match *self { Error::NotFound => None, @@ -68,7 +62,7 @@ impl ::std::error::Error for Error { } } -impl ::std::fmt::Display for Error { +impl std::fmt::Display for Error { fn fmt(&self, f: &mut ::std::fmt::Formatter<'_>) -> ::std::fmt::Result { match *self { Error::NotFound => write!(f, "{}", ::std::error::Error::description(self)), @@ -111,7 +105,7 @@ impl From for Error { /// 3. $HOME/.config/alacritty/alacritty.yml /// 4. $HOME/.alacritty.yml #[cfg(not(windows))] -pub fn installed_config<'a>() -> Option> { +pub fn installed_config() -> Option { // Try using XDG location by default xdg::BaseDirectories::with_prefix("alacritty") .ok() @@ -136,41 +130,11 @@ pub fn installed_config<'a>() -> Option> { } None }) - .map(Into::into) } #[cfg(windows)] -pub fn installed_config<'a>() -> Option> { - dirs::config_dir() - .map(|path| path.join("alacritty\\alacritty.yml")) - .filter(|new| new.exists()) - .map(Cow::from) -} - -#[cfg(not(windows))] -pub fn write_defaults() -> io::Result> { - let path = xdg::BaseDirectories::with_prefix("alacritty") - .map_err(|err| io::Error::new(io::ErrorKind::NotFound, err.to_string().as_str())) - .and_then(|p| p.place_config_file("alacritty.yml"))?; - - File::create(&path)?.write_all(DEFAULT_ALACRITTY_CONFIG.as_bytes())?; - - Ok(path.into()) -} - -#[cfg(windows)] -pub fn write_defaults() -> io::Result> { - let mut path = dirs::config_dir().ok_or_else(|| { - io::Error::new(io::ErrorKind::NotFound, "Couldn't find profile directory") - })?; - - path = path.join("alacritty/alacritty.yml"); - - std::fs::create_dir_all(path.parent().unwrap())?; - - File::create(&path)?.write_all(DEFAULT_ALACRITTY_CONFIG.as_bytes())?; - - Ok(path.into()) +pub fn installed_config() -> Option { + dirs::config_dir().map(|path| path.join("alacritty\\alacritty.yml")).filter(|new| new.exists()) } pub fn load_from(path: PathBuf) -> Config { @@ -190,24 +154,31 @@ pub fn reload_from(path: &PathBuf) -> Result { } fn read_config(path: &PathBuf) -> Result { - let mut contents = String::new(); - File::open(path)?.read_to_string(&mut contents)?; + let mut contents = std::fs::read_to_string(path)?; // Remove UTF-8 BOM if contents.chars().nth(0) == Some('\u{FEFF}') { contents = contents.split_off(3); } - // Prevent parsing error with empty string - if contents.is_empty() { - return Ok(Config::default()); + parse_config(&contents) +} + +fn parse_config(contents: &str) -> Result { + match serde_yaml::from_str(&contents) { + Err(error) => { + // Prevent parsing error with an empty string and commented out file. + if std::error::Error::description(&error) == "EOF while parsing a value" { + Ok(Config::default()) + } else { + Err(Error::Yaml(error)) + } + }, + Ok(config) => { + print_deprecation_warnings(&config); + Ok(config) + }, } - - let config = serde_yaml::from_str(&contents)?; - - print_deprecation_warnings(&config); - - Ok(config) } fn print_deprecation_warnings(config: &Config) { @@ -232,3 +203,16 @@ fn print_deprecation_warnings(config: &Config) { ); } } + +#[cfg(test)] +mod test { + static DEFAULT_ALACRITTY_CONFIG: &str = + include_str!(concat!(env!("CARGO_MANIFEST_DIR"), "/../alacritty.yml")); + + use super::Config; + + #[test] + fn config_read_eof() { + assert_eq!(super::parse_config(DEFAULT_ALACRITTY_CONFIG).unwrap(), Config::default()); + } +} diff --git a/alacritty/src/config/test.rs b/alacritty/src/config/test.rs deleted file mode 100644 index 8da6cef..0000000 --- a/alacritty/src/config/test.rs +++ /dev/null @@ -1,24 +0,0 @@ -use alacritty_terminal::config::DEFAULT_ALACRITTY_CONFIG; - -use crate::config::Config; - -#[test] -fn parse_config() { - let config: Config = - ::serde_yaml::from_str(DEFAULT_ALACRITTY_CONFIG).expect("deserialize config"); - - // Sanity check that mouse bindings are being parsed - assert!(!config.ui_config.mouse_bindings.is_empty()); - - // Sanity check that key bindings are being parsed - assert!(!config.ui_config.key_bindings.is_empty()); -} - -#[test] -fn default_match_empty() { - let default = Config::default(); - - let empty = serde_yaml::from_str("key: val\n").unwrap(); - - assert_eq!(default, empty); -} diff --git a/alacritty/src/config/ui_config.rs b/alacritty/src/config/ui_config.rs index 6230c5b..d7a477a 100644 --- a/alacritty/src/config/ui_config.rs +++ b/alacritty/src/config/ui_config.rs @@ -19,6 +19,16 @@ pub struct UIConfig { pub mouse_bindings: Vec, } +impl Default for UIConfig { + fn default() -> Self { + UIConfig { + mouse: Mouse::default(), + key_bindings: default_key_bindings(), + mouse_bindings: default_mouse_bindings(), + } + } +} + fn default_key_bindings() -> Vec { bindings::default_key_bindings() } diff --git a/alacritty/src/main.rs b/alacritty/src/main.rs index 146709f..cbd0044 100644 --- a/alacritty/src/main.rs +++ b/alacritty/src/main.rs @@ -34,7 +34,7 @@ use std::sync::Arc; #[cfg(target_os = "macos")] use dirs; use glutin::event_loop::EventLoop as GlutinEventLoop; -use log::{error, info}; +use log::info; #[cfg(windows)] use winapi::um::wincon::{AttachConsole, FreeConsole, ATTACH_PARENT_PROCESS}; @@ -85,18 +85,8 @@ fn main() { .expect("Unable to initialize logger"); // Load configuration file - // If the file is a command line argument, we won't write a generated default file - let config_path = options - .config_path() - .or_else(config::installed_config) - .or_else(|| config::write_defaults().ok()) - .map(|path| path.to_path_buf()); - let config = if let Some(path) = config_path { - config::load_from(path) - } else { - error!("Unable to write the default config"); - Config::default() - }; + let config_path = options.config_path().or_else(config::installed_config); + let config = config_path.map(config::load_from).unwrap_or_else(Config::default); let config = options.into_config(config); // Update the log level from config diff --git a/alacritty_terminal/src/config/mod.rs b/alacritty_terminal/src/config/mod.rs index cd90037..f810b51 100644 --- a/alacritty_terminal/src/config/mod.rs +++ b/alacritty_terminal/src/config/mod.rs @@ -18,7 +18,6 @@ use std::fmt::Display; use std::path::PathBuf; use log::error; -use serde::de::DeserializeOwned; use serde::{Deserialize, Deserializer}; use serde_yaml::Value; @@ -39,15 +38,13 @@ pub use crate::config::visual_bell::{VisualBellAnimation, VisualBellConfig}; pub use crate::config::window::{Decorations, Dimensions, StartupMode, WindowConfig, DEFAULT_NAME}; use crate::term::color::Rgb; -pub static DEFAULT_ALACRITTY_CONFIG: &str = - include_str!(concat!(env!("CARGO_MANIFEST_DIR"), "/../alacritty.yml")); pub const LOG_TARGET_CONFIG: &str = "alacritty_config"; const MAX_SCROLLBACK_LINES: u32 = 100_000; pub type MockConfig = Config>; /// Top-level config type -#[derive(Debug, PartialEq, Deserialize)] +#[derive(Debug, PartialEq, Default, Deserialize)] pub struct Config { /// Pixel padding #[serde(default, deserialize_with = "failure_default")] @@ -142,12 +139,6 @@ pub struct Config { pub persistent_logging: Option, } -impl Default for Config { - fn default() -> Self { - serde_yaml::from_str(DEFAULT_ALACRITTY_CONFIG).expect("default config is invalid") - } -} - impl Config { pub fn tabspaces(&self) -> usize { self.tabspaces.0