Skip to content

Commit

Permalink
Implemented open and share
Browse files Browse the repository at this point in the history
  • Loading branch information
mrusme committed Apr 4, 2021
1 parent 00c8b79 commit f116be5
Show file tree
Hide file tree
Showing 3 changed files with 63 additions and 0 deletions.
1 change: 1 addition & 0 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ module github.com/mrusme/gomphotherium
go 1.15

require (
github.com/atotto/clipboard v0.1.4 // indirect
github.com/eliukblau/pixterm v1.3.1
github.com/gdamore/tcell/v2 v2.2.0 // indirect
github.com/gizak/termui/v3 v3.1.0
Expand Down
2 changes: 2 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@ github.com/andybalholm/cascadia v1.0.0/go.mod h1:GsXiBklL0woXo1j/WYWtSYYC4ouU9Pq
github.com/armon/circbuf v0.0.0-20150827004946-bbbad097214e/go.mod h1:3U/XgcO3hCbHZ8TKRvWD2dDTCfh9M9ya+I9JpbB7O8o=
github.com/armon/go-metrics v0.0.0-20180917152333-f0300d1749da/go.mod h1:Q73ZrmVTwzkszR9V5SSuryQ31EELlFMUz1kKyl939pY=
github.com/armon/go-radix v0.0.0-20180808171621-7fddfc383310/go.mod h1:ufUuZ+zHj4x4TnLV4JWEpy2hxWSpsRywHrMgIH9cCH8=
github.com/atotto/clipboard v0.1.4 h1:EH0zSVneZPSuFR11BlR9YppQTVDbh5+16AmcJi4g1z4=
github.com/atotto/clipboard v0.1.4/go.mod h1:ZY9tmq7sm5xIbd9bOK4onWV4S6X0u6GY7Vn0Yu86PYI=
github.com/beorn7/perks v0.0.0-20180321164747-3a771d992973/go.mod h1:Dwedo/Wpr24TaqPxmxbtue+5NUziq4I4S80YR8gNf3Q=
github.com/beorn7/perks v1.0.0/go.mod h1:KWe93zE9D1o94FZ5RNwFwVgaQK1VOXiVxmqh+CedLV8=
github.com/bgentry/speakeasy v0.1.0/go.mod h1:+zsyZBPWlz7T6j88CTgSN5bM796AkVf0kBD4zp0CCIs=
Expand Down
60 changes: 60 additions & 0 deletions mast/cmd.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,10 @@ import (
"strconv"
"regexp"
"errors"
"os/exec"
"runtime"

"github.com/atotto/clipboard"
)

type CmdReturnCode int
Expand Down Expand Up @@ -192,6 +196,20 @@ func CmdProcessor(timeline *Timeline, input string) (CmdReturnCode) {
}

return CmdUnfav(timeline, tootId)
case "open":
tootId, err := CmdHelperGetOpenParams(args)
if err != nil {
return CodeNotOk
}

return CmdOpen(timeline, tootId)
case "share":
tootId, err := CmdHelperGetShareParams(args)
if err != nil {
return CodeNotOk
}

return CmdShare(timeline, tootId)
case "quit", "exit", "bye":
return CodeQuit
}
Expand Down Expand Up @@ -233,6 +251,14 @@ func CmdHelperGetFavParams(args string) (int, error) {
return CmdHelperGetTootIDFromString(args)
}

func CmdHelperGetOpenParams(args string) (int, error) {
return CmdHelperGetTootIDFromString(args)
}

func CmdHelperGetShareParams(args string) (int, error) {
return CmdHelperGetTootIDFromString(args)
}

func CmdToot(timeline *Timeline, content string, inReplyTo int, visibility string) (CmdReturnCode) {
var status string = ""
var spoiler string = ""
Expand Down Expand Up @@ -302,3 +328,37 @@ func CmdUnfav(timeline *Timeline, tootID int) (CmdReturnCode) {

return CodeOk
}

func CmdOpen(timeline *Timeline, tootID int) (CmdReturnCode) {
var err error

url := timeline.Toots[tootID].Status.URL

switch runtime.GOOS {
case "darwin":
err = exec.Command("open", url).Start()
case "linux":
err = exec.Command("xdg-open", url).Start()
case "windows":
err = exec.Command("rundll32", "url.dll,FileProtocolHandler", url).Start()
default:
err = errors.New("Platform not supported!")
}

if err != nil {
return CodeNotOk
}

return CodeOk
}

func CmdShare(timeline *Timeline, tootID int) (CmdReturnCode) {
url := timeline.Toots[tootID].Status.URL

err := clipboard.WriteAll(url)
if err != nil {
return CodeNotOk
}

return CodeOk
}

0 comments on commit f116be5

Please sign in to comment.