aboutsummaryrefslogtreecommitdiff
path: root/src
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
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')
-rw-r--r--src/ansi.rs6
-rw-r--r--src/config.rs47
-rw-r--r--src/display.rs14
-rw-r--r--src/event.rs8
-rw-r--r--src/event_loop.rs12
-rw-r--r--src/grid.rs6
-rw-r--r--src/index.rs2
-rw-r--r--src/logging.rs2
-rw-r--r--src/meter.rs2
-rw-r--r--src/renderer/mod.rs38
-rw-r--r--src/selection.rs36
-rw-r--r--src/term/cell.rs6
-rw-r--r--src/term/mod.rs26
-rw-r--r--src/window.rs4
14 files changed, 102 insertions, 107 deletions
diff --git a/src/ansi.rs b/src/ansi.rs
index 3bcfff88..b59959f5 100644
--- a/src/ansi.rs
+++ b/src/ansi.rs
@@ -65,7 +65,7 @@ fn parse_rgb_color(color: &[u8]) -> Option<Rgb> {
if next!() != Some('/') { return None; }
let b = parse_hex!();
- Some(Rgb { r: r, g: g, b: b})
+ Some(Rgb { r, g, b })
}
Some('#') => {
Some(Rgb {
@@ -128,8 +128,8 @@ impl<'a, H: Handler + TermInfo + 'a, W: io::Write> Performer<'a, H, W> {
) -> Performer<'b, H, W> {
Performer {
_state: state,
- handler: handler,
- writer: writer,
+ handler,
+ writer,
}
}
}
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,
diff --git a/src/display.rs b/src/display.rs
index 9227037e..418f616e 100644
--- a/src/display.rs
+++ b/src/display.rs
@@ -198,15 +198,15 @@ impl Display {
});
Ok(Display {
- window: window,
- renderer: renderer,
- glyph_cache: glyph_cache,
- render_timer: render_timer,
- tx: tx,
- rx: rx,
+ window,
+ renderer,
+ glyph_cache,
+ render_timer,
+ tx,
+ rx,
meter: Meter::new(),
font_size: font::Size::new(0.),
- size_info: size_info,
+ size_info,
last_background_color: background_color,
})
}
diff --git a/src/event.rs b/src/event.rs
index b133f8fa..8c4107ca 100644
--- a/src/event.rs
+++ b/src/event.rs
@@ -227,12 +227,12 @@ impl<N: Notify> Processor<N> {
mouse_config: config.mouse().to_owned(),
print_events: options.print_events,
wait_for_event: true,
- notifier: notifier,
- resize_tx: resize_tx,
- ref_test: ref_test,
+ notifier,
+ resize_tx,
+ ref_test,
mouse: Default::default(),
selection: None,
- size_info: size_info,
+ size_info,
hide_cursor_when_typing: config.hide_cursor_when_typing(),
hide_cursor: false,
received_count: 0,
diff --git a/src/event_loop.rs b/src/event_loop.rs
index 30732e2a..ce034ff0 100644
--- a/src/event_loop.rs
+++ b/src/event_loop.rs
@@ -179,12 +179,12 @@ impl<Io> EventLoop<Io>
let (tx, rx) = channel::channel();
EventLoop {
poll: mio::Poll::new().expect("create mio Poll"),
- pty: pty,
- tx: tx,
- rx: rx,
- terminal: terminal,
- display: display,
- ref_test: ref_test,
+ pty,
+ tx,
+ rx,
+ terminal,
+ display,
+ ref_test,
}
}
diff --git a/src/grid.rs b/src/grid.rs
index ed7efdb4..f40ceec9 100644
--- a/src/grid.rs
+++ b/src/grid.rs
@@ -82,9 +82,9 @@ impl<T: Clone> Grid<T> {
}
Grid {
- raw: raw,
- cols: cols,
- lines: lines,
+ raw,
+ cols,
+ lines,
}
}
diff --git a/src/index.rs b/src/index.rs
index 7fb591f4..418faff2 100644
--- a/src/index.rs
+++ b/src/index.rs
@@ -35,7 +35,7 @@ pub struct Point {
impl Point {
pub fn new(line: Line, col: Column) -> Point {
- Point { line: line, col: col }
+ Point { line, col }
}
}
diff --git a/src/logging.rs b/src/logging.rs
index ff2a7735..421223e8 100644
--- a/src/logging.rs
+++ b/src/logging.rs
@@ -32,7 +32,7 @@ impl<T: Send + io::Write> Logger<T> {
#[cfg_attr(feature = "clippy", allow(new_ret_no_self))]
pub fn new(output: T, level: log::LevelFilter) -> Logger<io::LineWriter<T>> {
Logger {
- level: level,
+ level,
output: sync::Mutex::new(io::LineWriter::new(output))
}
}
diff --git a/src/meter.rs b/src/meter.rs
index 51e68c34..1b6003db 100644
--- a/src/meter.rs
+++ b/src/meter.rs
@@ -62,7 +62,7 @@ pub struct Sampler<'a> {
impl<'a> Sampler<'a> {
fn new(meter: &'a mut Meter) -> Sampler<'a> {
Sampler {
- meter: meter,
+ meter,
created_at: Instant::now(),
}
}
diff --git a/src/renderer/mod.rs b/src/renderer/mod.rs
index c0e4a9f3..5b53e70f 100644
--- a/src/renderer/mod.rs
+++ b/src/renderer/mod.rs
@@ -188,13 +188,13 @@ impl GlyphCache {
let mut cache = GlyphCache {
cache: HashMap::default(),
- rasterizer: rasterizer,
+ rasterizer,
font_size: font.size(),
font_key: regular,
bold_key: bold,
italic_key: italic,
glyph_offset: *font.glyph_offset(),
- metrics: metrics
+ metrics,
};
cache.load_glyphs_for_font(regular, loader);
@@ -214,7 +214,7 @@ impl GlyphCache {
self.get(&GlyphKey {
font_key: font,
c: i as char,
- size: size
+ size,
}, loader);
}
}
@@ -262,7 +262,7 @@ impl GlyphCache {
let style = if let Some(ref spec) = desc.style {
font::Style::Specific(spec.to_owned())
} else {
- font::Style::Description {slant:slant, weight:weight}
+ font::Style::Description { slant, weight }
};
FontDesc::new(&desc.family[..], style)
}
@@ -606,11 +606,11 @@ impl QuadRenderer {
}
let mut renderer = QuadRenderer {
- program: program,
- vao: vao,
- vbo: vbo,
- ebo: ebo,
- vbo_instance: vbo_instance,
+ program,
+ vao,
+ vbo,
+ ebo,
+ vbo_instance,
atlas: Vec::new(),
current_atlas: 0,
active_tex: 0,
@@ -662,7 +662,7 @@ impl QuadRenderer {
current_atlas: &mut self.current_atlas,
program: &mut self.program,
visual_bell_intensity: visual_bell_intensity as _,
- config: config,
+ config,
});
unsafe {
@@ -789,9 +789,9 @@ impl<'a> RenderApi<'a> {
let cells = string.chars()
.enumerate()
.map(|(i, c)| RenderableCell {
- line: line,
+ line,
column: col + i,
- c: c,
+ c,
bg: color,
fg: Rgb { r: 0, g: 0, b: 0 },
flags: cell::Flags::empty(),
@@ -835,7 +835,7 @@ impl<'a> RenderApi<'a> {
}
let glyph_key = GlyphKey {
- font_key: font_key,
+ font_key,
size: glyph_cache.font_size,
c: cell.c
};
@@ -851,7 +851,7 @@ impl<'a> RenderApi<'a> {
// easy, clean hack.
if cell.flags.contains(cell::Flags::UNDERLINE) {
let glyph_key = GlyphKey {
- font_key: font_key,
+ font_key,
size: glyph_cache.font_size,
c: '_'
};
@@ -1332,7 +1332,7 @@ impl Atlas {
}
Atlas {
- id: id,
+ id,
width: size,
height: size,
row_extent: 0,
@@ -1424,10 +1424,10 @@ impl Atlas {
width: width as f32,
height: height as f32,
left: glyph.left as f32,
- uv_bot: uv_bot,
- uv_left: uv_left,
- uv_width: uv_width,
- uv_height: uv_height,
+ uv_bot,
+ uv_left,
+ uv_width,
+ uv_height,
}
}
diff --git a/src/selection.rs b/src/selection.rs
index 92410104..cd905164 100644
--- a/src/selection.rs
+++ b/src/selection.rs
@@ -75,7 +75,7 @@ pub struct Anchor {
impl Anchor {
fn new(point: Point, side: Side) -> Anchor {
- Anchor { point: point, side: side }
+ Anchor { point, side }
}
}
@@ -114,8 +114,8 @@ impl Selection {
end: point,
},
initial_expansion: Region {
- start: start,
- end: end
+ start,
+ end,
}
}
}
@@ -248,10 +248,10 @@ impl Selection {
return None;
} else {
return Some(Span {
- cols: cols,
+ cols,
ty: SpanType::Inclusive,
- front: front,
- tail: tail
+ front,
+ tail,
});
}
}
@@ -266,30 +266,30 @@ impl Selection {
Some(match (front_side, tail_side) {
// [FX][XX][XT]
(Side::Left, Side::Right) => Span {
- cols: cols,
- front: front,
- tail: tail,
+ cols,
+ front,
+ tail,
ty: SpanType::Inclusive
},
// [ F][XX][T ]
(Side::Right, Side::Left) => Span {
- cols: cols,
- front: front,
- tail: tail,
+ cols,
+ front,
+ tail,
ty: SpanType::Exclusive
},
// [FX][XX][T ]
(Side::Left, Side::Left) => Span {
- cols: cols,
- front: front,
- tail: tail,
+ cols,
+ front,
+ tail,
ty: SpanType::ExcludeTail
},
// [ F][XX][XT]
(Side::Right, Side::Right) => Span {
- cols: cols,
- front: front,
- tail: tail,
+ cols,
+ front,
+ tail,
ty: SpanType::ExcludeFront
},
})
diff --git a/src/term/cell.rs b/src/term/cell.rs
index 16e08cba..a04eb8e1 100644
--- a/src/term/cell.rs
+++ b/src/term/cell.rs
@@ -92,9 +92,9 @@ impl Cell {
pub fn new(c: char, fg: Color, bg: Color) -> Cell {
Cell {
- c: c,
- bg: bg,
- fg: fg,
+ c,
+ bg,
+ fg,
flags: Flags::empty(),
}
}
diff --git a/src/term/mod.rs b/src/term/mod.rs
index b11733f6..00244c8a 100644
--- a/src/term/mod.rs
+++ b/src/term/mod.rs
@@ -123,15 +123,15 @@ impl<'a> RenderableCellsIter<'a> {
let cursor_index = Linear(cursor.line.0 * grid.num_cols().0 + cursor.col.0);
RenderableCellsIter {
- grid: grid,
- cursor: cursor,
- cursor_index: cursor_index,
- mode: mode,
+ grid,
+ cursor,
+ cursor_index,
+ mode,
line: Line(0),
column: Column(0),
- selection: selection,
- config: config,
- colors: colors,
+ selection,
+ config,
+ colors,
cursor_cells: ArrayDeque::new(),
}.initialize(cursor_style)
}
@@ -396,13 +396,13 @@ impl<'a> Iterator for RenderableCellsIter<'a> {
}
return Some(RenderableCell {
- line: line,
- column: column,
+ line,
+ column,
flags: cell.flags,
c: cell.c,
fg: fg_rgb,
bg: bg_rgb,
- bg_alpha: bg_alpha,
+ bg_alpha,
})
}
@@ -816,7 +816,7 @@ impl Term {
visual_bell: VisualBell::new(config),
next_is_urgent: None,
input_needs_wrap: false,
- grid: grid,
+ grid,
alt_grid: alt,
alt: false,
font_size: config.font().size(),
@@ -825,9 +825,9 @@ impl Term {
cursor: Default::default(),
cursor_save: Default::default(),
cursor_save_alt: Default::default(),
- tabs: tabs,
+ tabs,
mode: Default::default(),
- scroll_region: scroll_region,
+ scroll_region,
size_info: size,
colors: color::List::from(config.colors()),
color_modified: [false; color::COUNT],
diff --git a/src/window.rs b/src/window.rs
index 55b7cd55..9644cd42 100644
--- a/src/window.rs
+++ b/src/window.rs
@@ -216,8 +216,8 @@ impl Window {
}
let window = Window {
- event_loop: event_loop,
- window: window,
+ event_loop,
+ window,
cursor_visible: true,
is_focused: true,
};