Skip to content

Commit

Permalink
feat(channels): allow sending currently selected entries to other cha…
Browse files Browse the repository at this point in the history
…nnels (#235)

Related to #229
  • Loading branch information
alexpasmantier authored Jan 6, 2025
1 parent 2e5f65b commit e2398ab
Show file tree
Hide file tree
Showing 3 changed files with 50 additions and 14 deletions.
12 changes: 10 additions & 2 deletions crates/television-channels/src/channels/dirs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,11 @@ impl From<&mut TelevisionChannel> for Channel {
fn from(value: &mut TelevisionChannel) -> Self {
match value {
c @ TelevisionChannel::GitRepos(_) => {
let entries = c.results(c.result_count(), 0);
let entries = if c.selected_entries().is_empty() {
c.results(c.result_count(), 0)
} else {
c.selected_entries().iter().cloned().collect()
};
Self::new(
entries
.iter()
Expand All @@ -46,7 +50,11 @@ impl From<&mut TelevisionChannel> for Channel {
)
}
c @ TelevisionChannel::Dirs(_) => {
let entries = c.results(c.result_count(), 0);
let entries = if c.selected_entries().is_empty() {
c.results(c.result_count(), 0)
} else {
c.selected_entries().iter().cloned().collect()
};
Self::new(
entries
.iter()
Expand Down
18 changes: 15 additions & 3 deletions crates/television-channels/src/channels/files.rs
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,11 @@ impl From<&mut TelevisionChannel> for Channel {
fn from(value: &mut TelevisionChannel) -> Self {
match value {
c @ TelevisionChannel::GitRepos(_) => {
let entries = c.results(c.result_count(), 0);
let entries = if c.selected_entries().is_empty() {
c.results(c.result_count(), 0)
} else {
c.selected_entries().iter().cloned().collect()
};
Self::new(
entries
.iter()
Expand All @@ -46,7 +50,11 @@ impl From<&mut TelevisionChannel> for Channel {
)
}
c @ TelevisionChannel::Files(_) => {
let entries = c.results(c.result_count(), 0);
let entries = if c.selected_entries().is_empty() {
c.results(c.result_count(), 0)
} else {
c.selected_entries().iter().cloned().collect()
};
Self::new(
entries
.iter()
Expand All @@ -55,7 +63,11 @@ impl From<&mut TelevisionChannel> for Channel {
)
}
c @ TelevisionChannel::Text(_) => {
let entries = c.results(c.result_count(), 0);
let entries = if c.selected_entries().is_empty() {
c.results(c.result_count(), 0)
} else {
c.selected_entries().iter().cloned().collect()
};
Self::new(
entries
.iter()
Expand Down
34 changes: 25 additions & 9 deletions crates/television-channels/src/channels/text.rs
Original file line number Diff line number Diff line change
Expand Up @@ -124,12 +124,16 @@ impl From<&mut TelevisionChannel> for Channel {
fn from(value: &mut TelevisionChannel) -> Self {
match value {
c @ TelevisionChannel::Files(_) => {
let entries = c.results(
c.result_count().min(
u32::try_from(MAX_PIPED_FILES).unwrap_or(u32::MAX),
),
0,
);
let entries = if c.selected_entries().is_empty() {
c.results(
c.result_count().min(
u32::try_from(MAX_PIPED_FILES).unwrap_or(u32::MAX),
),
0,
)
} else {
c.selected_entries().iter().cloned().collect()
};
Self::from_file_paths(
entries
.iter()
Expand All @@ -140,7 +144,11 @@ impl From<&mut TelevisionChannel> for Channel {
)
}
c @ TelevisionChannel::GitRepos(_) => {
let entries = c.results(c.result_count(), 0);
let entries = if c.selected_entries().is_empty() {
c.results(c.result_count(), 0)
} else {
c.selected_entries().iter().cloned().collect()
};
Self::new(
entries
.iter()
Expand All @@ -151,11 +159,19 @@ impl From<&mut TelevisionChannel> for Channel {
)
}
c @ TelevisionChannel::Text(_) => {
let entries = c.results(c.result_count(), 0);
let entries = if c.selected_entries().is_empty() {
c.results(c.result_count(), 0)
} else {
c.selected_entries().iter().cloned().collect()
};
Self::from_text_entries(entries)
}
c @ TelevisionChannel::Dirs(_) => {
let entries = c.results(c.result_count(), 0);
let entries = if c.selected_entries().is_empty() {
c.results(c.result_count(), 0)
} else {
c.selected_entries().iter().cloned().collect()
};
Self::new(
entries
.iter()
Expand Down

0 comments on commit e2398ab

Please sign in to comment.