Skip to content

Commit ea0989f

Browse files
committed
feat(shortcuts): C key opens comments. CTRL+C quits as well.
1 parent 177c11f commit ea0989f

2 files changed

Lines changed: 15 additions & 0 deletions

File tree

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,7 @@ cargo run
5252
- `j` or ``: Move down
5353
- `k` or ``: Move up
5454
- `Enter`: Open selected story in default browser
55+
- `C`: Open comments for selected story
5556
- `o`: Open options menu
5657
- `q`: Quit application
5758
- `Esc`: Close menus/summaries

src/main.rs

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -109,6 +109,16 @@ impl App {
109109
}
110110
}
111111

112+
fn open_comments(&mut self) {
113+
if let Some(story) = self.stories.get(self.selected_index) {
114+
let hn_url = format!("https://news.ycombinator.com/item?id={}", story.id);
115+
match open::that(&hn_url) {
116+
Ok(_) => self.set_status_message("Opened comments in browser".to_string()),
117+
Err(_) => self.set_status_message("Failed to open comments".to_string()),
118+
}
119+
}
120+
}
121+
112122
async fn load_all_sections(
113123
&mut self,
114124
terminal: &mut Terminal<CrosstermBackend<io::Stdout>>,
@@ -547,6 +557,7 @@ async fn main() -> Result<(), Box<dyn Error + Send + Sync>> {
547557
match app.mode {
548558
Mode::Normal => match key.code {
549559
KeyCode::Char('q') => break,
560+
KeyCode::Char('c') if key.modifiers.contains(event::KeyModifiers::CONTROL) => break,
550561
KeyCode::Char('j') | KeyCode::Down => app.next_story(),
551562
KeyCode::Char('k') | KeyCode::Up => app.previous_story(),
552563
KeyCode::Char('R') => {
@@ -600,6 +611,9 @@ async fn main() -> Result<(), Box<dyn Error + Send + Sync>> {
600611
app.mode = Mode::Menu;
601612
app.menu_index = 0;
602613
}
614+
KeyCode::Char('C') => {
615+
app.open_comments();
616+
}
603617
KeyCode::Char('h') => {
604618
app.current_section = match app.current_section {
605619
Section::Top => Section::Jobs,

0 commit comments

Comments
 (0)