Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,8 @@ Some normal mode controls vary based on whether you are currently selecting a fe

- `q`/`Esc` - quit Russ
- `hjkl`/arrows - move up/down/left/right between feeds and entries, scroll up/down on an entry
- `g`/`G` - move to top/bottom of the current entry or list
- `ctrl-o` - return to previous place after jumping with `g`/`G`
- `Enter` - read selected entry
- `r` - refresh the selected feed
- `r` - mark the selected entry as read
Expand Down
55 changes: 53 additions & 2 deletions src/app.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ use crate::modes::{Mode, ReadMode, Selected};
use crate::util;
use anyhow::Result;
use copypasta::{ClipboardContext, ClipboardProvider};
use ratatui::{backend::CrosstermBackend, Terminal};
use ratatui::{Terminal, backend::CrosstermBackend};
use std::sync::{Arc, Mutex};

macro_rules! delegate_to_locked_inner {
Expand Down Expand Up @@ -56,6 +56,8 @@ impl App {
(on_left, Result<()>),
(on_right, Result<()>),
(on_up, Result<()>),
(on_top, Result<()>),
(on_bottom, Result<()>),
(page_up, ()),
(page_down, ()),
(pop_feed_subscription_input, ()),
Expand Down Expand Up @@ -595,7 +597,9 @@ impl AppImpl {

#[cfg(not(target_os = "linux"))]
{
unreachable!("This should never happen. This code should only be reachable if the target OS is WSL.")
unreachable!(
"This should never happen. This code should only be reachable if the target OS is WSL."
)
}
} else if let Some(current_link) = current_link {
let mut ctx = ClipboardContext::new().map_err(|e| anyhow::anyhow!(e))?;
Expand Down Expand Up @@ -702,6 +706,53 @@ impl AppImpl {
Ok(())
}

pub fn on_top(&mut self) -> Result<()> {
match self.selected {
Selected::Feeds => {
self.feeds.first();
self.update_current_feed_and_entries()?;
}
Selected::Entries => {
if !self.entries.items.is_empty() {
self.entries.first();
self.entry_selection_position = self.entries.state.selected().unwrap();
self.update_current_entry_meta()?;
}
}
Selected::Entry(_) => {
self.entry_scroll_position = 0;
}
Selected::None => (),
}

Ok(())
}

pub fn on_bottom(&mut self) -> Result<()> {
match self.selected {
Selected::Feeds => {
self.feeds.last();
self.update_current_feed_and_entries()?;
}
Selected::Entries => {
if !self.entries.items.is_empty() {
self.entries.last();
self.entry_selection_position = self.entries.state.selected().unwrap();
self.update_current_entry_meta()?;
}
}
Selected::Entry(_) => {
self.entry_scroll_position = self
.entry_lines_len
.saturating_sub(self.entry_lines_rendered_len.into())
.saturating_sub(1) as u16;
}
Selected::None => (),
}

Ok(())
}

pub fn mode(&self) -> Mode {
self.mode
}
Expand Down
6 changes: 6 additions & 0 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -261,6 +261,8 @@ enum Action {
MoveDown,
MoveUp,
MoveRight,
MoveTop,
MoveBottom,
PageUp,
PageDown,
RefreshAll,
Expand Down Expand Up @@ -304,6 +306,8 @@ fn get_action(app: &App, event: Event<KeyEvent>) -> Option<Action> {
(KeyCode::Right, _) | (KeyCode::Char('l'), _) => Some(Action::MoveRight),
(KeyCode::Down, _) | (KeyCode::Char('j'), _) => Some(Action::MoveDown),
(KeyCode::Up, _) | (KeyCode::Char('k'), _) => Some(Action::MoveUp),
(KeyCode::Char('g'), _) => Some(Action::MoveTop),
(KeyCode::Char('G'), _) => Some(Action::MoveBottom),
(KeyCode::PageUp, _) | (KeyCode::Char('u'), KeyModifiers::CONTROL) => {
Some(Action::PageUp)
}
Expand Down Expand Up @@ -366,6 +370,8 @@ fn update(app: &mut App, action: Action) -> Result<()> {
Action::MoveDown => app.on_down()?,
Action::MoveUp => app.on_up()?,
Action::MoveRight => app.on_right()?,
Action::MoveTop => app.on_top()?,
Action::MoveBottom => app.on_bottom()?,
Action::PageUp => app.page_up(),
Action::PageDown => app.page_down(),
Action::ToggleHelp => app.toggle_help()?,
Expand Down
1 change: 0 additions & 1 deletion src/ui.rs
Original file line number Diff line number Diff line change
Expand Up @@ -403,7 +403,6 @@ fn draw_entry(f: &mut Frame, area: Rect, app: &mut AppImpl) {

let paragraph = Paragraph::new(app.current_entry_text.as_str())
.block(block)
.wrap(Wrap { trim: false })
.scroll((scroll, 0));

let entry_chunk_height = area.height - 2;
Expand Down
8 changes: 8 additions & 0 deletions src/util.rs
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,14 @@ impl<T> StatefulList<T> {
self.state.select(Some(i));
}

pub fn first(&mut self) {
self.state.select(Some(0));
}

pub fn last(&mut self) {
self.state.select(Some(self.items.len() - 1));
}

pub fn reset(&mut self) {
self.state.select(Some(0));
}
Expand Down