mirror of
https://github.com/alexpasmantier/television.git
synced 2025-06-07 20:15:23 +00:00
refactoring: split project into separate crates
This commit is contained in:
parent
f449477605
commit
ae938dcfc0
58
Cargo.lock
generated
58
Cargo.lock
generated
@ -3094,7 +3094,7 @@ dependencies = [
|
|||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "television"
|
name = "television"
|
||||||
version = "0.3.13"
|
version = "0.4.13"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"anyhow",
|
"anyhow",
|
||||||
"bat",
|
"bat",
|
||||||
@ -3126,8 +3126,11 @@ dependencies = [
|
|||||||
"strip-ansi-escapes",
|
"strip-ansi-escapes",
|
||||||
"strum",
|
"strum",
|
||||||
"syntect",
|
"syntect",
|
||||||
|
"television-channels",
|
||||||
"television-derive",
|
"television-derive",
|
||||||
"television-fuzzy",
|
"television-fuzzy",
|
||||||
|
"television-previewers",
|
||||||
|
"television-utils",
|
||||||
"termtree",
|
"termtree",
|
||||||
"tokio",
|
"tokio",
|
||||||
"toml",
|
"toml",
|
||||||
@ -3138,9 +3141,28 @@ dependencies = [
|
|||||||
"vergen-gix",
|
"vergen-gix",
|
||||||
]
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "television-channels"
|
||||||
|
version = "0.0.0"
|
||||||
|
dependencies = [
|
||||||
|
"clap",
|
||||||
|
"color-eyre",
|
||||||
|
"devicons",
|
||||||
|
"directories",
|
||||||
|
"eyre",
|
||||||
|
"ignore",
|
||||||
|
"serde",
|
||||||
|
"strum",
|
||||||
|
"television-derive",
|
||||||
|
"television-fuzzy",
|
||||||
|
"television-utils",
|
||||||
|
"tokio",
|
||||||
|
"tracing",
|
||||||
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "television-derive"
|
name = "television-derive"
|
||||||
version = "0.1.2"
|
version = "0.0.0"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"proc-macro2",
|
"proc-macro2",
|
||||||
"quote",
|
"quote",
|
||||||
@ -3149,12 +3171,42 @@ dependencies = [
|
|||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "television-fuzzy"
|
name = "television-fuzzy"
|
||||||
version = "0.1.1"
|
version = "0.0.0"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"nucleo",
|
"nucleo",
|
||||||
"parking_lot",
|
"parking_lot",
|
||||||
]
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "television-previewers"
|
||||||
|
version = "0.0.0"
|
||||||
|
dependencies = [
|
||||||
|
"color-eyre",
|
||||||
|
"devicons",
|
||||||
|
"infer",
|
||||||
|
"parking_lot",
|
||||||
|
"syntect",
|
||||||
|
"television-channels",
|
||||||
|
"television-utils",
|
||||||
|
"termtree",
|
||||||
|
"tokio",
|
||||||
|
"tracing",
|
||||||
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "television-utils"
|
||||||
|
version = "0.0.0"
|
||||||
|
dependencies = [
|
||||||
|
"bat",
|
||||||
|
"color-eyre",
|
||||||
|
"directories",
|
||||||
|
"ignore",
|
||||||
|
"infer",
|
||||||
|
"lazy_static",
|
||||||
|
"syntect",
|
||||||
|
"tracing",
|
||||||
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "tempfile"
|
name = "tempfile"
|
||||||
version = "3.14.0"
|
version = "3.14.0"
|
||||||
|
11
Cargo.toml
11
Cargo.toml
@ -1,6 +1,6 @@
|
|||||||
[package]
|
[package]
|
||||||
name = "television"
|
name = "television"
|
||||||
version = "0.3.13"
|
version = "0.4.13"
|
||||||
edition = "2021"
|
edition = "2021"
|
||||||
description = "The revolution will be televised."
|
description = "The revolution will be televised."
|
||||||
license = "MIT"
|
license = "MIT"
|
||||||
@ -22,11 +22,14 @@ path = "crates/television/main.rs"
|
|||||||
name = "tv"
|
name = "tv"
|
||||||
|
|
||||||
[workspace]
|
[workspace]
|
||||||
members = ["crates/television_derive", "crates/television_fuzzy"]
|
members = ["crates/television_channels","crates/television_derive", "crates/television_fuzzy", "crates/television_previewers", "crates/television_utils"]
|
||||||
|
|
||||||
[dependencies]
|
[dependencies]
|
||||||
television-fuzzy = { version = "0.1.1", path = "crates/television_fuzzy" }
|
television-fuzzy = { version = "0.0.0", path = "crates/television_fuzzy" }
|
||||||
television-derive = { version = "0.1.2", path = "crates/television_derive" }
|
television-derive = { version = "0.0.0", path = "crates/television_derive" }
|
||||||
|
television-channels = { version = "0.0.0", path = "crates/television_channels" }
|
||||||
|
television-previewers = { version = "0.0.0", path = "crates/television_previewers" }
|
||||||
|
television-utils = { version = "0.0.0", path = "crates/television_utils" }
|
||||||
better-panic = "0.3.0"
|
better-panic = "0.3.0"
|
||||||
clap = { version = "4.4.5", features = [
|
clap = { version = "4.4.5", features = [
|
||||||
"derive",
|
"derive",
|
||||||
|
@ -4,15 +4,15 @@ use color_eyre::Result;
|
|||||||
use tokio::sync::{mpsc, Mutex};
|
use tokio::sync::{mpsc, Mutex};
|
||||||
use tracing::{debug, info};
|
use tracing::{debug, info};
|
||||||
|
|
||||||
use crate::channels::TelevisionChannel;
|
|
||||||
use crate::television::{Mode, Television};
|
use crate::television::{Mode, Television};
|
||||||
use crate::{
|
use crate::{
|
||||||
action::Action,
|
action::Action,
|
||||||
config::Config,
|
config::Config,
|
||||||
entry::Entry,
|
|
||||||
event::{Event, EventLoop, Key},
|
event::{Event, EventLoop, Key},
|
||||||
render::{render, RenderingTask},
|
render::{render, RenderingTask},
|
||||||
};
|
};
|
||||||
|
use television_channels::channels::TelevisionChannel;
|
||||||
|
use television_channels::entry::Entry;
|
||||||
|
|
||||||
/// The main application struct that holds the state of the application.
|
/// The main application struct that holds the state of the application.
|
||||||
pub struct App {
|
pub struct App {
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
use clap::Parser;
|
use clap::Parser;
|
||||||
|
|
||||||
use crate::channels::CliTvChannel;
|
|
||||||
use crate::config::{get_config_dir, get_data_dir};
|
use crate::config::{get_config_dir, get_data_dir};
|
||||||
|
use television_channels::channels::CliTvChannel;
|
||||||
|
|
||||||
#[derive(Parser, Debug)]
|
#[derive(Parser, Debug)]
|
||||||
#[command(author, version = version(), about)]
|
#[command(author, version = version(), about)]
|
||||||
|
@ -1,5 +1,10 @@
|
|||||||
use std::{collections::HashMap, env, num::NonZeroUsize, path::PathBuf};
|
use std::{collections::HashMap, env, path::PathBuf};
|
||||||
|
|
||||||
|
use crate::{
|
||||||
|
action::Action,
|
||||||
|
event::{convert_raw_event_to_key, Key},
|
||||||
|
television::Mode,
|
||||||
|
};
|
||||||
use color_eyre::Result;
|
use color_eyre::Result;
|
||||||
use crossterm::event::{KeyCode, KeyEvent, KeyModifiers};
|
use crossterm::event::{KeyCode, KeyEvent, KeyModifiers};
|
||||||
use derive_deref::{Deref, DerefMut};
|
use derive_deref::{Deref, DerefMut};
|
||||||
@ -7,15 +12,9 @@ use directories::ProjectDirs;
|
|||||||
use lazy_static::lazy_static;
|
use lazy_static::lazy_static;
|
||||||
use ratatui::style::{Color, Modifier, Style};
|
use ratatui::style::{Color, Modifier, Style};
|
||||||
use serde::{de::Deserializer, Deserialize};
|
use serde::{de::Deserializer, Deserialize};
|
||||||
|
use television_previewers::previewers::{self, PreviewerConfig};
|
||||||
use tracing::{info, warn};
|
use tracing::{info, warn};
|
||||||
|
|
||||||
use crate::{
|
|
||||||
action::Action,
|
|
||||||
event::{convert_raw_event_to_key, Key},
|
|
||||||
previewers::{self, PreviewerConfig},
|
|
||||||
television::Mode,
|
|
||||||
};
|
|
||||||
|
|
||||||
const CONFIG: &str = include_str!("../../.config/config.toml");
|
const CONFIG: &str = include_str!("../../.config/config.toml");
|
||||||
|
|
||||||
#[allow(dead_code, clippy::module_name_repetitions)]
|
#[allow(dead_code, clippy::module_name_repetitions)]
|
||||||
@ -373,17 +372,6 @@ pub fn parse_key(raw: &str) -> Result<Key, String> {
|
|||||||
Ok(convert_raw_event_to_key(key_event))
|
Ok(convert_raw_event_to_key(key_event))
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn default_num_threads() -> NonZeroUsize {
|
|
||||||
// default to 1 thread if we can't determine the number of available threads
|
|
||||||
let default = NonZeroUsize::MIN;
|
|
||||||
// never use more than 32 threads to avoid startup overhead
|
|
||||||
let limit = NonZeroUsize::new(32).unwrap();
|
|
||||||
|
|
||||||
std::thread::available_parallelism()
|
|
||||||
.unwrap_or(default)
|
|
||||||
.min(limit)
|
|
||||||
}
|
|
||||||
|
|
||||||
#[derive(Clone, Debug, Default, Deref, DerefMut)]
|
#[derive(Clone, Debug, Default, Deref, DerefMut)]
|
||||||
pub struct Styles(pub HashMap<Mode, HashMap<String, Style>>);
|
pub struct Styles(pub HashMap<Mode, HashMap<String, Style>>);
|
||||||
|
|
||||||
|
@ -1,31 +1,27 @@
|
|||||||
use std::io::{stdout, IsTerminal, Write};
|
use std::io::{stdout, IsTerminal, Write};
|
||||||
|
|
||||||
use channels::TelevisionChannel;
|
|
||||||
use clap::Parser;
|
use clap::Parser;
|
||||||
use color_eyre::Result;
|
use color_eyre::Result;
|
||||||
|
use television_channels::channels::TelevisionChannel;
|
||||||
use tracing::{debug, info};
|
use tracing::{debug, info};
|
||||||
|
|
||||||
use crate::app::App;
|
use crate::app::App;
|
||||||
use crate::channels::stdin::Channel as StdinChannel;
|
|
||||||
use crate::cli::Cli;
|
use crate::cli::Cli;
|
||||||
use crate::utils::is_readable_stdin;
|
use television_channels::channels::stdin::Channel as StdinChannel;
|
||||||
|
use television_utils::utils::is_readable_stdin;
|
||||||
|
|
||||||
pub mod action;
|
pub mod action;
|
||||||
pub mod app;
|
pub mod app;
|
||||||
pub mod channels;
|
|
||||||
pub mod cli;
|
pub mod cli;
|
||||||
pub mod config;
|
pub mod config;
|
||||||
pub mod entry;
|
|
||||||
pub mod errors;
|
pub mod errors;
|
||||||
pub mod event;
|
pub mod event;
|
||||||
pub mod logging;
|
pub mod logging;
|
||||||
pub mod picker;
|
pub mod picker;
|
||||||
pub mod previewers;
|
|
||||||
pub mod render;
|
pub mod render;
|
||||||
pub mod television;
|
pub mod television;
|
||||||
pub mod tui;
|
pub mod tui;
|
||||||
pub mod ui;
|
pub mod ui;
|
||||||
pub mod utils;
|
|
||||||
|
|
||||||
#[tokio::main(flavor = "multi_thread")]
|
#[tokio::main(flavor = "multi_thread")]
|
||||||
async fn main() -> Result<()> {
|
async fn main() -> Result<()> {
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
use crate::ui::input::Input;
|
use crate::ui::input::Input;
|
||||||
use crate::utils::strings::EMPTY_STRING;
|
|
||||||
use ratatui::widgets::ListState;
|
use ratatui::widgets::ListState;
|
||||||
|
use television_utils::utils::strings::EMPTY_STRING;
|
||||||
|
|
||||||
#[derive(Debug)]
|
#[derive(Debug)]
|
||||||
pub struct Picker {
|
pub struct Picker {
|
||||||
|
@ -1,18 +1,9 @@
|
|||||||
use crate::channels::remote_control::RemoteControl;
|
|
||||||
use crate::channels::{OnAir, UnitChannel};
|
|
||||||
use crate::picker::Picker;
|
use crate::picker::Picker;
|
||||||
use crate::previewers;
|
use crate::ui::input::actions::InputActionHandler;
|
||||||
use crate::ui::layout::{Dimensions, Layout};
|
use crate::ui::layout::{Dimensions, Layout};
|
||||||
use crate::utils::strings::EMPTY_STRING;
|
use crate::ui::spinner::Spinner;
|
||||||
|
use crate::ui::spinner::SpinnerState;
|
||||||
use crate::{action::Action, config::Config};
|
use crate::{action::Action, config::Config};
|
||||||
use crate::{
|
|
||||||
channels::TelevisionChannel, ui::input::actions::InputActionHandler,
|
|
||||||
};
|
|
||||||
use crate::{
|
|
||||||
entry::{Entry, ENTRY_PLACEHOLDER},
|
|
||||||
ui::spinner::Spinner,
|
|
||||||
};
|
|
||||||
use crate::{previewers::Previewer, ui::spinner::SpinnerState};
|
|
||||||
use color_eyre::Result;
|
use color_eyre::Result;
|
||||||
use copypasta::{ClipboardContext, ClipboardProvider};
|
use copypasta::{ClipboardContext, ClipboardProvider};
|
||||||
use futures::executor::block_on;
|
use futures::executor::block_on;
|
||||||
@ -20,6 +11,13 @@ use ratatui::{layout::Rect, style::Color, widgets::Paragraph, Frame};
|
|||||||
use serde::{Deserialize, Serialize};
|
use serde::{Deserialize, Serialize};
|
||||||
use std::collections::HashMap;
|
use std::collections::HashMap;
|
||||||
use strum::Display;
|
use strum::Display;
|
||||||
|
use television_channels::channels::{
|
||||||
|
remote_control::RemoteControl, OnAir, TelevisionChannel, UnitChannel,
|
||||||
|
};
|
||||||
|
use television_channels::entry::{Entry, ENTRY_PLACEHOLDER};
|
||||||
|
use television_previewers::previewers;
|
||||||
|
use television_previewers::previewers::Previewer;
|
||||||
|
use television_utils::utils::strings::EMPTY_STRING;
|
||||||
use tokio::sync::mpsc::UnboundedSender;
|
use tokio::sync::mpsc::UnboundedSender;
|
||||||
|
|
||||||
#[derive(
|
#[derive(
|
||||||
|
@ -1,4 +1,3 @@
|
|||||||
use crate::channels::OnAir;
|
|
||||||
use crate::television::Television;
|
use crate::television::Television;
|
||||||
use crate::ui::layout::Layout;
|
use crate::ui::layout::Layout;
|
||||||
use crate::ui::BORDER_COLOR;
|
use crate::ui::BORDER_COLOR;
|
||||||
@ -11,6 +10,7 @@ use ratatui::style::Stylize;
|
|||||||
use ratatui::text::Line;
|
use ratatui::text::Line;
|
||||||
use ratatui::widgets::{Block, BorderType, Borders, Paragraph};
|
use ratatui::widgets::{Block, BorderType, Borders, Paragraph};
|
||||||
use ratatui::Frame;
|
use ratatui::Frame;
|
||||||
|
use television_channels::channels::OnAir;
|
||||||
|
|
||||||
pub mod actions;
|
pub mod actions;
|
||||||
pub mod backend;
|
pub mod backend;
|
||||||
|
@ -1,12 +1,6 @@
|
|||||||
use crate::channels::OnAir;
|
|
||||||
use crate::entry::Entry;
|
|
||||||
use crate::previewers::{
|
|
||||||
Preview, PreviewContent, FILE_TOO_LARGE_MSG, PREVIEW_NOT_SUPPORTED_MSG,
|
|
||||||
};
|
|
||||||
use crate::television::Television;
|
use crate::television::Television;
|
||||||
use crate::ui::layout::Layout;
|
use crate::ui::layout::Layout;
|
||||||
use crate::ui::BORDER_COLOR;
|
use crate::ui::BORDER_COLOR;
|
||||||
use crate::utils::strings::{shrink_with_ellipsis, EMPTY_STRING};
|
|
||||||
use color_eyre::eyre::Result;
|
use color_eyre::eyre::Result;
|
||||||
use ratatui::layout::{Alignment, Rect};
|
use ratatui::layout::{Alignment, Rect};
|
||||||
use ratatui::prelude::{Color, Line, Modifier, Span, Style, Stylize, Text};
|
use ratatui::prelude::{Color, Line, Modifier, Span, Style, Stylize, Text};
|
||||||
@ -15,6 +9,12 @@ use ratatui::Frame;
|
|||||||
use std::str::FromStr;
|
use std::str::FromStr;
|
||||||
use std::sync::Arc;
|
use std::sync::Arc;
|
||||||
use syntect::highlighting::Color as SyntectColor;
|
use syntect::highlighting::Color as SyntectColor;
|
||||||
|
use television_channels::channels::OnAir;
|
||||||
|
use television_channels::entry::Entry;
|
||||||
|
use television_previewers::previewers::{
|
||||||
|
Preview, PreviewContent, FILE_TOO_LARGE_MSG, PREVIEW_NOT_SUPPORTED_MSG,
|
||||||
|
};
|
||||||
|
use television_utils::utils::strings::{shrink_with_ellipsis, EMPTY_STRING};
|
||||||
|
|
||||||
// preview
|
// preview
|
||||||
pub const DEFAULT_PREVIEW_TITLE_FG: Color = Color::Blue;
|
pub const DEFAULT_PREVIEW_TITLE_FG: Color = Color::Blue;
|
||||||
|
@ -1,4 +1,3 @@
|
|||||||
use crate::channels::OnAir;
|
|
||||||
use crate::television::Television;
|
use crate::television::Television;
|
||||||
use crate::ui::logo::build_remote_logo_paragraph;
|
use crate::ui::logo::build_remote_logo_paragraph;
|
||||||
use crate::ui::mode::mode_color;
|
use crate::ui::mode::mode_color;
|
||||||
@ -13,6 +12,7 @@ use ratatui::widgets::{
|
|||||||
Block, BorderType, Borders, ListDirection, Padding, Paragraph,
|
Block, BorderType, Borders, ListDirection, Padding, Paragraph,
|
||||||
};
|
};
|
||||||
use ratatui::Frame;
|
use ratatui::Frame;
|
||||||
|
use television_channels::channels::OnAir;
|
||||||
|
|
||||||
impl Television {
|
impl Television {
|
||||||
pub fn draw_remote_control(
|
pub fn draw_remote_control(
|
||||||
|
@ -1,9 +1,6 @@
|
|||||||
use crate::channels::OnAir;
|
|
||||||
use crate::entry::Entry;
|
|
||||||
use crate::television::Television;
|
use crate::television::Television;
|
||||||
use crate::ui::layout::Layout;
|
use crate::ui::layout::Layout;
|
||||||
use crate::ui::BORDER_COLOR;
|
use crate::ui::BORDER_COLOR;
|
||||||
use crate::utils::strings::{next_char_boundary, slice_at_char_boundaries};
|
|
||||||
use color_eyre::eyre::Result;
|
use color_eyre::eyre::Result;
|
||||||
use ratatui::layout::Alignment;
|
use ratatui::layout::Alignment;
|
||||||
use ratatui::prelude::{Color, Line, Span, Style};
|
use ratatui::prelude::{Color, Line, Span, Style};
|
||||||
@ -12,6 +9,11 @@ use ratatui::widgets::{
|
|||||||
};
|
};
|
||||||
use ratatui::Frame;
|
use ratatui::Frame;
|
||||||
use std::str::FromStr;
|
use std::str::FromStr;
|
||||||
|
use television_channels::channels::OnAir;
|
||||||
|
use television_channels::entry::Entry;
|
||||||
|
use television_utils::utils::strings::{
|
||||||
|
next_char_boundary, slice_at_char_boundaries,
|
||||||
|
};
|
||||||
|
|
||||||
// Styles
|
// Styles
|
||||||
const DEFAULT_RESULT_NAME_FG: Color = Color::Blue;
|
const DEFAULT_RESULT_NAME_FG: Color = Color::Blue;
|
||||||
|
19
crates/television_channels/Cargo.toml
Normal file
19
crates/television_channels/Cargo.toml
Normal file
@ -0,0 +1,19 @@
|
|||||||
|
[package]
|
||||||
|
name = "television-channels"
|
||||||
|
version = "0.0.0"
|
||||||
|
edition = "2021"
|
||||||
|
|
||||||
|
[dependencies]
|
||||||
|
television-fuzzy = { path = "../television_fuzzy", version = "0.0.0" }
|
||||||
|
television-utils = { path = "../television_utils", version = "0.0.0" }
|
||||||
|
television-derive = { path = "../television_derive", version = "0.0.0" }
|
||||||
|
devicons = "0.6.11"
|
||||||
|
tracing = "0.1.40"
|
||||||
|
eyre = "0.6.12"
|
||||||
|
ignore = "0.4.23"
|
||||||
|
tokio = { version = "1.41.1", features = ["rt"] }
|
||||||
|
clap = { version = "4.5.20", features = ["derive"] }
|
||||||
|
directories = "5.0.1"
|
||||||
|
color-eyre = "0.6.3"
|
||||||
|
serde = "1.0.214"
|
||||||
|
strum = { version = "0.26.3", features = ["derive"] }
|
@ -23,7 +23,7 @@ mod text;
|
|||||||
/// return anything and instead typically stores the results internally for
|
/// return anything and instead typically stores the results internally for
|
||||||
/// later retrieval allowing to perform the search in the background while
|
/// later retrieval allowing to perform the search in the background while
|
||||||
/// incrementally polling the results.
|
/// incrementally polling the results.
|
||||||
/// ```rust
|
/// ```ignore
|
||||||
/// fn find(&mut self, pattern: &str);
|
/// fn find(&mut self, pattern: &str);
|
||||||
/// ```
|
/// ```
|
||||||
/// - `results`: Get the results of the search (at a given point in time, see
|
/// - `results`: Get the results of the search (at a given point in time, see
|
||||||
@ -31,20 +31,20 @@ mod text;
|
|||||||
/// search pattern. The `num_entries` parameter specifies the number of
|
/// search pattern. The `num_entries` parameter specifies the number of
|
||||||
/// entries to return and the `offset` parameter specifies the starting index
|
/// entries to return and the `offset` parameter specifies the starting index
|
||||||
/// of the entries to return.
|
/// of the entries to return.
|
||||||
/// ```rust
|
/// ```ignore
|
||||||
/// fn results(&mut self, num_entries: u32, offset: u32) -> Vec<Entry>;
|
/// fn results(&mut self, num_entries: u32, offset: u32) -> Vec<Entry>;
|
||||||
/// ```
|
/// ```
|
||||||
/// - `get_result`: Get a specific result by its index.
|
/// - `get_result`: Get a specific result by its index.
|
||||||
/// ```rust
|
/// ```ignore
|
||||||
/// fn get_result(&self, index: u32) -> Option<Entry>;
|
/// fn get_result(&self, index: u32) -> Option<Entry>;
|
||||||
/// ```
|
/// ```
|
||||||
/// - `result_count`: Get the number of results currently available.
|
/// - `result_count`: Get the number of results currently available.
|
||||||
/// ```rust
|
/// ```ignore
|
||||||
/// fn result_count(&self) -> u32;
|
/// fn result_count(&self) -> u32;
|
||||||
/// ```
|
/// ```
|
||||||
/// - `total_count`: Get the total number of entries currently available (e.g.
|
/// - `total_count`: Get the total number of entries currently available (e.g.
|
||||||
/// the haystack).
|
/// the haystack).
|
||||||
/// ```rust
|
/// ```ignore
|
||||||
/// fn total_count(&self) -> u32;
|
/// fn total_count(&self) -> u32;
|
||||||
/// ```
|
/// ```
|
||||||
///
|
///
|
||||||
@ -195,7 +195,7 @@ macro_rules! variant_to_module {
|
|||||||
/// # Example
|
/// # Example
|
||||||
/// The following example defines transitions from the `Files` channel to the `Text`
|
/// The following example defines transitions from the `Files` channel to the `Text`
|
||||||
/// channel and from the `GitRepos` channel to the `Files` and `Text` channels.
|
/// channel and from the `GitRepos` channel to the `Files` and `Text` channels.
|
||||||
/// ```rust
|
/// ```ignore
|
||||||
/// define_transitions! {
|
/// define_transitions! {
|
||||||
/// // The `Files` channel can transition to the `Text` channel.
|
/// // The `Files` channel can transition to the `Text` channel.
|
||||||
/// Files => [Text],
|
/// Files => [Text],
|
||||||
@ -204,7 +204,7 @@ macro_rules! variant_to_module {
|
|||||||
/// }
|
/// }
|
||||||
/// ```
|
/// ```
|
||||||
/// This will generate the following methods for the `TelevisionChannel` enum:
|
/// This will generate the following methods for the `TelevisionChannel` enum:
|
||||||
/// ```rust
|
/// ```ignore
|
||||||
/// impl TelevisionChannel {
|
/// impl TelevisionChannel {
|
||||||
/// pub fn available_transitions(&self) -> Vec<UnitChannel> {
|
/// pub fn available_transitions(&self) -> Vec<UnitChannel> {
|
||||||
/// match self {
|
/// match self {
|
@ -1,10 +1,10 @@
|
|||||||
use crate::channels::OnAir;
|
use crate::channels::OnAir;
|
||||||
use crate::entry::Entry;
|
use crate::entry::Entry;
|
||||||
use crate::previewers::PreviewType;
|
use crate::entry::PreviewType;
|
||||||
use crate::utils::indices::sep_name_and_value_indices;
|
|
||||||
use crate::utils::strings::preprocess_line;
|
|
||||||
use devicons::FileIcon;
|
use devicons::FileIcon;
|
||||||
use television_fuzzy::matcher::{config::Config, injector::Injector, Matcher};
|
use television_fuzzy::matcher::{config::Config, injector::Injector, Matcher};
|
||||||
|
use television_utils::utils::indices::sep_name_and_value_indices;
|
||||||
|
use television_utils::utils::strings::preprocess_line;
|
||||||
use tracing::debug;
|
use tracing::debug;
|
||||||
|
|
||||||
#[derive(Debug, Clone)]
|
#[derive(Debug, Clone)]
|
@ -1,11 +1,10 @@
|
|||||||
use devicons::FileIcon;
|
use devicons::FileIcon;
|
||||||
|
|
||||||
use super::OnAir;
|
use super::OnAir;
|
||||||
use crate::entry::Entry;
|
use crate::entry::{Entry, PreviewType};
|
||||||
use crate::previewers::PreviewType;
|
|
||||||
use crate::utils::indices::sep_name_and_value_indices;
|
|
||||||
use crate::utils::strings::preprocess_line;
|
|
||||||
use television_fuzzy::matcher::{config::Config, Matcher};
|
use television_fuzzy::matcher::{config::Config, Matcher};
|
||||||
|
use television_utils::utils::indices::sep_name_and_value_indices;
|
||||||
|
use television_utils::utils::strings::preprocess_line;
|
||||||
|
|
||||||
#[derive(Debug, Clone)]
|
#[derive(Debug, Clone)]
|
||||||
struct EnvVar {
|
struct EnvVar {
|
@ -1,12 +1,11 @@
|
|||||||
use crate::channels::{OnAir, TelevisionChannel};
|
use crate::channels::{OnAir, TelevisionChannel};
|
||||||
use crate::entry::Entry;
|
use crate::entry::{Entry, PreviewType};
|
||||||
use crate::previewers::PreviewType;
|
|
||||||
use crate::utils::files::{walk_builder, DEFAULT_NUM_THREADS};
|
|
||||||
use crate::utils::strings::preprocess_line;
|
|
||||||
use devicons::FileIcon;
|
use devicons::FileIcon;
|
||||||
use std::collections::HashSet;
|
use std::collections::HashSet;
|
||||||
use std::path::PathBuf;
|
use std::path::PathBuf;
|
||||||
use television_fuzzy::matcher::{config::Config, injector::Injector, Matcher};
|
use television_fuzzy::matcher::{config::Config, injector::Injector, Matcher};
|
||||||
|
use television_utils::utils::files::{walk_builder, DEFAULT_NUM_THREADS};
|
||||||
|
use television_utils::utils::strings::preprocess_line;
|
||||||
|
|
||||||
pub struct Channel {
|
pub struct Channel {
|
||||||
matcher: Matcher<String>,
|
matcher: Matcher<String>,
|
@ -5,15 +5,11 @@ use std::path::PathBuf;
|
|||||||
use tokio::task::JoinHandle;
|
use tokio::task::JoinHandle;
|
||||||
use tracing::debug;
|
use tracing::debug;
|
||||||
|
|
||||||
use crate::{
|
|
||||||
entry::Entry,
|
|
||||||
previewers::PreviewType,
|
|
||||||
utils::files::{walk_builder, DEFAULT_NUM_THREADS},
|
|
||||||
};
|
|
||||||
|
|
||||||
use crate::channels::OnAir;
|
use crate::channels::OnAir;
|
||||||
use crate::utils::strings::preprocess_line;
|
use crate::entry::{Entry, PreviewType};
|
||||||
use television_fuzzy::matcher::{config::Config, injector::Injector, Matcher};
|
use television_fuzzy::matcher::{config::Config, injector::Injector, Matcher};
|
||||||
|
use television_utils::utils::files::{walk_builder, DEFAULT_NUM_THREADS};
|
||||||
|
use television_utils::utils::strings::preprocess_line;
|
||||||
|
|
||||||
pub struct Channel {
|
pub struct Channel {
|
||||||
matcher: Matcher<String>,
|
matcher: Matcher<String>,
|
@ -1,9 +1,5 @@
|
|||||||
use crate::channels::{TelevisionChannel, UnitChannel};
|
use crate::channels::{CliTvChannel, OnAir, TelevisionChannel, UnitChannel};
|
||||||
use crate::{
|
use crate::entry::{Entry, PreviewType};
|
||||||
channels::{CliTvChannel, OnAir},
|
|
||||||
entry::Entry,
|
|
||||||
previewers::PreviewType,
|
|
||||||
};
|
|
||||||
use clap::ValueEnum;
|
use clap::ValueEnum;
|
||||||
use devicons::FileIcon;
|
use devicons::FileIcon;
|
||||||
use television_fuzzy::matcher::{config::Config, Matcher};
|
use television_fuzzy::matcher::{config::Config, Matcher};
|
@ -4,10 +4,9 @@ use std::path::Path;
|
|||||||
use devicons::FileIcon;
|
use devicons::FileIcon;
|
||||||
|
|
||||||
use super::OnAir;
|
use super::OnAir;
|
||||||
use crate::entry::Entry;
|
use crate::entry::{Entry, PreviewType};
|
||||||
use crate::previewers::PreviewType;
|
|
||||||
use crate::utils::strings::preprocess_line;
|
|
||||||
use television_fuzzy::matcher::{config::Config, Matcher};
|
use television_fuzzy::matcher::{config::Config, Matcher};
|
||||||
|
use television_utils::utils::strings::preprocess_line;
|
||||||
|
|
||||||
pub struct Channel {
|
pub struct Channel {
|
||||||
matcher: Matcher<String>,
|
matcher: Matcher<String>,
|
@ -1,13 +1,5 @@
|
|||||||
use super::{OnAir, TelevisionChannel};
|
use super::{OnAir, TelevisionChannel};
|
||||||
use crate::previewers::PreviewType;
|
use crate::entry::{Entry, PreviewType};
|
||||||
use crate::utils::strings::PRINTABLE_ASCII_THRESHOLD;
|
|
||||||
use crate::utils::{
|
|
||||||
files::{is_not_text, walk_builder, DEFAULT_NUM_THREADS},
|
|
||||||
strings::preprocess_line,
|
|
||||||
};
|
|
||||||
use crate::{
|
|
||||||
entry::Entry, utils::strings::proportion_of_printable_ascii_characters,
|
|
||||||
};
|
|
||||||
use devicons::FileIcon;
|
use devicons::FileIcon;
|
||||||
use ignore::WalkState;
|
use ignore::WalkState;
|
||||||
use std::{
|
use std::{
|
||||||
@ -17,6 +9,13 @@ use std::{
|
|||||||
sync::{atomic::AtomicUsize, Arc},
|
sync::{atomic::AtomicUsize, Arc},
|
||||||
};
|
};
|
||||||
use television_fuzzy::matcher::{config::Config, injector::Injector, Matcher};
|
use television_fuzzy::matcher::{config::Config, injector::Injector, Matcher};
|
||||||
|
use television_utils::utils::strings::{
|
||||||
|
proportion_of_printable_ascii_characters, PRINTABLE_ASCII_THRESHOLD,
|
||||||
|
};
|
||||||
|
use television_utils::utils::{
|
||||||
|
files::{is_not_text, walk_builder, DEFAULT_NUM_THREADS},
|
||||||
|
strings::preprocess_line,
|
||||||
|
};
|
||||||
use tracing::{debug, warn};
|
use tracing::{debug, warn};
|
||||||
|
|
||||||
#[derive(Debug, Clone)]
|
#[derive(Debug, Clone)]
|
@ -1,7 +1,5 @@
|
|||||||
use devicons::FileIcon;
|
use devicons::FileIcon;
|
||||||
|
|
||||||
use crate::previewers::PreviewType;
|
|
||||||
|
|
||||||
// NOTE: having an enum for entry types would be nice since it would allow
|
// NOTE: having an enum for entry types would be nice since it would allow
|
||||||
// having a nicer implementation for transitions between channels. This would
|
// having a nicer implementation for transitions between channels. This would
|
||||||
// permit implementing `From<EntryType>` for channels which would make the
|
// permit implementing `From<EntryType>` for channels which would make the
|
||||||
@ -127,3 +125,12 @@ pub const ENTRY_PLACEHOLDER: Entry = Entry {
|
|||||||
line_number: None,
|
line_number: None,
|
||||||
preview_type: PreviewType::EnvVar,
|
preview_type: PreviewType::EnvVar,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
#[derive(Debug, Clone, Eq, PartialEq, Hash, Default)]
|
||||||
|
pub enum PreviewType {
|
||||||
|
#[default]
|
||||||
|
Basic,
|
||||||
|
Directory,
|
||||||
|
EnvVar,
|
||||||
|
Files,
|
||||||
|
}
|
17
crates/television_channels/src/lib.rs
Normal file
17
crates/television_channels/src/lib.rs
Normal file
@ -0,0 +1,17 @@
|
|||||||
|
pub mod channels;
|
||||||
|
pub mod entry;
|
||||||
|
|
||||||
|
pub fn add(left: u64, right: u64) -> u64 {
|
||||||
|
left + right
|
||||||
|
}
|
||||||
|
|
||||||
|
#[cfg(test)]
|
||||||
|
mod tests {
|
||||||
|
use super::*;
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn it_works() {
|
||||||
|
let result = add(2, 2);
|
||||||
|
assert_eq!(result, 4);
|
||||||
|
}
|
||||||
|
}
|
@ -1,6 +1,6 @@
|
|||||||
[package]
|
[package]
|
||||||
name = "television-derive"
|
name = "television-derive"
|
||||||
version = "0.1.2"
|
version = "0.0.0"
|
||||||
edition = "2021"
|
edition = "2021"
|
||||||
description = "The revolution will be televised."
|
description = "The revolution will be televised."
|
||||||
license = "MIT"
|
license = "MIT"
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
[package]
|
[package]
|
||||||
name = "television-fuzzy"
|
name = "television-fuzzy"
|
||||||
version = "0.1.1"
|
version = "0.0.0"
|
||||||
edition = "2021"
|
edition = "2021"
|
||||||
description = "The revolution will be televised."
|
description = "The revolution will be televised."
|
||||||
license = "MIT"
|
license = "MIT"
|
||||||
@ -16,4 +16,4 @@ categories = [
|
|||||||
|
|
||||||
[dependencies]
|
[dependencies]
|
||||||
nucleo = "0.5.0"
|
nucleo = "0.5.0"
|
||||||
parking_lot = "0.12.3"
|
parking_lot = "0.12.3"
|
16
crates/television_previewers/Cargo.toml
Normal file
16
crates/television_previewers/Cargo.toml
Normal file
@ -0,0 +1,16 @@
|
|||||||
|
[package]
|
||||||
|
name = "television-previewers"
|
||||||
|
version = "0.0.0"
|
||||||
|
edition = "2021"
|
||||||
|
|
||||||
|
[dependencies]
|
||||||
|
syntect = "5.2.0"
|
||||||
|
television-channels = { version = "0.0.0", path = "../television_channels" }
|
||||||
|
television-utils = { version = "0.0.0", path = "../television_utils" }
|
||||||
|
tracing = "0.1.40"
|
||||||
|
parking_lot = "0.12.3"
|
||||||
|
tokio = "1.41.1"
|
||||||
|
termtree = "0.5.1"
|
||||||
|
devicons = "0.6.11"
|
||||||
|
color-eyre = "0.6.3"
|
||||||
|
infer = "0.16.0"
|
1
crates/television_previewers/src/lib.rs
Normal file
1
crates/television_previewers/src/lib.rs
Normal file
@ -0,0 +1 @@
|
|||||||
|
pub mod previewers;
|
@ -1,13 +1,13 @@
|
|||||||
use std::sync::Arc;
|
use std::sync::Arc;
|
||||||
|
|
||||||
use crate::entry::Entry;
|
use television_channels::entry::{Entry, PreviewType};
|
||||||
|
|
||||||
mod basic;
|
pub mod basic;
|
||||||
mod cache;
|
pub mod cache;
|
||||||
mod directory;
|
pub mod directory;
|
||||||
mod env;
|
pub mod env;
|
||||||
mod files;
|
pub mod files;
|
||||||
mod meta;
|
pub mod meta;
|
||||||
|
|
||||||
// previewer types
|
// previewer types
|
||||||
pub use basic::BasicPreviewer;
|
pub use basic::BasicPreviewer;
|
||||||
@ -21,15 +21,6 @@ pub use files::FilePreviewerConfig;
|
|||||||
//use ratatui_image::protocol::StatefulProtocol;
|
//use ratatui_image::protocol::StatefulProtocol;
|
||||||
use syntect::highlighting::Style;
|
use syntect::highlighting::Style;
|
||||||
|
|
||||||
#[derive(Debug, Clone, Eq, PartialEq, Hash, Default)]
|
|
||||||
pub enum PreviewType {
|
|
||||||
#[default]
|
|
||||||
Basic,
|
|
||||||
Directory,
|
|
||||||
EnvVar,
|
|
||||||
Files,
|
|
||||||
}
|
|
||||||
|
|
||||||
#[derive(Clone, Debug)]
|
#[derive(Clone, Debug)]
|
||||||
pub enum PreviewContent {
|
pub enum PreviewContent {
|
||||||
Empty,
|
Empty,
|
@ -1,7 +1,7 @@
|
|||||||
use std::sync::Arc;
|
use std::sync::Arc;
|
||||||
|
|
||||||
use crate::entry::Entry;
|
|
||||||
use crate::previewers::{Preview, PreviewContent};
|
use crate::previewers::{Preview, PreviewContent};
|
||||||
|
use television_channels::entry::Entry;
|
||||||
|
|
||||||
#[derive(Debug, Default)]
|
#[derive(Debug, Default)]
|
||||||
pub struct BasicPreviewer {
|
pub struct BasicPreviewer {
|
@ -16,6 +16,8 @@ use crate::previewers::Preview;
|
|||||||
///
|
///
|
||||||
/// # Example
|
/// # Example
|
||||||
/// ```rust
|
/// ```rust
|
||||||
|
/// use television_previewers::previewers::cache::RingSet;
|
||||||
|
///
|
||||||
/// let mut ring_set = RingSet::with_capacity(3);
|
/// let mut ring_set = RingSet::with_capacity(3);
|
||||||
/// // push 3 values into the ringset
|
/// // push 3 values into the ringset
|
||||||
/// assert_eq!(ring_set.push(1), None);
|
/// assert_eq!(ring_set.push(1), None);
|
||||||
@ -45,7 +47,7 @@ use crate::previewers::Preview;
|
|||||||
/// assert!(ring_set.contains(&4));
|
/// assert!(ring_set.contains(&4));
|
||||||
/// ```
|
/// ```
|
||||||
#[derive(Debug)]
|
#[derive(Debug)]
|
||||||
struct RingSet<T> {
|
pub struct RingSet<T> {
|
||||||
ring_buffer: VecDeque<T>,
|
ring_buffer: VecDeque<T>,
|
||||||
known_keys: HashSet<T>,
|
known_keys: HashSet<T>,
|
||||||
capacity: usize,
|
capacity: usize,
|
||||||
@ -94,7 +96,7 @@ where
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn contains(&self, key: &T) -> bool {
|
pub fn contains(&self, key: &T) -> bool {
|
||||||
self.known_keys.contains(key)
|
self.known_keys.contains(key)
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -5,11 +5,11 @@ use devicons::FileIcon;
|
|||||||
use parking_lot::Mutex;
|
use parking_lot::Mutex;
|
||||||
use termtree::Tree;
|
use termtree::Tree;
|
||||||
|
|
||||||
use crate::entry::Entry;
|
use television_channels::entry::Entry;
|
||||||
|
|
||||||
use crate::previewers::cache::PreviewCache;
|
use crate::previewers::cache::PreviewCache;
|
||||||
use crate::previewers::{meta, Preview, PreviewContent};
|
use crate::previewers::{meta, Preview, PreviewContent};
|
||||||
use crate::utils::files::walk_builder;
|
use television_utils::utils::files::walk_builder;
|
||||||
|
|
||||||
#[derive(Debug, Default)]
|
#[derive(Debug, Default)]
|
||||||
pub struct DirectoryPreviewer {
|
pub struct DirectoryPreviewer {
|
@ -1,8 +1,8 @@
|
|||||||
use std::collections::HashMap;
|
use std::collections::HashMap;
|
||||||
use std::sync::Arc;
|
use std::sync::Arc;
|
||||||
|
|
||||||
use crate::entry;
|
|
||||||
use crate::previewers::{Preview, PreviewContent};
|
use crate::previewers::{Preview, PreviewContent};
|
||||||
|
use television_channels::entry;
|
||||||
|
|
||||||
#[derive(Debug, Default)]
|
#[derive(Debug, Default)]
|
||||||
pub struct EnvVarPreviewer {
|
pub struct EnvVarPreviewer {
|
@ -14,15 +14,15 @@ use syntect::{
|
|||||||
use tracing::{debug, warn};
|
use tracing::{debug, warn};
|
||||||
|
|
||||||
use super::cache::PreviewCache;
|
use super::cache::PreviewCache;
|
||||||
use crate::entry;
|
|
||||||
use crate::previewers::{meta, Preview, PreviewContent};
|
use crate::previewers::{meta, Preview, PreviewContent};
|
||||||
use crate::utils::files::FileType;
|
use television_channels::entry;
|
||||||
use crate::utils::files::{get_file_size, is_known_text_extension};
|
use television_utils::utils::files::FileType;
|
||||||
use crate::utils::strings::{
|
use television_utils::utils::files::{get_file_size, is_known_text_extension};
|
||||||
|
use television_utils::utils::strings::{
|
||||||
preprocess_line, proportion_of_printable_ascii_characters,
|
preprocess_line, proportion_of_printable_ascii_characters,
|
||||||
PRINTABLE_ASCII_THRESHOLD,
|
PRINTABLE_ASCII_THRESHOLD,
|
||||||
};
|
};
|
||||||
use crate::utils::syntax::{self, load_highlighting_assets};
|
use television_utils::utils::syntax::{self, load_highlighting_assets};
|
||||||
|
|
||||||
#[derive(Debug, Default)]
|
#[derive(Debug, Default)]
|
||||||
pub struct FilePreviewer {
|
pub struct FilePreviewer {
|
14
crates/television_utils/Cargo.toml
Normal file
14
crates/television_utils/Cargo.toml
Normal file
@ -0,0 +1,14 @@
|
|||||||
|
[package]
|
||||||
|
name = "television-utils"
|
||||||
|
version = "0.0.0"
|
||||||
|
edition = "2021"
|
||||||
|
|
||||||
|
[dependencies]
|
||||||
|
ignore = "0.4.23"
|
||||||
|
infer = "0.16.0"
|
||||||
|
lazy_static = "1.5.0"
|
||||||
|
tracing = "0.1.40"
|
||||||
|
color-eyre = "0.6.3"
|
||||||
|
bat = "0.24.0"
|
||||||
|
directories = "5.0.1"
|
||||||
|
syntect = "5.2.0"
|
1
crates/television_utils/src/lib.rs
Normal file
1
crates/television_utils/src/lib.rs
Normal file
@ -0,0 +1 @@
|
|||||||
|
pub mod utils;
|
@ -1,3 +1,5 @@
|
|||||||
|
use std::num::NonZeroUsize;
|
||||||
|
|
||||||
pub mod files;
|
pub mod files;
|
||||||
pub mod indices;
|
pub mod indices;
|
||||||
pub mod strings;
|
pub mod strings;
|
||||||
@ -64,3 +66,19 @@ pub fn is_readable_stdin() -> bool {
|
|||||||
|
|
||||||
!std::io::stdin().is_terminal() && imp()
|
!std::io::stdin().is_terminal() && imp()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Get the number of threads to use by default.
|
||||||
|
///
|
||||||
|
/// This will use the number of available threads if possible, but will default to 1 if the number
|
||||||
|
/// of available threads cannot be determined. It will also never use more than 32 threads to avoid
|
||||||
|
/// startup overhead.
|
||||||
|
pub fn default_num_threads() -> NonZeroUsize {
|
||||||
|
// default to 1 thread if we can't determine the number of available threads
|
||||||
|
let default = NonZeroUsize::MIN;
|
||||||
|
// never use more than 32 threads to avoid startup overhead
|
||||||
|
let limit = NonZeroUsize::new(32).unwrap();
|
||||||
|
|
||||||
|
std::thread::available_parallelism()
|
||||||
|
.unwrap_or(default)
|
||||||
|
.min(limit)
|
||||||
|
}
|
@ -6,7 +6,7 @@ use infer::Infer;
|
|||||||
use lazy_static::lazy_static;
|
use lazy_static::lazy_static;
|
||||||
use tracing::debug;
|
use tracing::debug;
|
||||||
|
|
||||||
use crate::config::default_num_threads;
|
use crate::utils::default_num_threads;
|
||||||
|
|
||||||
lazy_static::lazy_static! {
|
lazy_static::lazy_static! {
|
||||||
pub static ref DEFAULT_NUM_THREADS: usize = default_num_threads().into();
|
pub static ref DEFAULT_NUM_THREADS: usize = default_num_threads().into();
|
Loading…
x
Reference in New Issue
Block a user