mirror of
https://github.com/alexpasmantier/television.git
synced 2025-06-07 03:55:23 +00:00
refactor(ui): display current channel in input bar border (#354)
<img width="860" alt="Screenshot 2025-02-08 at 13 38 42" src="https://github.com/user-attachments/assets/ab1558a9-75f6-4006-be2b-9a78dc56b44f" />
This commit is contained in:
parent
b706dcb8dd
commit
86c100e381
@ -29,7 +29,7 @@ enum PreviewKind {
|
|||||||
|
|
||||||
#[allow(dead_code)]
|
#[allow(dead_code)]
|
||||||
pub struct Channel {
|
pub struct Channel {
|
||||||
name: String,
|
pub name: String,
|
||||||
matcher: Matcher<String>,
|
matcher: Matcher<String>,
|
||||||
entries_command: String,
|
entries_command: String,
|
||||||
preview_kind: PreviewKind,
|
preview_kind: PreviewKind,
|
||||||
|
@ -174,6 +174,14 @@ impl TelevisionChannel {
|
|||||||
_ => unreachable!(),
|
_ => unreachable!(),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub fn name(&self) -> String {
|
||||||
|
match self {
|
||||||
|
TelevisionChannel::Cable(channel) => channel.name.clone(),
|
||||||
|
TelevisionChannel::Stdin(_) => String::from("Stdin"),
|
||||||
|
_ => UnitChannel::from(self).to_string(),
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
macro_rules! variant_to_module {
|
macro_rules! variant_to_module {
|
||||||
|
@ -7,10 +7,7 @@ use tokio::sync::mpsc::Sender;
|
|||||||
|
|
||||||
use crate::{
|
use crate::{
|
||||||
action::Action,
|
action::Action,
|
||||||
channels::{
|
channels::entry::{Entry, PreviewType, ENTRY_PLACEHOLDER},
|
||||||
entry::{Entry, PreviewType, ENTRY_PLACEHOLDER},
|
|
||||||
UnitChannel,
|
|
||||||
},
|
|
||||||
config::Config,
|
config::Config,
|
||||||
picker::Picker,
|
picker::Picker,
|
||||||
preview::PreviewState,
|
preview::PreviewState,
|
||||||
@ -27,7 +24,7 @@ use crate::{
|
|||||||
|
|
||||||
#[derive(Debug, Clone, PartialEq)]
|
#[derive(Debug, Clone, PartialEq)]
|
||||||
pub struct ChannelState {
|
pub struct ChannelState {
|
||||||
pub current_channel: UnitChannel,
|
pub current_channel_name: String,
|
||||||
pub selected_entries: FxHashSet<Entry>,
|
pub selected_entries: FxHashSet<Entry>,
|
||||||
pub total_count: u32,
|
pub total_count: u32,
|
||||||
pub running: bool,
|
pub running: bool,
|
||||||
@ -35,13 +32,13 @@ pub struct ChannelState {
|
|||||||
|
|
||||||
impl ChannelState {
|
impl ChannelState {
|
||||||
pub fn new(
|
pub fn new(
|
||||||
current_channel: UnitChannel,
|
current_channel_name: String,
|
||||||
selected_entries: FxHashSet<Entry>,
|
selected_entries: FxHashSet<Entry>,
|
||||||
total_count: u32,
|
total_count: u32,
|
||||||
running: bool,
|
running: bool,
|
||||||
) -> Self {
|
) -> Self {
|
||||||
Self {
|
Self {
|
||||||
current_channel,
|
current_channel_name,
|
||||||
selected_entries,
|
selected_entries,
|
||||||
total_count,
|
total_count,
|
||||||
running,
|
running,
|
||||||
@ -51,7 +48,7 @@ impl ChannelState {
|
|||||||
|
|
||||||
impl Hash for ChannelState {
|
impl Hash for ChannelState {
|
||||||
fn hash<H: std::hash::Hasher>(&self, state: &mut H) {
|
fn hash<H: std::hash::Hasher>(&self, state: &mut H) {
|
||||||
self.current_channel.hash(state);
|
self.current_channel_name.hash(state);
|
||||||
self.selected_entries
|
self.selected_entries
|
||||||
.iter()
|
.iter()
|
||||||
.for_each(|entry| entry.hash(state));
|
.for_each(|entry| entry.hash(state));
|
||||||
@ -177,7 +174,7 @@ pub fn draw(ctx: &Ctx, f: &mut Frame<'_>, area: Rect) -> Result<()> {
|
|||||||
draw_help_bar(
|
draw_help_bar(
|
||||||
f,
|
f,
|
||||||
&layout.help_bar,
|
&layout.help_bar,
|
||||||
ctx.tv_state.channel_state.current_channel,
|
&ctx.tv_state.channel_state.current_channel_name,
|
||||||
build_keybindings_table(
|
build_keybindings_table(
|
||||||
&ctx.config.keybindings.to_displayable(),
|
&ctx.config.keybindings.to_displayable(),
|
||||||
ctx.tv_state.mode,
|
ctx.tv_state.mode,
|
||||||
@ -233,6 +230,7 @@ pub fn draw(ctx: &Ctx, f: &mut Frame<'_>, area: Rect) -> Result<()> {
|
|||||||
&ctx.tv_state.results_picker.input,
|
&ctx.tv_state.results_picker.input,
|
||||||
&ctx.tv_state.results_picker.state,
|
&ctx.tv_state.results_picker.state,
|
||||||
ctx.tv_state.channel_state.running,
|
ctx.tv_state.channel_state.running,
|
||||||
|
&ctx.tv_state.channel_state.current_channel_name,
|
||||||
&ctx.tv_state.spinner,
|
&ctx.tv_state.spinner,
|
||||||
&ctx.colorscheme,
|
&ctx.colorscheme,
|
||||||
)?;
|
)?;
|
||||||
|
@ -1,5 +1,4 @@
|
|||||||
use super::layout::HelpBarLayout;
|
use super::layout::HelpBarLayout;
|
||||||
use crate::channels::UnitChannel;
|
|
||||||
use crate::screen::colors::{Colorscheme, GeneralColorscheme};
|
use crate::screen::colors::{Colorscheme, GeneralColorscheme};
|
||||||
use crate::screen::logo::build_logo_paragraph;
|
use crate::screen::logo::build_logo_paragraph;
|
||||||
use crate::screen::metadata::build_metadata_table;
|
use crate::screen::metadata::build_metadata_table;
|
||||||
@ -37,7 +36,7 @@ fn draw_metadata_block(
|
|||||||
f: &mut Frame,
|
f: &mut Frame,
|
||||||
area: Rect,
|
area: Rect,
|
||||||
mode: Mode,
|
mode: Mode,
|
||||||
current_channel: UnitChannel,
|
current_channel_name: &str,
|
||||||
app_metadata: &AppMetadata,
|
app_metadata: &AppMetadata,
|
||||||
colorscheme: &Colorscheme,
|
colorscheme: &Colorscheme,
|
||||||
) {
|
) {
|
||||||
@ -51,8 +50,12 @@ fn draw_metadata_block(
|
|||||||
.bg(colorscheme.general.background.unwrap_or_default()),
|
.bg(colorscheme.general.background.unwrap_or_default()),
|
||||||
);
|
);
|
||||||
|
|
||||||
let metadata_table =
|
let metadata_table = build_metadata_table(
|
||||||
build_metadata_table(mode, current_channel, app_metadata, colorscheme)
|
mode,
|
||||||
|
current_channel_name,
|
||||||
|
app_metadata,
|
||||||
|
colorscheme,
|
||||||
|
)
|
||||||
.block(metadata_block);
|
.block(metadata_block);
|
||||||
|
|
||||||
f.render_widget(metadata_table, area);
|
f.render_widget(metadata_table, area);
|
||||||
@ -79,7 +82,7 @@ fn draw_keymaps_block(
|
|||||||
pub fn draw_help_bar(
|
pub fn draw_help_bar(
|
||||||
f: &mut Frame,
|
f: &mut Frame,
|
||||||
layout: &Option<HelpBarLayout>,
|
layout: &Option<HelpBarLayout>,
|
||||||
current_channel: UnitChannel,
|
current_channel_name: &str,
|
||||||
keymap_table: Table,
|
keymap_table: Table,
|
||||||
mode: Mode,
|
mode: Mode,
|
||||||
app_metadata: &AppMetadata,
|
app_metadata: &AppMetadata,
|
||||||
@ -90,7 +93,7 @@ pub fn draw_help_bar(
|
|||||||
f,
|
f,
|
||||||
help_bar.left,
|
help_bar.left,
|
||||||
mode,
|
mode,
|
||||||
current_channel,
|
current_channel_name,
|
||||||
app_metadata,
|
app_metadata,
|
||||||
colorscheme,
|
colorscheme,
|
||||||
);
|
);
|
||||||
|
@ -5,14 +5,13 @@ use ratatui::{
|
|||||||
Alignment, Constraint, Direction, Layout as RatatuiLayout, Rect,
|
Alignment, Constraint, Direction, Layout as RatatuiLayout, Rect,
|
||||||
},
|
},
|
||||||
style::{Style, Stylize},
|
style::{Style, Stylize},
|
||||||
text::Span,
|
text::{Line, Span},
|
||||||
widgets::{Block, BorderType, Borders, ListState, Paragraph},
|
widgets::{Block, BorderType, Borders, ListState, Paragraph},
|
||||||
Frame,
|
Frame,
|
||||||
};
|
};
|
||||||
|
|
||||||
use crate::screen::{colors::Colorscheme, spinner::Spinner};
|
use crate::screen::{colors::Colorscheme, spinner::Spinner};
|
||||||
|
|
||||||
// TODO: refactor arguments (e.g. use a struct for the spinner+state, same
|
|
||||||
#[allow(clippy::too_many_arguments)]
|
#[allow(clippy::too_many_arguments)]
|
||||||
pub fn draw_input_box(
|
pub fn draw_input_box(
|
||||||
f: &mut Frame,
|
f: &mut Frame,
|
||||||
@ -22,6 +21,7 @@ pub fn draw_input_box(
|
|||||||
input_state: &Input,
|
input_state: &Input,
|
||||||
results_picker_state: &ListState,
|
results_picker_state: &ListState,
|
||||||
matcher_running: bool,
|
matcher_running: bool,
|
||||||
|
channel_name: &str,
|
||||||
spinner: &Spinner,
|
spinner: &Spinner,
|
||||||
colorscheme: &Colorscheme,
|
colorscheme: &Colorscheme,
|
||||||
) -> Result<()> {
|
) -> Result<()> {
|
||||||
@ -29,6 +29,11 @@ pub fn draw_input_box(
|
|||||||
.borders(Borders::ALL)
|
.borders(Borders::ALL)
|
||||||
.border_type(BorderType::Rounded)
|
.border_type(BorderType::Rounded)
|
||||||
.border_style(Style::default().fg(colorscheme.general.border_fg))
|
.border_style(Style::default().fg(colorscheme.general.border_fg))
|
||||||
|
.title_top(
|
||||||
|
Line::from(String::from(" ") + channel_name + " ")
|
||||||
|
.style(Style::default().fg(colorscheme.mode.channel).bold())
|
||||||
|
.centered(),
|
||||||
|
)
|
||||||
.style(
|
.style(
|
||||||
Style::default()
|
Style::default()
|
||||||
.bg(colorscheme.general.background.unwrap_or_default()),
|
.bg(colorscheme.general.background.unwrap_or_default()),
|
||||||
|
@ -1,6 +1,5 @@
|
|||||||
use std::fmt::Display;
|
use std::fmt::Display;
|
||||||
|
|
||||||
use crate::channels::UnitChannel;
|
|
||||||
use crate::screen::{colors::Colorscheme, mode::mode_color};
|
use crate::screen::{colors::Colorscheme, mode::mode_color};
|
||||||
use crate::television::Mode;
|
use crate::television::Mode;
|
||||||
use crate::utils::metadata::AppMetadata;
|
use crate::utils::metadata::AppMetadata;
|
||||||
@ -23,7 +22,7 @@ impl Display for Mode {
|
|||||||
|
|
||||||
pub fn build_metadata_table<'a>(
|
pub fn build_metadata_table<'a>(
|
||||||
mode: Mode,
|
mode: Mode,
|
||||||
current_channel: UnitChannel,
|
current_channel_name: &'a str,
|
||||||
app_metadata: &'a AppMetadata,
|
app_metadata: &'a AppMetadata,
|
||||||
colorscheme: &'a Colorscheme,
|
colorscheme: &'a Colorscheme,
|
||||||
) -> Table<'a> {
|
) -> Table<'a> {
|
||||||
@ -58,7 +57,7 @@ pub fn build_metadata_table<'a>(
|
|||||||
Style::default().fg(colorscheme.help.metadata_field_name_fg),
|
Style::default().fg(colorscheme.help.metadata_field_name_fg),
|
||||||
)),
|
)),
|
||||||
Cell::from(Span::styled(
|
Cell::from(Span::styled(
|
||||||
current_channel.to_string(),
|
current_channel_name,
|
||||||
Style::default().fg(colorscheme.help.metadata_field_value_fg),
|
Style::default().fg(colorscheme.help.metadata_field_value_fg),
|
||||||
)),
|
)),
|
||||||
]);
|
]);
|
||||||
|
@ -127,7 +127,7 @@ impl Television {
|
|||||||
|
|
||||||
pub fn dump_context(&self) -> Ctx {
|
pub fn dump_context(&self) -> Ctx {
|
||||||
let channel_state = ChannelState::new(
|
let channel_state = ChannelState::new(
|
||||||
self.current_channel(),
|
self.channel.name(),
|
||||||
self.channel.selected_entries().clone(),
|
self.channel.selected_entries().clone(),
|
||||||
self.channel.total_count(),
|
self.channel.total_count(),
|
||||||
self.channel.running(),
|
self.channel.running(),
|
||||||
|
Loading…
x
Reference in New Issue
Block a user