mirror of
https://github.com/alexpasmantier/television.git
synced 2025-06-06 03:25:23 +00:00
fix(stdout): never quote selected entries (#307)
fixes #284 the outcome of entry selection quoting was not consistent depending on whether the entry existed on the filesystem or not this PR removes all entry quoting, making the behaviour consistent and predictible - remove quoting of entries in Entry#stdout_repr - apply clippy suggestions for redundant clones
This commit is contained in:
parent
3970f65946
commit
c7109044f0
@ -271,6 +271,7 @@ impl App {
|
||||
{
|
||||
return Ok(ActionOutcome::Entries(entries));
|
||||
}
|
||||
|
||||
return Ok(ActionOutcome::Input(
|
||||
self.television.lock().await.current_pattern.clone(),
|
||||
));
|
||||
|
@ -170,7 +170,7 @@ async fn load_aliases(injector: Injector<Alias>) {
|
||||
None
|
||||
})
|
||||
.for_each(|alias| {
|
||||
let () = injector.push(alias.clone(), |e, cols| {
|
||||
let () = injector.push(alias, |e, cols| {
|
||||
cols[0] = (e.name.clone() + &e.value).into();
|
||||
});
|
||||
});
|
||||
|
@ -159,7 +159,7 @@ impl OnAir for Channel {
|
||||
.map(|item| {
|
||||
let path = item.matched_string;
|
||||
Entry::new(
|
||||
path.clone(),
|
||||
path,
|
||||
match &self.preview_kind {
|
||||
PreviewKind::Command(ref preview_command) => {
|
||||
PreviewType::Command(preview_command.clone())
|
||||
@ -179,7 +179,7 @@ impl OnAir for Channel {
|
||||
self.matcher.get_result(index).map(|item| {
|
||||
let path = item.matched_string;
|
||||
Entry::new(
|
||||
path.clone(),
|
||||
path,
|
||||
match &self.preview_kind {
|
||||
PreviewKind::Command(ref preview_command) => {
|
||||
PreviewType::Command(preview_command.clone())
|
||||
|
@ -1,7 +1,6 @@
|
||||
use std::{
|
||||
fmt::Display,
|
||||
hash::{Hash, Hasher},
|
||||
path::PathBuf,
|
||||
};
|
||||
|
||||
use devicons::FileIcon;
|
||||
@ -143,12 +142,6 @@ impl Entry {
|
||||
|
||||
pub fn stdout_repr(&self) -> String {
|
||||
let mut repr = self.name.clone();
|
||||
if PathBuf::from(&repr).exists()
|
||||
&& repr.contains(|c| char::is_ascii_whitespace(&c))
|
||||
{
|
||||
repr.insert(0, '\'');
|
||||
repr.push('\'');
|
||||
}
|
||||
if let Some(line_number) = self.line_number {
|
||||
repr.push_str(&format!(":{line_number}"));
|
||||
}
|
||||
@ -226,4 +219,32 @@ mod tests {
|
||||
let ranges = vec![(1, 2), (3, 4), (5, 6)];
|
||||
assert_eq!(merge_ranges(&ranges), vec![(1, 2), (3, 4), (5, 6)]);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_leaves_name_intact() {
|
||||
let entry = Entry {
|
||||
name: "test name with spaces".to_string(),
|
||||
value: None,
|
||||
name_match_ranges: None,
|
||||
value_match_ranges: None,
|
||||
icon: None,
|
||||
line_number: None,
|
||||
preview_type: PreviewType::Basic,
|
||||
};
|
||||
assert_eq!(entry.stdout_repr(), "test name with spaces");
|
||||
}
|
||||
#[test]
|
||||
fn test_uses_line_number_information() {
|
||||
let a: usize = 10;
|
||||
let entry = Entry {
|
||||
name: "test_file_name.rs".to_string(),
|
||||
value: None,
|
||||
name_match_ranges: None,
|
||||
value_match_ranges: None,
|
||||
icon: None,
|
||||
line_number: Some(a),
|
||||
preview_type: PreviewType::Basic,
|
||||
};
|
||||
assert_eq!(entry.stdout_repr(), "test_file_name.rs:10");
|
||||
}
|
||||
}
|
||||
|
@ -64,12 +64,9 @@ impl OnAir for Channel {
|
||||
.into_iter()
|
||||
.map(|item| {
|
||||
let path = item.matched_string;
|
||||
Entry::new(
|
||||
path.clone(),
|
||||
PreviewType::Command(PREVIEW_COMMAND.clone()),
|
||||
)
|
||||
.with_name_match_ranges(&item.match_indices)
|
||||
.with_icon(self.icon)
|
||||
Entry::new(path, PreviewType::Command(PREVIEW_COMMAND.clone()))
|
||||
.with_name_match_ranges(&item.match_indices)
|
||||
.with_icon(self.icon)
|
||||
})
|
||||
.collect()
|
||||
}
|
||||
@ -77,11 +74,8 @@ impl OnAir for Channel {
|
||||
fn get_result(&self, index: u32) -> Option<Entry> {
|
||||
self.matcher.get_result(index).map(|item| {
|
||||
let path = item.matched_string;
|
||||
Entry::new(
|
||||
path.clone(),
|
||||
PreviewType::Command(PREVIEW_COMMAND.clone()),
|
||||
)
|
||||
.with_icon(self.icon)
|
||||
Entry::new(path, PreviewType::Command(PREVIEW_COMMAND.clone()))
|
||||
.with_icon(self.icon)
|
||||
})
|
||||
}
|
||||
|
||||
|
@ -78,9 +78,9 @@ impl RemoteControl {
|
||||
.as_ref()
|
||||
.and_then(|channels| channels.get(channel_name).cloned())
|
||||
{
|
||||
Some(prototype) => Ok(TelevisionChannel::Cable(
|
||||
cable::Channel::from(prototype.clone()),
|
||||
)),
|
||||
Some(prototype) => {
|
||||
Ok(TelevisionChannel::Cable(cable::Channel::from(prototype)))
|
||||
}
|
||||
None => match UnitChannel::try_from(channel_name) {
|
||||
Ok(channel) => Ok(channel.into()),
|
||||
Err(_) => Err(color_eyre::eyre::eyre!(
|
||||
|
@ -91,7 +91,7 @@ impl OnAir for Channel {
|
||||
|
||||
fn get_result(&self, index: u32) -> Option<Entry> {
|
||||
self.matcher.get_result(index).map(|item| {
|
||||
Entry::new(item.matched_string.clone(), self.preview_type.clone())
|
||||
Entry::new(item.matched_string, self.preview_type.clone())
|
||||
})
|
||||
}
|
||||
|
||||
|
@ -423,9 +423,7 @@ impl Television {
|
||||
.iter()
|
||||
.map(|e| e.name.clone())
|
||||
.collect::<Vec<_>>()
|
||||
.join(" ")
|
||||
.to_string()
|
||||
.to_string(),
|
||||
.join(" "),
|
||||
)
|
||||
.unwrap();
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user