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

open hacker news comments via c keyword

This commit is contained in:
Halil Kaskavalci 2018-11-13 16:36:42 +01:00
parent 748ad82967
commit 545092a8a3

View File

@ -2,12 +2,13 @@ package hackernews
import (
"fmt"
"github.com/gdamore/tcell"
"github.com/rivo/tview"
"github.com/senorprogrammer/wtf/wtf"
"net/url"
"strconv"
"strings"
"github.com/gdamore/tcell"
"github.com/rivo/tview"
"github.com/senorprogrammer/wtf/wtf"
)
const HelpText = `
@ -22,6 +23,7 @@ const HelpText = `
arrow up: Select the previous story in the list
return: Open the selected story in a browser
c: Open the comments of the article
`
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() {
widget.selected = -1
widget.display()
@ -169,6 +179,9 @@ func (widget *Widget) keyboardIntercept(event *tcell.EventKey) *tcell.EventKey {
case "r":
widget.Refresh()
return nil
case "c":
widget.openComments()
return nil
}
switch event.Key() {