-
Notifications
You must be signed in to change notification settings - Fork 38
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
12a9c5c
commit 27e23a4
Showing
15 changed files
with
363 additions
and
310 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,61 +1,76 @@ | ||
use color_eyre::Result; | ||
use tokio::sync::mpsc::UnboundedSender; | ||
use tracing::info; | ||
|
||
use crate::action::Action; | ||
use crate::cli::UnitTvChannel; | ||
use crate::components::finders::Entry; | ||
use crate::components::pickers::{self, Picker}; | ||
use crate::components::previewers; | ||
use crate::components::{ | ||
finders::{EnvVarFinder, FileFinder}, | ||
previewers::{EnvVarPreviewer, FilePreviewer}, | ||
}; | ||
|
||
use super::finders::Finder; | ||
|
||
pub enum TvChannel { | ||
Env(pickers::env::EnvVarPicker), | ||
Files(pickers::files::FilePicker), | ||
Env(EnvChannel), | ||
Files(FilesChannel), | ||
} | ||
|
||
impl TvChannel { | ||
pub fn register_action_handler(&mut self, tx: UnboundedSender<Action>) -> Result<()> { | ||
pub fn find(&mut self, pattern: &str) { | ||
match self { | ||
TvChannel::Files(picker) => picker.register_action_handler(tx), | ||
_ => Ok(()), | ||
TvChannel::Env(channel) => channel.finder.find(pattern), | ||
TvChannel::Files(channel) => channel.finder.find(pattern), | ||
} | ||
} | ||
|
||
pub async fn load_entries(&mut self, pattern: &str) -> Result<()> { | ||
pub fn results(&mut self, num_entries: u32, offset: u32) -> Vec<Entry> { | ||
match self { | ||
TvChannel::Env(picker) => picker.load_entries(pattern).await, | ||
TvChannel::Files(picker) => picker.load_entries(pattern).await, | ||
TvChannel::Env(channel) => channel.finder.results(num_entries, offset).collect(), | ||
TvChannel::Files(channel) => channel.finder.results(num_entries, offset).collect(), | ||
} | ||
} | ||
|
||
pub fn entries(&self) -> &Vec<Entry> { | ||
pub fn get_result(&self, index: u32) -> Option<Entry> { | ||
match self { | ||
TvChannel::Env(picker) => picker.entries(), | ||
TvChannel::Files(picker) => picker.entries(), | ||
TvChannel::Env(channel) => channel.finder.get_result(index), | ||
TvChannel::Files(channel) => channel.finder.get_result(index), | ||
} | ||
} | ||
|
||
pub fn clear(&mut self) { | ||
pub fn result_count(&self) -> u32 { | ||
match self { | ||
TvChannel::Env(picker) => picker.clear(), | ||
TvChannel::Files(picker) => picker.clear(), | ||
TvChannel::Env(channel) => channel.finder.result_count(), | ||
TvChannel::Files(channel) => channel.finder.result_count(), | ||
} | ||
} | ||
|
||
pub fn get_preview(&mut self, entry: &Entry) -> previewers::Preview { | ||
if entry.name.is_empty() { | ||
return previewers::Preview::default(); | ||
} | ||
pub fn total_count(&self) -> u32 { | ||
match self { | ||
TvChannel::Env(picker) => picker.get_preview(entry), | ||
TvChannel::Files(picker) => picker.get_preview(entry), | ||
TvChannel::Env(channel) => channel.finder.total_count(), | ||
TvChannel::Files(channel) => channel.finder.total_count(), | ||
} | ||
} | ||
} | ||
|
||
pub async fn get_tv_channel(channel: UnitTvChannel) -> TvChannel { | ||
pub fn get_tv_channel(channel: UnitTvChannel) -> TvChannel { | ||
match channel { | ||
UnitTvChannel::ENV => TvChannel::Env(pickers::env::EnvVarPicker::new().await), | ||
UnitTvChannel::FILES => TvChannel::Files(pickers::files::FilePicker::new().await), | ||
UnitTvChannel::ENV => TvChannel::Env(EnvChannel { | ||
finder: EnvVarFinder::new(), | ||
}), | ||
UnitTvChannel::FILES => TvChannel::Files(FilesChannel { | ||
finder: FileFinder::new(), | ||
}), | ||
_ => unimplemented!(), | ||
} | ||
} | ||
|
||
pub struct EnvChannel { | ||
pub finder: EnvVarFinder, | ||
} | ||
|
||
pub struct FilesChannel { | ||
pub finder: FileFinder, | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.