mirror of
https://github.com/alexpasmantier/television.git
synced 2025-06-06 03:25: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)]
|
||||
pub struct Channel {
|
||||
name: String,
|
||||
pub name: String,
|
||||
matcher: Matcher<String>,
|
||||
entries_command: String,
|
||||
preview_kind: PreviewKind,
|
||||
|
@ -174,6 +174,14 @@ impl TelevisionChannel {
|
||||
_ => 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 {
|
||||
|
@ -7,10 +7,7 @@ use tokio::sync::mpsc::Sender;
|
||||
|
||||
use crate::{
|
||||
action::Action,
|
||||
channels::{
|
||||
entry::{Entry, PreviewType, ENTRY_PLACEHOLDER},
|
||||
UnitChannel,
|
||||
},
|
||||
channels::entry::{Entry, PreviewType, ENTRY_PLACEHOLDER},
|
||||
config::Config,
|
||||
picker::Picker,
|
||||
preview::PreviewState,
|
||||
@ -27,7 +24,7 @@ use crate::{
|
||||
|
||||
#[derive(Debug, Clone, PartialEq)]
|
||||
pub struct ChannelState {
|
||||
pub current_channel: UnitChannel,
|
||||
pub current_channel_name: String,
|
||||
pub selected_entries: FxHashSet<Entry>,
|
||||
pub total_count: u32,
|
||||
pub running: bool,
|
||||
@ -35,13 +32,13 @@ pub struct ChannelState {
|
||||
|
||||
impl ChannelState {
|
||||
pub fn new(
|
||||
current_channel: UnitChannel,
|
||||
current_channel_name: String,
|
||||
selected_entries: FxHashSet<Entry>,
|
||||
total_count: u32,
|
||||
running: bool,
|
||||
) -> Self {
|
||||
Self {
|
||||
current_channel,
|
||||
current_channel_name,
|
||||
selected_entries,
|
||||
total_count,
|
||||
running,
|
||||
@ -51,7 +48,7 @@ impl ChannelState {
|
||||
|
||||
impl Hash for ChannelState {
|
||||
fn hash<H: std::hash::Hasher>(&self, state: &mut H) {
|
||||
self.current_channel.hash(state);
|
||||
self.current_channel_name.hash(state);
|
||||
self.selected_entries
|
||||
.iter()
|
||||
.for_each(|entry| entry.hash(state));
|
||||
@ -177,7 +174,7 @@ pub fn draw(ctx: &Ctx, f: &mut Frame<'_>, area: Rect) -> Result<()> {
|
||||
draw_help_bar(
|
||||
f,
|
||||
&layout.help_bar,
|
||||
ctx.tv_state.channel_state.current_channel,
|
||||
&ctx.tv_state.channel_state.current_channel_name,
|
||||
build_keybindings_table(
|
||||
&ctx.config.keybindings.to_displayable(),
|
||||
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.state,
|
||||
ctx.tv_state.channel_state.running,
|
||||
&ctx.tv_state.channel_state.current_channel_name,
|
||||
&ctx.tv_state.spinner,
|
||||
&ctx.colorscheme,
|
||||
)?;
|
||||
|
@ -1,5 +1,4 @@
|
||||
use super::layout::HelpBarLayout;
|
||||
use crate::channels::UnitChannel;
|
||||
use crate::screen::colors::{Colorscheme, GeneralColorscheme};
|
||||
use crate::screen::logo::build_logo_paragraph;
|
||||
use crate::screen::metadata::build_metadata_table;
|
||||
@ -37,7 +36,7 @@ fn draw_metadata_block(
|
||||
f: &mut Frame,
|
||||
area: Rect,
|
||||
mode: Mode,
|
||||
current_channel: UnitChannel,
|
||||
current_channel_name: &str,
|
||||
app_metadata: &AppMetadata,
|
||||
colorscheme: &Colorscheme,
|
||||
) {
|
||||
@ -51,8 +50,12 @@ fn draw_metadata_block(
|
||||
.bg(colorscheme.general.background.unwrap_or_default()),
|
||||
);
|
||||
|
||||
let metadata_table =
|
||||
build_metadata_table(mode, current_channel, app_metadata, colorscheme)
|
||||
let metadata_table = build_metadata_table(
|
||||
mode,
|
||||
current_channel_name,
|
||||
app_metadata,
|
||||
colorscheme,
|
||||
)
|
||||
.block(metadata_block);
|
||||
|
||||
f.render_widget(metadata_table, area);
|
||||
@ -79,7 +82,7 @@ fn draw_keymaps_block(
|
||||
pub fn draw_help_bar(
|
||||
f: &mut Frame,
|
||||
layout: &Option<HelpBarLayout>,
|
||||
current_channel: UnitChannel,
|
||||
current_channel_name: &str,
|
||||
keymap_table: Table,
|
||||
mode: Mode,
|
||||
app_metadata: &AppMetadata,
|
||||
@ -90,7 +93,7 @@ pub fn draw_help_bar(
|
||||
f,
|
||||
help_bar.left,
|
||||
mode,
|
||||
current_channel,
|
||||
current_channel_name,
|
||||
app_metadata,
|
||||
colorscheme,
|
||||
);
|
||||
|
@ -5,14 +5,13 @@ use ratatui::{
|
||||
Alignment, Constraint, Direction, Layout as RatatuiLayout, Rect,
|
||||
},
|
||||
style::{Style, Stylize},
|
||||
text::Span,
|
||||
text::{Line, Span},
|
||||
widgets::{Block, BorderType, Borders, ListState, Paragraph},
|
||||
Frame,
|
||||
};
|
||||
|
||||
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)]
|
||||
pub fn draw_input_box(
|
||||
f: &mut Frame,
|
||||
@ -22,6 +21,7 @@ pub fn draw_input_box(
|
||||
input_state: &Input,
|
||||
results_picker_state: &ListState,
|
||||
matcher_running: bool,
|
||||
channel_name: &str,
|
||||
spinner: &Spinner,
|
||||
colorscheme: &Colorscheme,
|
||||
) -> Result<()> {
|
||||
@ -29,6 +29,11 @@ pub fn draw_input_box(
|
||||
.borders(Borders::ALL)
|
||||
.border_type(BorderType::Rounded)
|
||||
.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::default()
|
||||
.bg(colorscheme.general.background.unwrap_or_default()),
|
||||
|
@ -1,6 +1,5 @@
|
||||
use std::fmt::Display;
|
||||
|
||||
use crate::channels::UnitChannel;
|
||||
use crate::screen::{colors::Colorscheme, mode::mode_color};
|
||||
use crate::television::Mode;
|
||||
use crate::utils::metadata::AppMetadata;
|
||||
@ -23,7 +22,7 @@ impl Display for Mode {
|
||||
|
||||
pub fn build_metadata_table<'a>(
|
||||
mode: Mode,
|
||||
current_channel: UnitChannel,
|
||||
current_channel_name: &'a str,
|
||||
app_metadata: &'a AppMetadata,
|
||||
colorscheme: &'a Colorscheme,
|
||||
) -> Table<'a> {
|
||||
@ -58,7 +57,7 @@ pub fn build_metadata_table<'a>(
|
||||
Style::default().fg(colorscheme.help.metadata_field_name_fg),
|
||||
)),
|
||||
Cell::from(Span::styled(
|
||||
current_channel.to_string(),
|
||||
current_channel_name,
|
||||
Style::default().fg(colorscheme.help.metadata_field_value_fg),
|
||||
)),
|
||||
]);
|
||||
|
@ -127,7 +127,7 @@ impl Television {
|
||||
|
||||
pub fn dump_context(&self) -> Ctx {
|
||||
let channel_state = ChannelState::new(
|
||||
self.current_channel(),
|
||||
self.channel.name(),
|
||||
self.channel.selected_entries().clone(),
|
||||
self.channel.total_count(),
|
||||
self.channel.running(),
|
||||
|
Loading…
x
Reference in New Issue
Block a user