Error if empty list is passed to set selection
This commit is contained in:
parent
fac1ab37ea
commit
df610c7e03
@ -16,6 +16,8 @@ pub enum KakError {
|
||||
NotImplemented(&'static str),
|
||||
/// Custom error string
|
||||
Custom(String),
|
||||
/// The selections/selections_desc list passed was empty
|
||||
SetEmptySelections,
|
||||
}
|
||||
|
||||
impl KakError {
|
||||
@ -28,6 +30,9 @@ impl KakError {
|
||||
Self::Io(e) => format!("{e:?}"),
|
||||
Self::NotImplemented(e) => e.to_string(),
|
||||
Self::Custom(s) => s.clone(),
|
||||
Self::SetEmptySelections => {
|
||||
String::from("Attempted to set selections/selections_desc to empty list")
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -44,6 +49,8 @@ impl ToString for KakError {
|
||||
Self::Io(_) => "IO error",
|
||||
Self::NotImplemented(_) => "Not Implemented",
|
||||
Self::Custom(s) => s,
|
||||
Self::SetEmptySelections =>
|
||||
"Attempted to set selections/selections_desc to empty list",
|
||||
}
|
||||
)
|
||||
}
|
||||
|
@ -96,9 +96,14 @@ where
|
||||
I: IntoIterator<Item = &'a S>,
|
||||
S: AsRef<str>,
|
||||
{
|
||||
let mut selections_iter = selections.into_iter().peekable();
|
||||
if selections_iter.peek().is_none() {
|
||||
return Err(KakError::SetEmptySelections);
|
||||
}
|
||||
|
||||
let mut f = open_command_fifo()?;
|
||||
write!(f, "set-register '\"'")?;
|
||||
for i in selections {
|
||||
for i in selections_iter {
|
||||
write!(f, " '{}'", escape(i))?;
|
||||
}
|
||||
write!(f, "; execute-keys R;")?;
|
||||
@ -113,9 +118,14 @@ pub fn set_selections_desc<'a, I>(selections: I) -> Result<(), KakError>
|
||||
where
|
||||
I: IntoIterator<Item = &'a SelectionDesc>,
|
||||
{
|
||||
let mut selections_iter = selections.into_iter().peekable();
|
||||
if selections_iter.peek().is_none() {
|
||||
return Err(KakError::SetEmptySelections);
|
||||
}
|
||||
|
||||
let mut f = open_command_fifo()?;
|
||||
write!(f, "select")?;
|
||||
for i in selections {
|
||||
for i in selections_iter {
|
||||
write!(f, " {}", i)?;
|
||||
}
|
||||
write!(f, ";")?;
|
||||
|
Loading…
Reference in New Issue
Block a user