Skip to content

Commit

Permalink
top menus
Browse files Browse the repository at this point in the history
  • Loading branch information
alexpasmantier committed Oct 25, 2024
1 parent 4bec64e commit 9eea37a
Show file tree
Hide file tree
Showing 9 changed files with 329 additions and 157 deletions.
3 changes: 0 additions & 3 deletions .config/config.toml
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,7 @@ down = "SelectNextEntry"
up = "SelectPrevEntry"
ctrl-n = "SelectNextEntry"
ctrl-p = "SelectPrevEntry"
alt-down = "ScrollPreviewHalfPageDown"
ctrl-d = "ScrollPreviewHalfPageDown"
alt-up = "ScrollPreviewHalfPageUp"
ctrl-u = "ScrollPreviewHalfPageUp"
enter = "SelectEntry"
ctrl-enter = "SendToChannel"
Expand All @@ -20,4 +18,3 @@ ctrl-n = "SelectNextEntry"
ctrl-p = "SelectPrevEntry"
enter = "SelectEntry"
ctrl-s = "ToggleChannelSelection"

8 changes: 4 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,12 @@
_______________
|,----------. |\
|| |=| |
|| || | |
|| . _o| | |
|| | | |
|| |o| |
|`-----------' |/
~~~~~~~~~~~~~~~
`--------------'
__ __ _ _
/ /____ / /__ _ __(_)__ (_)__ ___
/ /____ / /__ _ __(_)__ (_)__ ___
/ __/ -_) / -_) |/ / (_-</ / _ \/ _ \
\__/\__/_/\__/|___/_/___/_/\___/_//_/
Expand Down
87 changes: 57 additions & 30 deletions crates/television/television.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,26 +14,32 @@ use ratatui::{
};
use serde::{Deserialize, Serialize};
use std::{collections::HashMap, str::FromStr};
use strum::Display;
use tokio::sync::mpsc::UnboundedSender;

use crate::ui::input::Input;
use crate::ui::layout::{Dimensions, Layout};
use crate::ui::preview::DEFAULT_PREVIEW_TITLE_FG;
use crate::ui::results::build_results_list;
use crate::ui::{
layout::{Dimensions, Layout},
logo::build_logo_paragraph,
};
use crate::utils::strings::EMPTY_STRING;
use crate::{action::Action, config::Config};
use crate::{channels::tv_guide::TvGuide, ui::get_border_style};
use crate::{channels::OnAir, utils::strings::shrink_with_ellipsis};
use crate::{
channels::TelevisionChannel, ui::input::actions::InputActionHandler,
};
use crate::{channels::UnitChannel, ui::input::Input};
use crate::{
entry::{Entry, ENTRY_PLACEHOLDER},
ui::spinner::Spinner,
};
use crate::{previewers::Previewer, ui::spinner::SpinnerState};

#[derive(PartialEq, Copy, Clone, Hash, Eq, Debug, Serialize, Deserialize)]
#[derive(
PartialEq, Copy, Clone, Hash, Eq, Debug, Serialize, Deserialize, Display,
)]
pub enum Mode {
Channel,
Guide,
Expand Down Expand Up @@ -98,6 +104,10 @@ impl Television {
}
}

pub fn current_channel(&self) -> UnitChannel {
UnitChannel::from(&self.channel)
}

/// FIXME: this needs rework
pub fn change_channel(&mut self, channel: TelevisionChannel) {
self.reset_preview_scroll();
Expand Down Expand Up @@ -304,19 +314,17 @@ impl Television {
Action::ScrollPreviewUp => self.scroll_preview_up(1),
Action::ScrollPreviewHalfPageDown => self.scroll_preview_down(20),
Action::ScrollPreviewHalfPageUp => self.scroll_preview_up(20),
Action::ToggleChannelSelection => {
match self.mode {
Mode::Channel => {
self.reset_screen();
self.mode = Mode::Guide;
}
Mode::Guide => {
self.reset_screen();
self.mode = Mode::Channel;
}
Mode::SendToChannel => {}
Action::ToggleChannelSelection => match self.mode {
Mode::Channel => {
self.reset_screen();
self.mode = Mode::Guide;
}
}
Mode::Guide => {
self.reset_screen();
self.mode = Mode::Channel;
}
Mode::SendToChannel => {}
},
Action::SelectEntry => {
if let Some(entry) = self.get_selected_entry() {
match self.mode {
Expand Down Expand Up @@ -387,19 +395,38 @@ impl Television {
},
);

let help_block = Block::default()
.borders(Borders::NONE)
let metadata_block = Block::default()
.borders(Borders::ALL)
.border_type(BorderType::Rounded)
.border_style(Style::default().fg(Color::Blue))
.padding(Padding::horizontal(1))
.style(Style::default());

let metadata_table = self.build_metadata_table().block(metadata_block);

f.render_widget(metadata_table, layout.help_bar_left);

let keymaps_block = Block::default()
.borders(Borders::ALL)
.border_type(BorderType::Rounded)
.border_style(Style::default().fg(Color::Blue))
.style(Style::default())
.padding(Padding::uniform(1));
.padding(Padding::horizontal(1));

let keymaps_table = self.build_help_table()?.block(keymaps_block);

f.render_widget(keymaps_table, layout.help_bar_middle);

let logo_block = Block::default()
.borders(Borders::ALL)
.border_type(BorderType::Rounded)
.border_style(Style::default().fg(Color::Blue))
.style(Style::default().fg(Color::Yellow))
.padding(Padding::horizontal(1));

let help_text = self
.build_help_paragraph()?
.style(Style::default().fg(Color::DarkGray).italic())
.alignment(Alignment::Center)
.wrap(Wrap { trim: true })
.block(help_block);
let logo_paragraph = build_logo_paragraph().block(logo_block);

f.render_widget(help_text, layout.help_bar);
f.render_widget(logo_paragraph, layout.help_bar_right);

self.results_area_height = u32::from(layout.results.height);
if let Some(preview_window) = layout.preview_window {
Expand Down Expand Up @@ -489,7 +516,7 @@ impl Television {
"> ",
Style::default().fg(DEFAULT_INPUT_FG).bold(),
))
.block(arrow_block);
.block(arrow_block);
f.render_widget(arrow, inner_input_chunks[0]);

let interactive_input_block = Block::default();
Expand Down Expand Up @@ -527,8 +554,8 @@ impl Television {
),
Style::default().fg(DEFAULT_RESULTS_COUNT_FG).italic(),
))
.block(result_count_block)
.alignment(Alignment::Right);
.block(result_count_block)
.alignment(Alignment::Right);
f.render_widget(result_count_paragraph, inner_input_chunks[2]);

// Make the cursor visible and ask tui-rs to put it at the
Expand All @@ -537,8 +564,8 @@ impl Television {
// Put cursor past the end of the input text
inner_input_chunks[1].x
+ u16::try_from(
self.input.visual_cursor().max(scroll) - scroll,
)?,
self.input.visual_cursor().max(scroll) - scroll,
)?,
// Move one line down, from the border to the input line
inner_input_chunks[1].y,
));
Expand Down
2 changes: 2 additions & 0 deletions crates/television/ui.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ use ratatui::style::{Color, Style, Stylize};
pub mod help;
pub mod input;
pub mod layout;
pub mod logo;
pub mod metadata;
pub mod preview;
pub mod results;
pub mod spinner;
Expand Down
Loading

0 comments on commit 9eea37a

Please sign in to comment.