caret

[ACTIVE] a command line tool for browsing Lobsters in your terminal
git clone git://git.figbert.com/caret.git
Log | Files | Refs | README | LICENSE

commit ebb307c57b2d2e529459c22a07ca0468a5badb9e
parent 1499ba5280aaa3fe86be3a98fba6b7ebafe536ef
Author: FIGBERT <figbert@figbert.com>
Date:   Tue,  5 Sep 2023 10:06:10 -0700

Add open-comments-in-browser

Diffstat:
Mcmds.go | 48+++++++++++++++++++++++++++++++++++++-----------
Mmain.go | 2++
2 files changed, 39 insertions(+), 11 deletions(-)

diff --git a/cmds.go b/cmds.go @@ -26,22 +26,48 @@ func attemptToOpenPostURL(itm list.Item) tea.Cmd { return postHasNoLinkToOpen{} } - switch runtime.GOOS { - case "darwin": - cmd := exec.Command("open", i.post.URL) - _ = cmd.Start() - case "linux": - cmd := exec.Command("xdg-open", i.post.URL) - _ = cmd.Start() - case "windows": - cmd := exec.Command("rundll32", "url.dll,FileProtocolHandler", i.post.URL) - _ = cmd.Start() + success := openURL(i.post.URL) + if !success { + return platformUnsupported{} } - return platformUnsupported{} + return nil } } +func attemptToOpenPostComments(itm list.Item) tea.Cmd { + return func() tea.Msg { + i, ok := itm.(item) + if !ok { + return genericError{} + } + + success := openURL(i.post.CommentsURL) + if !success { + return platformUnsupported{} + } + + return nil + } +} + +func openURL(url string) bool { + switch runtime.GOOS { + case "darwin": + cmd := exec.Command("open", url) + _ = cmd.Start() + case "linux": + cmd := exec.Command("xdg-open", url) + _ = cmd.Start() + case "windows": + cmd := exec.Command("rundll32", "url.dll,FileProtocolHandler", url) + _ = cmd.Start() + default: + return false + } + return true +} + func clearMsg() tea.Msg { time.Sleep(time.Second * 5) return msgExpired{} diff --git a/main.go b/main.go @@ -36,6 +36,8 @@ func (m model) Update(msg tea.Msg) (tea.Model, tea.Cmd) { return m, tea.Quit case "o": cmds = append(cmds, attemptToOpenPostURL(m.posts.SelectedItem())) + case "c": + cmds = append(cmds, attemptToOpenPostComments(m.posts.SelectedItem())) case "j": if m.posts.Index() == len(m.posts.Items())-1 { m.page++