1
0
mirror of https://github.com/taigrr/wtf synced 2025-01-18 04:03:14 -08:00

Merge pull request #340 from kaskavalci/add-hn-comments

Add shortcut to open Hacker News comments
This commit is contained in:
Anand Sudhir Prayaga 2018-11-13 20:36:27 +01:00 committed by GitHub
commit 3c669607de
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -2,12 +2,13 @@ package hackernews
import ( import (
"fmt" "fmt"
"github.com/gdamore/tcell"
"github.com/rivo/tview"
"github.com/senorprogrammer/wtf/wtf"
"net/url" "net/url"
"strconv" "strconv"
"strings" "strings"
"github.com/gdamore/tcell"
"github.com/rivo/tview"
"github.com/senorprogrammer/wtf/wtf"
) )
const HelpText = ` const HelpText = `
@ -22,6 +23,7 @@ const HelpText = `
arrow up: Select the previous story in the list arrow up: Select the previous story in the list
return: Open the selected story in a browser return: Open the selected story in a browser
c: Open the comments of the article
` `
type Widget struct { type Widget struct {
@ -151,6 +153,14 @@ func (widget *Widget) openStory() {
} }
} }
func (widget *Widget) openComments() {
sel := widget.selected
if sel >= 0 && widget.stories != nil && sel < len(widget.stories) {
story := &widget.stories[widget.selected]
wtf.OpenFile(fmt.Sprintf("https://news.ycombinator.com/item?id=%d", story.ID))
}
}
func (widget *Widget) unselect() { func (widget *Widget) unselect() {
widget.selected = -1 widget.selected = -1
widget.display() widget.display()
@ -169,6 +179,9 @@ func (widget *Widget) keyboardIntercept(event *tcell.EventKey) *tcell.EventKey {
case "r": case "r":
widget.Refresh() widget.Refresh()
return nil return nil
case "c":
widget.openComments()
return nil
} }
switch event.Key() { switch event.Key() {