refactor(channels): some renaming and refactoring the channels module (#503)

This commit is contained in:
Alexandre Pasmantier 2025-05-11 17:00:31 +02:00 committed by GitHub
parent cd33151bac
commit 1a5fa5dd4c
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
13 changed files with 51 additions and 44 deletions

View File

@ -8,12 +8,11 @@ use ratatui::prelude::{Line, Style};
use ratatui::style::Color; use ratatui::style::Color;
use ratatui::widgets::{Block, BorderType, Borders, ListDirection, Padding}; use ratatui::widgets::{Block, BorderType, Borders, ListDirection, Padding};
use ratatui::Terminal; use ratatui::Terminal;
use television::channels::cable::prototypes::Cable;
use television::{ use television::{
action::Action, action::Action,
channels::{ channels::{
cable::prototypes::ChannelPrototype,
entry::{into_ranges, Entry}, entry::{into_ranges, Entry},
prototypes::{Cable, ChannelPrototype},
}, },
config::{Config, ConfigEnv}, config::{Config, ConfigEnv},
screen::{colors::ResultsColorscheme, results::build_results_list}, screen::{colors::ResultsColorscheme, results::build_results_list},

View File

@ -4,16 +4,17 @@ use anyhow::Result;
use tokio::sync::mpsc; use tokio::sync::mpsc;
use tracing::{debug, trace}; use tracing::{debug, trace};
use crate::channels::cable::prototypes::{Cable, ChannelPrototype};
use crate::channels::entry::Entry;
use crate::config::{default_tick_rate, Config};
use crate::keymap::Keymap;
use crate::render::UiState;
use crate::television::{Mode, Television};
use crate::{ use crate::{
action::Action, action::Action,
channels::{
entry::Entry,
prototypes::{Cable, ChannelPrototype},
},
config::{default_tick_rate, Config},
event::{Event, EventLoop, Key}, event::{Event, EventLoop, Key},
render::{render, RenderingTask}, keymap::Keymap,
render::{render, RenderingTask, UiState},
television::{Mode, Television},
}; };
#[allow(clippy::struct_excessive_bools)] #[allow(clippy::struct_excessive_bools)]

View File

@ -6,7 +6,7 @@ use anyhow::Result;
use tracing::{debug, error}; use tracing::{debug, error};
use crate::{ use crate::{
channels::cable::prototypes::{Cable, ChannelPrototype}, channels::prototypes::{Cable, ChannelPrototype},
config::get_config_dir, config::get_config_dir,
}; };

View File

@ -2,17 +2,18 @@ use std::collections::HashSet;
use std::io::{BufRead, BufReader}; use std::io::{BufRead, BufReader};
use std::process::Stdio; use std::process::Stdio;
use prototypes::{ChannelPrototype, DEFAULT_DELIMITER};
use rustc_hash::{FxBuildHasher, FxHashSet}; use rustc_hash::{FxBuildHasher, FxHashSet};
use tracing::debug; use tracing::debug;
use crate::channels::{entry::Entry, preview::PreviewCommand}; use crate::channels::{
entry::Entry,
preview::PreviewCommand,
prototypes::{ChannelPrototype, DEFAULT_DELIMITER},
};
use crate::matcher::Matcher; use crate::matcher::Matcher;
use crate::matcher::{config::Config, injector::Injector}; use crate::matcher::{config::Config, injector::Injector};
use crate::utils::command::shell_command; use crate::utils::command::shell_command;
pub mod prototypes;
#[allow(dead_code)] #[allow(dead_code)]
pub struct Channel { pub struct Channel {
pub name: String, pub name: String,

View File

@ -1,4 +1,5 @@
pub mod cable; pub mod cable;
pub mod entry; pub mod entry;
pub mod preview; pub mod preview;
pub mod prototypes;
pub mod remote_control; pub mod remote_control;

View File

@ -1,7 +1,9 @@
use std::fmt::Display; use std::fmt::Display;
use super::{cable::prototypes::DEFAULT_DELIMITER, entry::Entry}; use crate::channels::{
use crate::channels::cable::prototypes::ChannelPrototype; entry::Entry,
prototypes::{ChannelPrototype, DEFAULT_DELIMITER},
};
use lazy_regex::{regex, Lazy, Regex}; use lazy_regex::{regex, Lazy, Regex};
use tracing::debug; use tracing::debug;

View File

@ -6,7 +6,7 @@ use std::{
use crate::{cable::CableSpec, channels::preview::PreviewCommand}; use crate::{cable::CableSpec, channels::preview::PreviewCommand};
/// A prototype for a cable channel. /// A prototype for cable channels.
/// ///
/// This can be seen as a cable channel specification, which is used to /// This can be seen as a cable channel specification, which is used to
/// create a cable channel. /// create a cable channel.
@ -122,7 +122,7 @@ impl Display for ChannelPrototype {
} }
} }
/// A neat `HashMap` of cable channel prototypes indexed by their name. /// A neat `HashMap` of channel prototypes indexed by their name.
/// ///
/// This is used to store cable channel prototypes throughout the application /// This is used to store cable channel prototypes throughout the application
/// in a way that facilitates answering questions like "what's the prototype /// in a way that facilitates answering questions like "what's the prototype
@ -142,12 +142,12 @@ impl Deref for Cable {
/// application. /// application.
#[cfg(unix)] #[cfg(unix)]
const DEFAULT_CABLE_CHANNELS_FILE: &str = const DEFAULT_CABLE_CHANNELS_FILE: &str =
include_str!("../../../cable/unix-channels.toml"); include_str!("../../cable/unix-channels.toml");
/// A default cable channels specification that is compiled into the /// A default cable channels specification that is compiled into the
/// application. /// application.
#[cfg(not(unix))] #[cfg(not(unix))]
const DEFAULT_CABLE_CHANNELS_FILE: &str = const DEFAULT_CABLE_CHANNELS_FILE: &str =
include_str!("../../../cable/windows-channels.toml"); include_str!("../../cable/windows-channels.toml");
impl Default for Cable { impl Default for Cable {
/// Fallback to the default cable channels specification (the template file /// Fallback to the default cable channels specification (the template file

View File

@ -1,11 +1,13 @@
use crate::channels::cable::prototypes::Cable; use crate::{
use crate::channels::entry::Entry; channels::{
use crate::matcher::{config::Config, Matcher}; entry::Entry,
prototypes::{Cable, ChannelPrototype},
},
matcher::{config::Config, Matcher},
};
use anyhow::Result; use anyhow::Result;
use devicons::FileIcon; use devicons::FileIcon;
use super::cable::prototypes::ChannelPrototype;
pub struct RemoteControl { pub struct RemoteControl {
matcher: Matcher<String>, matcher: Matcher<String>,
cable_channels: Option<Cable>, cable_channels: Option<Cable>,

View File

@ -4,13 +4,14 @@ use std::path::Path;
use anyhow::{anyhow, Result}; use anyhow::{anyhow, Result};
use tracing::debug; use tracing::debug;
use crate::channels::cable::prototypes::{Cable, ChannelPrototype};
use crate::channels::preview::PreviewCommand;
use crate::cli::args::{Cli, Command};
use crate::config::{KeyBindings, DEFAULT_CHANNEL};
use crate::{ use crate::{
cable, cable,
config::{get_config_dir, get_data_dir}, channels::{
preview::PreviewCommand,
prototypes::{Cable, ChannelPrototype},
},
cli::args::{Cli, Command},
config::{get_config_dir, get_data_dir, KeyBindings, DEFAULT_CHANNEL},
}; };
pub mod args; pub mod args;

View File

@ -5,9 +5,11 @@ use std::process::exit;
use anyhow::Result; use anyhow::Result;
use clap::Parser; use clap::Parser;
use television::cable; use television::{
use television::channels::cable::prototypes::{Cable, ChannelPrototype}; cable,
use television::utils::clipboard::CLIPBOARD; channels::prototypes::{Cable, ChannelPrototype},
utils::clipboard::CLIPBOARD,
};
use tracing::{debug, error, info}; use tracing::{debug, error, info};
use television::app::{App, AppOptions}; use television::app::{App, AppOptions};
@ -177,7 +179,7 @@ pub fn determine_channel(
mod tests { mod tests {
use rustc_hash::FxHashMap; use rustc_hash::FxHashMap;
use television::{ use television::{
cable::load_cable, channels::cable::prototypes::ChannelPrototype, cable::load_cable, channels::prototypes::ChannelPrototype,
}; };
use super::*; use super::*;

View File

@ -1,9 +1,9 @@
use crate::channels::cable::prototypes::ChannelPrototype;
use crate::preview::{Preview, PreviewContent};
use crate::utils::command::shell_command;
use crate::{ use crate::{
channels::{entry::Entry, preview::PreviewCommand}, channels::{
preview::cache::PreviewCache, entry::Entry, preview::PreviewCommand, prototypes::ChannelPrototype,
},
preview::{cache::PreviewCache, Preview, PreviewContent},
utils::command::shell_command,
}; };
use parking_lot::Mutex; use parking_lot::Mutex;
use rustc_hash::FxHashSet; use rustc_hash::FxHashSet;

View File

@ -1,11 +1,9 @@
use crate::{ use crate::{
action::Action, action::Action,
channels::{ channels::{
cable::{ cable::Channel as CableChannel,
prototypes::{Cable, ChannelPrototype},
Channel as CableChannel,
},
entry::Entry, entry::Entry,
prototypes::{Cable, ChannelPrototype},
remote_control::RemoteControl, remote_control::RemoteControl,
}, },
config::{Config, Theme}, config::{Config, Theme},

View File

@ -3,7 +3,7 @@ use std::{collections::HashSet, path::PathBuf, time::Duration};
use television::{ use television::{
action::Action, action::Action,
app::{App, AppOptions}, app::{App, AppOptions},
channels::cable::prototypes::{Cable, ChannelPrototype}, channels::prototypes::{Cable, ChannelPrototype},
config::default_config_from_file, config::default_config_from_file,
}; };
use tokio::{task::JoinHandle, time::timeout}; use tokio::{task::JoinHandle, time::timeout};