Sometimes you can't get a clipboard, don't fail
This should fix CI as well, but there are possibly folks out there that don't have a functioning clipboard and still want to run.
This commit is contained in:
parent
bb8c87bad9
commit
69b9bc9824
1 changed files with 12 additions and 7 deletions
|
|
@ -13,7 +13,7 @@ use crossterm::{
|
||||||
EnterAlternateScreen, LeaveAlternateScreen,
|
EnterAlternateScreen, LeaveAlternateScreen,
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
use log::{error, info, Level, Metadata, Record};
|
use log::{error, info, warn, Level, Metadata, Record};
|
||||||
use std::collections::vec_deque::VecDeque;
|
use std::collections::vec_deque::VecDeque;
|
||||||
use std::collections::{HashMap, HashSet};
|
use std::collections::{HashMap, HashSet};
|
||||||
use std::io::stdout;
|
use std::io::stdout;
|
||||||
|
|
@ -218,7 +218,7 @@ pub struct UI {
|
||||||
show_help: bool,
|
show_help: bool,
|
||||||
alternate_screen: bool,
|
alternate_screen: bool,
|
||||||
raw_mode: bool,
|
raw_mode: bool,
|
||||||
clipboard: ClipboardContext,
|
clipboard: Option<ClipboardContext>,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl UI {
|
impl UI {
|
||||||
|
|
@ -228,6 +228,8 @@ impl UI {
|
||||||
ports.insert(*port, Listener::from_config(config.clone()));
|
ports.insert(*port, Listener::from_config(config.clone()));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
let clipboard = ClipboardContext::new().ok();
|
||||||
|
|
||||||
UI {
|
UI {
|
||||||
events,
|
events,
|
||||||
ports,
|
ports,
|
||||||
|
|
@ -240,8 +242,7 @@ impl UI {
|
||||||
config,
|
config,
|
||||||
alternate_screen: false,
|
alternate_screen: false,
|
||||||
raw_mode: false,
|
raw_mode: false,
|
||||||
clipboard: ClipboardContext::new()
|
clipboard,
|
||||||
.expect("Unable to initialize clipboard context"),
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -672,10 +673,14 @@ impl UI {
|
||||||
}
|
}
|
||||||
Some(UIEvent::SetClipboard(contents)) => {
|
Some(UIEvent::SetClipboard(contents)) => {
|
||||||
let length = contents.len();
|
let length = contents.len();
|
||||||
if let Err(e) = self.clipboard.set_contents(contents) {
|
if let Some(clipboard) = self.clipboard.as_mut() {
|
||||||
error!("Error setting clipboard contents: {e:#}");
|
if let Err(e) = clipboard.set_contents(contents) {
|
||||||
|
error!("Error setting clipboard contents: {e:#}");
|
||||||
|
} else {
|
||||||
|
info!("Received clipboard contents ({length} bytes)");
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
info!("Received clipboard contents ({length} bytes)");
|
warn!("No clipboard available, contents discarded");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
None => {
|
None => {
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue