aboutsummaryrefslogtreecommitdiff
path: root/src/input.rs
diff options
context:
space:
mode:
authorJoe Wilm <joe@jwilm.com>2017-01-01 19:09:27 -0800
committerJoe Wilm <joe@jwilm.com>2017-01-01 19:09:27 -0800
commitd4e20a4741a4966fbb0b8162ed7cdf47007ca7b8 (patch)
treed5afd5e61de6eb229fa2383b4dce8b3ada7edf62 /src/input.rs
parent82bfc41af7d6eff384bdf95cedaf0d62b5450979 (diff)
downloadalacritty-d4e20a4741a4966fbb0b8162ed7cdf47007ca7b8.tar.gz
alacritty-d4e20a4741a4966fbb0b8162ed7cdf47007ca7b8.zip
Improve error handling for clipboard actions
Previously, these could have crashed alacritty. Now, they simply print an error message in Red to stderr. The Red format wrapper was moved to a central location where both main.rs and the alacritty lib can access it.
Diffstat (limited to 'src/input.rs')
-rw-r--r--src/input.rs24
1 files changed, 13 insertions, 11 deletions
diff --git a/src/input.rs b/src/input.rs
index 960bc017..012163b8 100644
--- a/src/input.rs
+++ b/src/input.rs
@@ -25,12 +25,12 @@ use glutin::{ElementState, VirtualKeyCode, MouseButton};
use glutin::{Mods, mods};
use glutin::{TouchPhase, MouseScrollDelta};
-use event::Notify;
+use event::{Mouse, Notify};
use index::{Line, Column, Side, Point};
use selection::Selection;
use term::mode::{self, TermMode};
use term::{self, Term};
-use event::Mouse;
+use util::fmt::Red;
/// Processes input from glutin.
///
@@ -149,16 +149,17 @@ impl Action {
let buf = ctx.terminal.string_from_selection(&selection);
if !buf.is_empty() {
Clipboard::new()
- .expect("get clipboard")
- .store_primary(buf)
- .expect("copy into clipboard");
+ .and_then(|mut clipboard| clipboard.store_primary(buf))
+ .unwrap_or_else(|err| {
+ err_println!("Error storing selection to clipboard: {}", Red(err));
+ });
}
}
},
Action::Paste |
Action::PasteSelection => {
- let clip = Clipboard::new().expect("get clipboard");
- clip.load_selection()
+ Clipboard::new()
+ .and_then(|clipboard| clipboard.load_selection())
.map(|contents| {
if ctx.terminal.mode().contains(mode::BRACKETED_PASTE) {
ctx.notifier.notify(&b"\x1b[200~"[..]);
@@ -169,7 +170,7 @@ impl Action {
}
})
.unwrap_or_else(|err| {
- err_println!("Error getting clipboard contents: {}", err);
+ err_println!("Error loading data from clipboard {}", Red(err));
});
},
}
@@ -275,9 +276,10 @@ impl<'a, N: Notify + 'a> Processor<'a, N> {
let buf = self.ctx.terminal.string_from_selection(&selection);
if !buf.is_empty() {
Clipboard::new()
- .expect("get clipboard")
- .store_selection(buf)
- .expect("copy into clipboard");
+ .and_then(|mut clipboard| clipboard.store_selection(buf))
+ .unwrap_or_else(|err| {
+ err_println!("Error storing selection to clipboard: {}", Red(err));
+ });
}
}
}