-
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
d2b0fe9
commit c9ee129
Showing
8 changed files
with
371 additions
and
276 deletions.
There are no files selected for viewing
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 |
---|---|---|
|
@@ -7,6 +7,7 @@ pub enum UnitTvChannel { | |
#[default] | ||
ENV, | ||
FILES, | ||
GREP, | ||
OTHER, | ||
} | ||
|
||
|
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,76 +1,81 @@ | ||
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::previewers; | ||
use crate::components::{ | ||
finders::{EnvVarFinder, FileFinder, NucleoEnvVarFinder}, | ||
previewers::{EnvVarPreviewer, FilePreviewer}, | ||
}; | ||
use crate::components::finders::{EnvVarFinder, FileFinder, GrepFinder}; | ||
|
||
use super::finders::Finder; | ||
|
||
pub enum TvChannel { | ||
Env(EnvChannel), | ||
Files(FilesChannel), | ||
Grep(GrepChannel), | ||
} | ||
|
||
impl TvChannel { | ||
pub fn find(&mut self, pattern: &str) { | ||
match self { | ||
TvChannel::Env(channel) => channel.finder.find(pattern), | ||
TvChannel::Files(channel) => channel.finder.find(pattern), | ||
TvChannel::Grep(channel) => channel.finder.find(pattern), | ||
} | ||
} | ||
|
||
// FIXME: could we avoid collecting here? | ||
pub fn results(&mut self, num_entries: u32, offset: u32) -> Vec<Entry> { | ||
match self { | ||
TvChannel::Env(channel) => channel.finder.results(num_entries, offset).collect(), | ||
TvChannel::Files(channel) => channel.finder.results(num_entries, offset).collect(), | ||
TvChannel::Grep(channel) => channel.finder.results(num_entries, offset).collect(), | ||
} | ||
} | ||
|
||
pub fn get_result(&self, index: u32) -> Option<Entry> { | ||
match self { | ||
TvChannel::Env(channel) => channel.finder.get_result(index), | ||
TvChannel::Files(channel) => channel.finder.get_result(index), | ||
TvChannel::Grep(channel) => channel.finder.get_result(index), | ||
} | ||
} | ||
|
||
pub fn result_count(&self) -> u32 { | ||
match self { | ||
TvChannel::Env(channel) => channel.finder.result_count(), | ||
TvChannel::Files(channel) => channel.finder.result_count(), | ||
TvChannel::Grep(channel) => channel.finder.result_count(), | ||
} | ||
} | ||
|
||
pub fn total_count(&self) -> u32 { | ||
match self { | ||
TvChannel::Env(channel) => channel.finder.total_count(), | ||
TvChannel::Files(channel) => channel.finder.total_count(), | ||
TvChannel::Grep(channel) => channel.finder.total_count(), | ||
} | ||
} | ||
} | ||
|
||
pub fn get_tv_channel(channel: UnitTvChannel) -> TvChannel { | ||
match channel { | ||
UnitTvChannel::ENV => TvChannel::Env(EnvChannel { | ||
finder: NucleoEnvVarFinder::new(), | ||
finder: EnvVarFinder::new(), | ||
}), | ||
UnitTvChannel::FILES => TvChannel::Files(FilesChannel { | ||
finder: FileFinder::new(), | ||
}), | ||
UnitTvChannel::GREP => TvChannel::Grep(GrepChannel { | ||
finder: GrepFinder::new(), | ||
}), | ||
_ => unimplemented!(), | ||
} | ||
} | ||
|
||
pub struct EnvChannel { | ||
pub finder: NucleoEnvVarFinder, | ||
pub finder: EnvVarFinder, | ||
} | ||
|
||
pub struct FilesChannel { | ||
pub finder: FileFinder, | ||
} | ||
|
||
pub struct GrepChannel { | ||
pub finder: GrepFinder, | ||
} |
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.