mirror of
https://github.com/alexpasmantier/television.git
synced 2025-06-06 03:25:23 +00:00
refactor(channels): converting between entries and channels is now generic over channels (#25)
This commit is contained in:
parent
f47b8be9de
commit
4f0daec63d
@ -1,5 +1,4 @@
|
||||
use crate::entry::Entry;
|
||||
use color_eyre::eyre::Result;
|
||||
use television_derive::{Broadcast, ToCliChannel, ToUnitChannel};
|
||||
|
||||
mod alias;
|
||||
@ -140,22 +139,9 @@ pub enum TelevisionChannel {
|
||||
RemoteControl(remote_control::RemoteControl),
|
||||
}
|
||||
|
||||
/// NOTE: this could/should be generated by a macro
|
||||
impl TryFrom<&Entry> for TelevisionChannel {
|
||||
type Error = String;
|
||||
|
||||
fn try_from(entry: &Entry) -> Result<Self, Self::Error> {
|
||||
match entry.name.to_ascii_lowercase().as_ref() {
|
||||
"env" => Ok(TelevisionChannel::Env(env::Channel::default())),
|
||||
"files" => Ok(TelevisionChannel::Files(files::Channel::default())),
|
||||
"gitrepos" => {
|
||||
Ok(TelevisionChannel::GitRepos(git_repos::Channel::default()))
|
||||
}
|
||||
"text" => Ok(TelevisionChannel::Text(text::Channel::default())),
|
||||
"stdin" => Ok(TelevisionChannel::Stdin(stdin::Channel::default())),
|
||||
"alias" => Ok(TelevisionChannel::Alias(alias::Channel::default())),
|
||||
_ => Err(format!("Unknown channel: {}", entry.name)),
|
||||
}
|
||||
impl From<&Entry> for TelevisionChannel {
|
||||
fn from(entry: &Entry) -> Self {
|
||||
UnitChannel::from(entry.name.as_str()).into()
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -312,17 +312,14 @@ impl Television {
|
||||
.unwrap()
|
||||
.send(Action::SelectAndExit)?,
|
||||
Mode::RemoteControl => {
|
||||
if let Ok(new_channel) =
|
||||
// FIXME: this is kind of shitty
|
||||
TelevisionChannel::try_from(&entry)
|
||||
{
|
||||
// this resets the RC picker
|
||||
self.reset_picker_selection();
|
||||
self.reset_picker_input();
|
||||
self.remote_control.find(EMPTY_STRING);
|
||||
self.mode = Mode::Channel;
|
||||
self.change_channel(new_channel);
|
||||
}
|
||||
// FIXME: this is kind of shitty
|
||||
let new_channel = TelevisionChannel::from(&entry);
|
||||
// this resets the RC picker
|
||||
self.reset_picker_selection();
|
||||
self.reset_picker_input();
|
||||
self.remote_control.find(EMPTY_STRING);
|
||||
self.mode = Mode::Channel;
|
||||
self.change_channel(new_channel);
|
||||
}
|
||||
Mode::SendToChannel => {
|
||||
let new_channel = self
|
||||
|
Loading…
x
Reference in New Issue
Block a user