aboutsummaryrefslogtreecommitdiff
path: root/src/config.rs
diff options
context:
space:
mode:
authorChristian Duerr <chrisduerr@users.noreply.github.com>2018-03-04 22:40:15 +0000
committerGitHub <noreply@github.com>2018-03-04 22:40:15 +0000
commit7f2b398ad2084bdaaa266e8da770a213f0a9a2eb (patch)
tree9d249fd13e80c9ca2d03f37fd6147fbc1ee8ba4a /src/config.rs
parent475ebecfc4e0648242e82e256dee1489f3a3fe81 (diff)
downloadalacritty-7f2b398ad2084bdaaa266e8da770a213f0a9a2eb.tar.gz
alacritty-7f2b398ad2084bdaaa266e8da770a213f0a9a2eb.zip
Remove all instances of unwrap() from config
Unwrapping inside the config file parsing can lead to some issues that prevent us from falling back to a default configuration file. One instance of that issue was mentioned in #1135. Now all instances of `unwrap()` have been removed and replaced with proper error handling. This will make the config more robust and prevents live reload from silently breaking while alacritty is running. This also fixes a few currently existing clippy issues. Clippy added an additonal lint which complains about `MyStruct { field: field }`. These issues have been fixed, except for some false-positives and issues in external macros which will probably be fixed with future updates (rust-lang-nursery/bitflags#149)
Diffstat (limited to 'src/config.rs')
-rw-r--r--src/config.rs47
1 files changed, 21 insertions, 26 deletions
diff --git a/src/config.rs b/src/config.rs
index be967150..eb7f0f72 100644
--- a/src/config.rs
+++ b/src/config.rs
@@ -214,7 +214,7 @@ impl<'a> Shell<'a> {
{
Shell {
program: program.into(),
- args: args
+ args,
}
}
@@ -678,9 +678,9 @@ struct RawBinding {
impl RawBinding {
fn into_mouse_binding(self) -> ::std::result::Result<MouseBinding, Self> {
- if self.mouse.is_some() {
+ if let Some(mouse) = self.mouse {
Ok(Binding {
- trigger: self.mouse.unwrap(),
+ trigger: mouse,
mods: self.mods,
action: self.action,
mode: self.mode,
@@ -692,9 +692,9 @@ impl RawBinding {
}
fn into_key_binding(self) -> ::std::result::Result<KeyBinding, Self> {
- if self.key.is_some() {
+ if let Some(key) = self.key {
Ok(KeyBinding {
- trigger: self.key.unwrap(),
+ trigger: key,
mods: self.mods,
action: self.action,
mode: self.mode,
@@ -865,12 +865,12 @@ impl<'a> de::Deserialize<'a> for RawBinding {
}
Ok(RawBinding {
- mode: mode,
+ mode,
notmode: not_mode,
- action: action,
- key: key,
- mouse: mouse,
- mods: mods,
+ action,
+ key,
+ mouse,
+ mods,
})
}
}
@@ -977,8 +977,8 @@ impl CursorOrPrimaryColors {
fn into_cursor_colors(self) -> CursorColors {
match self {
CursorOrPrimaryColors::Cursor { text, cursor } => CursorColors {
- text: text,
- cursor: cursor
+ text,
+ cursor,
},
CursorOrPrimaryColors::Primary { foreground, background } => {
// Must print in config since logger isn't setup yet.
@@ -1124,12 +1124,12 @@ impl FromStr for Rgb {
macro_rules! component {
($($c:ident),*) => {
$(
- match chars.next().unwrap().to_digit(16) {
+ match chars.next().and_then(|c| c.to_digit(16)) {
Some(val) => rgb.$c = (val as u8) << 4,
None => return Err(())
}
- match chars.next().unwrap().to_digit(16) {
+ match chars.next().and_then(|c| c.to_digit(16)) {
Some(val) => rgb.$c |= val as u8,
None => return Err(())
}
@@ -1137,9 +1137,9 @@ impl FromStr for Rgb {
}
}
- match chars.next().unwrap() {
- '0' => if chars.next().unwrap() != 'x' { return Err(()); },
- '#' => (),
+ match chars.next() {
+ Some('0') => if chars.next() != Some('x') { return Err(()); },
+ Some('#') => (),
_ => return Err(()),
}
@@ -1429,8 +1429,8 @@ impl Default for Dimensions {
impl Dimensions {
pub fn new(columns: Column, lines: Line) -> Self {
Dimensions {
- columns: columns,
- lines: lines
+ columns,
+ lines,
}
}
@@ -1668,7 +1668,8 @@ impl Monitor {
_thread: ::util::thread::spawn_named("config watcher", move || {
let (tx, rx) = mpsc::channel();
// The Duration argument is a debouncing period.
- let mut watcher = watcher(tx, Duration::from_millis(10)).unwrap();
+ let mut watcher = watcher(tx, Duration::from_millis(10))
+ .expect("Unable to spawn file watcher");
let config_path = ::std::fs::canonicalize(path)
.expect("canonicalize config path");
@@ -1742,7 +1743,6 @@ enum Key {
Key8,
Key9,
Key0,
-
A,
B,
C,
@@ -1769,9 +1769,7 @@ enum Key {
X,
Y,
Z,
-
Escape,
-
F1,
F2,
F3,
@@ -1787,7 +1785,6 @@ enum Key {
F13,
F14,
F15,
-
Snapshot,
Scroll,
Pause,
@@ -1797,7 +1794,6 @@ enum Key {
End,
PageDown,
PageUp,
-
Left,
Up,
Right,
@@ -1817,7 +1813,6 @@ enum Key {
Numpad7,
Numpad8,
Numpad9,
-
AbntC1,
AbntC2,
Add,