From 2e5eeb22ed9a17c6f97b5ea6c301e4ab19c86b0b Mon Sep 17 00:00:00 2001 From: Kasper Seweryn Date: Tue, 8 Sep 2020 00:49:25 +0000 Subject: [PATCH 1/9] Fix #122 --- ui/commands.go | 56 +------------ ui/help-modal.go | 205 +++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 207 insertions(+), 54 deletions(-) create mode 100644 ui/help-modal.go diff --git a/ui/commands.go b/ui/commands.go index f8b7232..8235c15 100644 --- a/ui/commands.go +++ b/ui/commands.go @@ -454,60 +454,8 @@ func cmdUnknownCommand(cmd *Command) { } func cmdHelp(cmd *Command) { - cmd.Reply(`# General -/help - Show this "temporary" help message. -/quit - Quit gomuks. -/clearcache - Clear cache and quit gomuks. -/logout - Log out of Matrix. -/toggle - Temporary command to toggle various UI features. - -Things: rooms, users, baremessages, images, typingnotif, unverified - -# Sending special messages -/me - Send an emote message. -/notice - Send a notice (generally used for bot messages). -/rainbow - Send rainbow text (markdown not supported). -/rainbowme - Send rainbow text in an emote. -/reply [text] - Reply to the selected message. -/react - React to the selected message. -/redact [reason] - Redact the selected message. -/edit - Edit the selected message. - -# Encryption -/fingerprint - View the fingerprint of your device. - -/devices - View the device list of a user. -/device - Show info about a specific device. -/unverify - Un-verify a device. -/blacklist - Blacklist a device. -/verify [fingerprint] - - Verify a device. If the fingerprint is not provided, - interactive emoji verification will be started. -/reset-session - Reset the outbound Megolm session in the current room. - -/import - Import encryption keys -/export - Export encryption keys -/export-room - Export encryption keys for the current room. - -# Rooms -/pm <...> - Create a private chat with the given user(s). -/create [room name] - Create a room. - -/join [server] - Join a room. -/accept - Accept the invite. -/reject - Reject the invite. - -/invite - Invite the given user to the room. -/roomnick - Change your per-room displayname. -/tag - Add the room to . -/untag - Remove the room from . -/tags - List the tags the room is in. -/alias - Add or remove local addresses. - -/leave - Leave the current room. -/kick [reason] - Kick a user. -/ban [reason] - Ban a user. -/unban - Unban a user.`) + view := cmd.MainView + view.ShowModal(NewHelpModal(view)) } func cmdLeave(cmd *Command) { diff --git a/ui/help-modal.go b/ui/help-modal.go new file mode 100644 index 0000000..6588651 --- /dev/null +++ b/ui/help-modal.go @@ -0,0 +1,205 @@ +package ui + +import ( + "strings" + + "maunium.net/go/mauview" + "maunium.net/go/tcell" +) + +type HelpModal struct { + mauview.Component + + container *mauview.Box + + text *mauview.TextView + scrollX int + scrollY int + maxScrollX int + maxScrollY int + textWidth int + textHeight int + + parent *MainView +} + +// There are only math.Min/math.Max for float64 +func Max(a int, b int) int { + if a > b { + return a + } + + return b +} + +func Min(a int, b int) int { + if a < b { + return a + } + + return b +} + +func NewHelpModal(parent *MainView) *HelpModal { + hm := &HelpModal{ + parent: parent, + + scrollX: 0, + scrollY: 0, + maxScrollX: 0, + maxScrollY: 0, + } + + helpText := `# General +/help - Show this "temporary" help message. +/quit - Quit gomuks. +/clearcache - Clear cache and quit gomuks. +/logout - Log out of Matrix. +/toggle - Temporary command to toggle various UI features. + +Things: rooms, users, baremessages, images, typingnotif, unverified + +# Sending special messages +/me - Send an emote message. +/notice - Send a notice (generally used for bot messages). +/rainbow - Send rainbow text (markdown not supported). +/rainbowme - Send rainbow text in an emote. +/reply [text] - Reply to the selected message. +/react - React to the selected message. +/redact [reason] - Redact the selected message. +/edit - Edit the selected message. + +# Encryption +/fingerprint - View the fingerprint of your device. + +/devices - View the device list of a user. +/device - Show info about a specific device. +/unverify - Un-verify a device. +/blacklist - Blacklist a device. +/verify [fingerprint] + - Verify a device. If the fingerprint is not provided, + interactive emoji verification will be started. +/reset-session - Reset the outbound Megolm session in the current room. + +/import - Import encryption keys +/export - Export encryption keys +/export-room - Export encryption keys for the current room. + +# Rooms +/pm <...> - Create a private chat with the given user(s). +/create [room name] - Create a room. + +/join [server] - Join a room. +/accept - Accept the invite. +/reject - Reject the invite. + +/invite - Invite the given user to the room. +/roomnick - Change your per-room displayname. +/tag - Add the room to . +/untag - Remove the room from . +/tags - List the tags the room is in. +/alias - Add or remove local addresses. + +/leave - Leave the current room. +/kick [reason] - Kick a user. +/ban [reason] - Ban a user. +/unban - Unban a user.` + + split := strings.Split(helpText, "\n") + hm.textHeight = len(split) + hm.textWidth = 0 + + for _, line := range split { + hm.textWidth = Max(hm.textWidth, len(line)) + } + + hm.text = mauview.NewTextView(). + SetText(helpText). + SetScrollable(true). + SetWrap(false) + + flex := mauview.NewFlex(). + SetDirection(mauview.FlexRow). + AddProportionalComponent(hm.text, 1) + + hm.container = mauview.NewBox(flex). + SetBorder(true). + SetTitle("Help"). + SetBlurCaptureFunc(func() bool { + hm.parent.HideModal() + return true + }) + + hm.Component = mauview.Center(hm.container, 0, 0). + SetAlwaysFocusChild(true) + + return hm +} + +func (hm *HelpModal) Focus() { + hm.container.Focus() +} + +func (hm *HelpModal) Blur() { + hm.container.Blur() +} + +func (hm *HelpModal) Draw(screen mauview.Screen) { + width, height := screen.Size() + + width /= 2 + if width < 42 { + width = 42 + } + + if height > 40 { + height -= 20 + } else if height > 30 { + height -= 10 + } else if height > 20 { + height -= 5 + } + + oldMaxScrollY := hm.maxScrollY + hm.maxScrollY = hm.textHeight - height + 2 + hm.maxScrollX = hm.textWidth - width + 2 + + if hm.maxScrollY != oldMaxScrollY { + // Reset the scroll + // NOTE: Workarounds a problem where we can no longer scroll + // due to hm.scrollY being too big. + hm.scrollY = 0 + hm.scrollX = 0 + hm.text.ScrollTo(hm.scrollY, hm.scrollX) + } + + hm.Component = mauview.Center(hm.container, width, height). + SetAlwaysFocusChild(true) + + hm.Component.Draw(screen) +} + +func (hm *HelpModal) OnKeyEvent(event mauview.KeyEvent) bool { + switch event.Key() { + case tcell.KeyUp: + hm.scrollY = Max(0, hm.scrollY-1) + hm.text.ScrollTo(hm.scrollY, hm.scrollX) + return true + case tcell.KeyDown: + hm.scrollY = Min(hm.maxScrollY, hm.scrollY+1) + hm.text.ScrollTo(hm.scrollY, hm.scrollX) + return true + + case tcell.KeyLeft: + hm.scrollX = Max(0, hm.scrollX-1) + hm.text.ScrollTo(hm.scrollY, hm.scrollX) + return true + case tcell.KeyRight: + hm.scrollX = Min(hm.maxScrollX, hm.scrollX+1) + hm.text.ScrollTo(hm.scrollY, hm.scrollX) + return true + } + + hm.parent.HideModal() + return true +} From 153aa34f2bee5dfd13c28c059c2e30292cf31f4a Mon Sep 17 00:00:00 2001 From: Tulir Asokan Date: Sun, 13 Sep 2020 17:16:47 +0300 Subject: [PATCH 2/9] Simplify HelpModal --- go.mod | 2 +- go.sum | 2 + ui/help-modal.go | 145 ++++++++--------------------------------------- 3 files changed, 26 insertions(+), 123 deletions(-) diff --git a/go.mod b/go.mod index 3048822..63a1b82 100644 --- a/go.mod +++ b/go.mod @@ -24,6 +24,6 @@ require ( gopkg.in/vansante/go-ffprobe.v2 v2.0.2 gopkg.in/yaml.v2 v2.3.0 maunium.net/go/mautrix v0.7.6 - maunium.net/go/mauview v0.1.1 + maunium.net/go/mauview v0.1.2 maunium.net/go/tcell v0.2.0 ) diff --git a/go.sum b/go.sum index 4572c2b..4ffbc00 100644 --- a/go.sum +++ b/go.sum @@ -121,5 +121,7 @@ maunium.net/go/mautrix v0.7.6 h1:jB9oCimPq0mVyolwQBC/9N1fu21AU+Ryq837cLf4gOo= maunium.net/go/mautrix v0.7.6/go.mod h1:Va/74MijqaS0DQ3aUqxmFO54/PMfr1LVsCOcGRHbYmo= maunium.net/go/mauview v0.1.1 h1:wfTXyPx3LGAGpTskh+UbBv/QItUWnEpaneHmywoYnfY= maunium.net/go/mauview v0.1.1/go.mod h1:3QBUiuLct9moP1LgDhCGIg0Ovxn38Bd2sGndnUOuj4o= +maunium.net/go/mauview v0.1.2 h1:6Y3GpyckIlzCNkry6k025YhWg8oh5XJFj3RAMf4VwWo= +maunium.net/go/mauview v0.1.2/go.mod h1:3QBUiuLct9moP1LgDhCGIg0Ovxn38Bd2sGndnUOuj4o= maunium.net/go/tcell v0.2.0 h1:1Q0kN3wCOGAIGu1r3QHADsjSUOPDylKREvCv3EzJpVg= maunium.net/go/tcell v0.2.0/go.mod h1:9Apcb3lNNS6C6lCqKT9UFp7BTRzHXfWE+/tgufsAMho= diff --git a/ui/help-modal.go b/ui/help-modal.go index 6588651..41d644e 100644 --- a/ui/help-modal.go +++ b/ui/help-modal.go @@ -1,68 +1,23 @@ package ui import ( - "strings" - - "maunium.net/go/mauview" "maunium.net/go/tcell" + + "maunium.net/go/gomuks/debug" + "maunium.net/go/mauview" ) -type HelpModal struct { - mauview.Component - - container *mauview.Box - - text *mauview.TextView - scrollX int - scrollY int - maxScrollX int - maxScrollY int - textWidth int - textHeight int - - parent *MainView -} - -// There are only math.Min/math.Max for float64 -func Max(a int, b int) int { - if a > b { - return a - } - - return b -} - -func Min(a int, b int) int { - if a < b { - return a - } - - return b -} - -func NewHelpModal(parent *MainView) *HelpModal { - hm := &HelpModal{ - parent: parent, - - scrollX: 0, - scrollY: 0, - maxScrollX: 0, - maxScrollY: 0, - } - - helpText := `# General -/help - Show this "temporary" help message. +const helpText = `# General +/help - Show this help dialog. /quit - Quit gomuks. /clearcache - Clear cache and quit gomuks. /logout - Log out of Matrix. /toggle - Temporary command to toggle various UI features. -Things: rooms, users, baremessages, images, typingnotif, unverified - # Sending special messages /me - Send an emote message. /notice - Send a notice (generally used for bot messages). -/rainbow - Send rainbow text (markdown not supported). +/rainbow - Send rainbow text. /rainbowme - Send rainbow text in an emote. /reply [text] - Reply to the selected message. /react - React to the selected message. @@ -105,101 +60,47 @@ Things: rooms, users, baremessages, images, typingnotif, unverified /ban [reason] - Ban a user. /unban - Unban a user.` - split := strings.Split(helpText, "\n") - hm.textHeight = len(split) - hm.textWidth = 0 +type HelpModal struct { + mauview.FocusableComponent + parent *MainView +} - for _, line := range split { - hm.textWidth = Max(hm.textWidth, len(line)) - } +func NewHelpModal(parent *MainView) *HelpModal { + hm := &HelpModal{parent: parent} - hm.text = mauview.NewTextView(). + text := mauview.NewTextView(). SetText(helpText). SetScrollable(true). SetWrap(false) - flex := mauview.NewFlex(). - SetDirection(mauview.FlexRow). - AddProportionalComponent(hm.text, 1) - - hm.container = mauview.NewBox(flex). + box := mauview.NewBox(text). SetBorder(true). SetTitle("Help"). SetBlurCaptureFunc(func() bool { hm.parent.HideModal() return true }) + box.Focus() - hm.Component = mauview.Center(hm.container, 0, 0). - SetAlwaysFocusChild(true) + hm.FocusableComponent = mauview.FractionalCenter(box, 42, 10, 0.5, 0.5) return hm } func (hm *HelpModal) Focus() { - hm.container.Focus() + debug.Print("focus") + hm.FocusableComponent.Focus() } func (hm *HelpModal) Blur() { - hm.container.Blur() -} - -func (hm *HelpModal) Draw(screen mauview.Screen) { - width, height := screen.Size() - - width /= 2 - if width < 42 { - width = 42 - } - - if height > 40 { - height -= 20 - } else if height > 30 { - height -= 10 - } else if height > 20 { - height -= 5 - } - - oldMaxScrollY := hm.maxScrollY - hm.maxScrollY = hm.textHeight - height + 2 - hm.maxScrollX = hm.textWidth - width + 2 - - if hm.maxScrollY != oldMaxScrollY { - // Reset the scroll - // NOTE: Workarounds a problem where we can no longer scroll - // due to hm.scrollY being too big. - hm.scrollY = 0 - hm.scrollX = 0 - hm.text.ScrollTo(hm.scrollY, hm.scrollX) - } - - hm.Component = mauview.Center(hm.container, width, height). - SetAlwaysFocusChild(true) - - hm.Component.Draw(screen) + debug.Print("blur") + hm.FocusableComponent.Blur() } func (hm *HelpModal) OnKeyEvent(event mauview.KeyEvent) bool { - switch event.Key() { - case tcell.KeyUp: - hm.scrollY = Max(0, hm.scrollY-1) - hm.text.ScrollTo(hm.scrollY, hm.scrollX) - return true - case tcell.KeyDown: - hm.scrollY = Min(hm.maxScrollY, hm.scrollY+1) - hm.text.ScrollTo(hm.scrollY, hm.scrollX) - return true - - case tcell.KeyLeft: - hm.scrollX = Max(0, hm.scrollX-1) - hm.text.ScrollTo(hm.scrollY, hm.scrollX) - return true - case tcell.KeyRight: - hm.scrollX = Min(hm.maxScrollX, hm.scrollX+1) - hm.text.ScrollTo(hm.scrollY, hm.scrollX) + if event.Key() == tcell.KeyEscape || event.Rune() == 'q' { + hm.parent.HideModal() return true } - - hm.parent.HideModal() - return true + return hm.FocusableComponent.OnKeyEvent(event) } From f0a40ec20bd82f62b667dfadd8c614f2dfae9870 Mon Sep 17 00:00:00 2001 From: Tulir Asokan Date: Sun, 13 Sep 2020 17:18:26 +0300 Subject: [PATCH 3/9] Remove debug prints --- ui/help-modal.go | 11 ----------- 1 file changed, 11 deletions(-) diff --git a/ui/help-modal.go b/ui/help-modal.go index 41d644e..98e73fc 100644 --- a/ui/help-modal.go +++ b/ui/help-modal.go @@ -3,7 +3,6 @@ package ui import ( "maunium.net/go/tcell" - "maunium.net/go/gomuks/debug" "maunium.net/go/mauview" ) @@ -87,16 +86,6 @@ func NewHelpModal(parent *MainView) *HelpModal { return hm } -func (hm *HelpModal) Focus() { - debug.Print("focus") - hm.FocusableComponent.Focus() -} - -func (hm *HelpModal) Blur() { - debug.Print("blur") - hm.FocusableComponent.Blur() -} - func (hm *HelpModal) OnKeyEvent(event mauview.KeyEvent) bool { if event.Key() == tcell.KeyEscape || event.Rune() == 'q' { hm.parent.HideModal() From 180ecc36cc92610711a666e4c9abf4c5a4ed184e Mon Sep 17 00:00:00 2001 From: Tulir Asokan Date: Fri, 18 Sep 2020 21:12:59 +0300 Subject: [PATCH 4/9] Improve detecting login flows supported by homeserver --- matrix/matrix.go | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/matrix/matrix.go b/matrix/matrix.go index d54ad82..bac95b9 100644 --- a/matrix/matrix.go +++ b/matrix/matrix.go @@ -252,13 +252,14 @@ func (c *Container) Login(user, password string) error { if err != nil { return err } - if len(resp.Flows) == 1 && resp.Flows[0].Type == "m.login.password" { - return c.PasswordLogin(user, password) - } else if len(resp.Flows) == 2 && resp.Flows[0].Type == "m.login.sso" && resp.Flows[1].Type == "m.login.token" { - return c.SingleSignOn() - } else { - return fmt.Errorf("no supported login flows") + for _, flow := range resp.Flows { + if flow.Type == "m.login.password" { + return c.PasswordLogin(user, password) + } else if flow.Type == "m.login.sso" { + return c.SingleSignOn() + } } + return fmt.Errorf("no supported login flows") } // Logout revokes the access token, stops the syncer and calls the OnLogout() method of the UI. From 22b982d9631b5e66ba31efa64c2009097578f879 Mon Sep 17 00:00:00 2001 From: Midov Date: Fri, 2 Oct 2020 17:22:00 +0200 Subject: [PATCH 5/9] open reap children --- lib/open/open.go | 10 +++++++++- ui/message-view.go | 1 + ui/room-view.go | 1 + 3 files changed, 11 insertions(+), 1 deletion(-) diff --git a/lib/open/open.go b/lib/open/open.go index 4a92706..935018f 100644 --- a/lib/open/open.go +++ b/lib/open/open.go @@ -20,8 +20,16 @@ package open import ( "os/exec" + "maunium.net/go/gomuks/debug" ) func Open(input string) error { - return exec.Command("xdg-open", input).Start() + cmd := exec.Command("xdg-open", input) + err := cmd.Start() + if err != nil { + debug.Print("xdg-open error:", err) + } else { + go cmd.Wait() + } + return err } diff --git a/ui/message-view.go b/ui/message-view.go index 2410cd5..a2989ff 100644 --- a/ui/message-view.go +++ b/ui/message-view.go @@ -360,6 +360,7 @@ func (view *MessageView) SetSelected(message *messages.UIMessage) { func (view *MessageView) handleMessageClick(message *messages.UIMessage, mod tcell.ModMask) bool { if msg, ok := message.Renderer.(*messages.FileMessage); ok && mod > 0 && !msg.Thumbnail.IsEmpty() { + debug.Print("Opening thumbnail", msg.ThumbnailPath()) open.Open(msg.ThumbnailPath()) // No need to re-render return false diff --git a/ui/room-view.go b/ui/room-view.go index 13ba700..7975106 100644 --- a/ui/room-view.go +++ b/ui/room-view.go @@ -713,6 +713,7 @@ func (view *RoomView) Download(url id.ContentURI, file *attachment.EncryptedFile view.AddServiceMessage(fmt.Sprintf("File downloaded to %s", path)) view.parent.parent.Render() if openFile { + debug.Print("Opening file", path) open.Open(path) } } From 1437a799e57cdcffc54ca2267406f725106ee50a Mon Sep 17 00:00:00 2001 From: Tulir Asokan Date: Tue, 20 Oct 2020 13:29:50 +0300 Subject: [PATCH 6/9] Don't panic on empty code block. Fixes #237 --- ui/messages/html/parser.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ui/messages/html/parser.go b/ui/messages/html/parser.go index c45e8ce..d7ed66c 100644 --- a/ui/messages/html/parser.go +++ b/ui/messages/html/parser.go @@ -320,7 +320,7 @@ func (parser *htmlParser) syntaxHighlight(text, language string) Entity { func (parser *htmlParser) codeblockToEntity(node *html.Node) Entity { lang := "plaintext" // TODO allow disabling syntax highlighting - if node.FirstChild.Type == html.ElementNode && node.FirstChild.Data == "code" { + if node.FirstChild != nil && node.FirstChild.Type == html.ElementNode && node.FirstChild.Data == "code" { node = node.FirstChild attr := parser.getAttribute(node, "class") for _, class := range strings.Split(attr, " ") { From c6185780f4f8d043834de3f5940be78915b89117 Mon Sep 17 00:00:00 2001 From: Tulir Asokan Date: Fri, 23 Oct 2020 11:35:34 +0300 Subject: [PATCH 7/9] Bump version to 0.2.1 --- deb/DEBIAN/control | 2 +- gomuks.go | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/deb/DEBIAN/control b/deb/DEBIAN/control index f80c9f7..a382777 100644 --- a/deb/DEBIAN/control +++ b/deb/DEBIAN/control @@ -1,5 +1,5 @@ Package: gomuks -Version: 0.1.1-1 +Version: 0.2.1-1 Section: net Priority: optional Architecture: amd64 diff --git a/gomuks.go b/gomuks.go index 104e7c4..6601408 100644 --- a/gomuks.go +++ b/gomuks.go @@ -56,7 +56,7 @@ func NewGomuks(uiProvider ifc.UIProvider, configDir, dataDir, cacheDir, download } func (gmx *Gomuks) Version() string { - return "v0.2.0" + return "v0.2.1" } // Save saves the active session and message history. From d103d005a3b712ae40ac61dd4896a689b5b5a011 Mon Sep 17 00:00:00 2001 From: Tulir Asokan Date: Fri, 23 Oct 2020 12:02:42 +0300 Subject: [PATCH 8/9] Update deps and stop using github.com/pkg/errors --- go.mod | 17 ++++++++--------- go.sum | 20 ++++++++++++++++++++ matrix/crypto.go | 7 +++---- matrix/matrix.go | 18 +++++++++--------- matrix/mediainfo.go | 12 ++++++------ matrix/rooms/roomcache.go | 15 ++++++++------- ui/commands.go | 4 ++-- ui/room-view.go | 2 +- 8 files changed, 57 insertions(+), 38 deletions(-) diff --git a/go.mod b/go.mod index 63a1b82..e2da18e 100644 --- a/go.mod +++ b/go.mod @@ -3,27 +3,26 @@ module maunium.net/go/gomuks go 1.14 require ( - github.com/alecthomas/chroma v0.8.0 + github.com/alecthomas/chroma v0.8.1 github.com/disintegration/imaging v1.6.2 github.com/gabriel-vasile/mimetype v1.1.1 - github.com/kyokomi/emoji v2.2.2+incompatible - github.com/lithammer/fuzzysearch v1.1.0 + github.com/kyokomi/emoji/v2 v2.2.5 + github.com/lithammer/fuzzysearch v1.1.1 github.com/lucasb-eyer/go-colorful v1.0.3 github.com/mattn/go-runewidth v0.0.9 github.com/nu7hatch/gouuid v0.0.0-20131221200532-179d4d0c4d8d // indirect github.com/petermattis/goid v0.0.0-20180202154549-b0b1615b78e5 // indirect - github.com/pkg/errors v0.9.1 github.com/rivo/uniseg v0.1.0 github.com/russross/blackfriday/v2 v2.0.1 github.com/sasha-s/go-deadlock v0.2.0 - github.com/zyedidia/clipboard v0.0.0-20200421031010-7c45b8673834 - go.etcd.io/bbolt v1.3.4 - golang.org/x/image v0.0.0-20200430140353-33d19683fad8 - golang.org/x/net v0.0.0-20200822124328-c89045814202 + github.com/zyedidia/clipboard v1.0.3 + go.etcd.io/bbolt v1.3.5 + golang.org/x/image v0.0.0-20200927104501-e162460cd6b5 + golang.org/x/net v0.0.0-20201022231255-08b38378de70 gopkg.in/toast.v1 v1.0.0-20180812000517-0a84660828b2 gopkg.in/vansante/go-ffprobe.v2 v2.0.2 gopkg.in/yaml.v2 v2.3.0 - maunium.net/go/mautrix v0.7.6 + maunium.net/go/mautrix v0.7.13 maunium.net/go/mauview v0.1.2 maunium.net/go/tcell v0.2.0 ) diff --git a/go.sum b/go.sum index 4ffbc00..ec29e65 100644 --- a/go.sum +++ b/go.sum @@ -3,6 +3,8 @@ github.com/alecthomas/assert v0.0.0-20170929043011-405dbfeb8e38 h1:smF2tmSOzy2Mm github.com/alecthomas/assert v0.0.0-20170929043011-405dbfeb8e38/go.mod h1:r7bzyVFMNntcxPZXK3/+KdruV1H5KSlyVY0gc+NgInI= github.com/alecthomas/chroma v0.8.0 h1:HS+HE97sgcqjQGu5uVr8jIE55Mmh5UeQ7kckAhHg2pY= github.com/alecthomas/chroma v0.8.0/go.mod h1:sko8vR34/90zvl5QdcUdvzL3J8NKjAUx9va9jPuFNoM= +github.com/alecthomas/chroma v0.8.1 h1:ym20sbvyC6RXz45u4qDglcgr8E313oPROshcuCHqiEE= +github.com/alecthomas/chroma v0.8.1/go.mod h1:sko8vR34/90zvl5QdcUdvzL3J8NKjAUx9va9jPuFNoM= github.com/alecthomas/colour v0.0.0-20160524082231-60882d9e2721 h1:JHZL0hZKJ1VENNfmXvHbgYlbUOvpzYzvy2aZU5gXVeo= github.com/alecthomas/colour v0.0.0-20160524082231-60882d9e2721/go.mod h1:QO9JBoKquHd+jz9nshCh40fOfO+JzsoXy8qTHF68zU0= github.com/alecthomas/kong v0.2.4/go.mod h1:kQOmtJgV+Lb4aj+I2LEn40cbtawdWJ9Y8QLq+lElKxE= @@ -25,10 +27,14 @@ github.com/gdamore/encoding v1.0.0/go.mod h1:alR0ol34c49FCSBLjhosxzcPHQbf2trDkoo github.com/gorilla/mux v1.7.4/go.mod h1:DVbg23sWSpFRCP0SfiEN6jmj59UnW/n46BH5rLB71So= github.com/kyokomi/emoji v2.2.2+incompatible h1:gaQFbK2+uSxOR4iGZprJAbpmtqTrHhSdgOyIMD6Oidc= github.com/kyokomi/emoji v2.2.2+incompatible/go.mod h1:mZ6aGCD7yk8j6QY6KICwnZ2pxoszVseX1DNoGtU2tBA= +github.com/kyokomi/emoji/v2 v2.2.5 h1:sxOmQKMB3ICTDWiJbtMHUnKn1HFHjGk9av0+IYWVovI= +github.com/kyokomi/emoji/v2 v2.2.5/go.mod h1:JUcn42DTdsXJo1SWanHh4HKDEyPaR5CqkmoirZZP9qE= github.com/lib/pq v1.7.0 h1:h93mCPfUSkaul3Ka/VG8uZdmW1uMHDGxzu0NWHuJmHY= github.com/lib/pq v1.7.0/go.mod h1:AlVN5x4E4T544tWzH6hKfbfQvm3HdbOxrmggDNAPY9o= github.com/lithammer/fuzzysearch v1.1.0 h1:go9v8tLCrNTTlH42OAaq4eHFe81TDHEnlrMEb6R4f+A= github.com/lithammer/fuzzysearch v1.1.0/go.mod h1:Bqx4wo8lTOFcJr3ckpY6HA9lEIOO0H5HrkJ5CsN56HQ= +github.com/lithammer/fuzzysearch v1.1.1 h1:8F9OAV2xPuYblToVohjanztdnPjbtA0MLgMvDKQ0Z08= +github.com/lithammer/fuzzysearch v1.1.1/go.mod h1:H2bng+w5gsR7NlfIJM8ElGZI0sX6C/9uzGqicVXGU6c= github.com/lucasb-eyer/go-colorful v1.0.3 h1:QIbQXiugsb+q10B+MI+7DI1oQLdmnep86tWFlaaUAac= github.com/lucasb-eyer/go-colorful v1.0.3/go.mod h1:R4dSotOR9KMtayYi1e77YzuveK+i7ruzyGqttikkLy0= github.com/mattn/go-colorable v0.1.6/go.mod h1:u6P/XSegPjTcexA+o6vUJrdnUu04hMope9wVRipJSqc= @@ -74,10 +80,14 @@ github.com/tidwall/sjson v1.1.1 h1:7h1vk049Jnd5EH9NyzNiEuwYW4b5qgreBbqRC19AS3U= github.com/tidwall/sjson v1.1.1/go.mod h1:yvVuSnpEQv5cYIrO+AT6kw4QVfd5SDZoGIS7/5+fZFs= github.com/zyedidia/clipboard v0.0.0-20200421031010-7c45b8673834 h1:0nOfq3JwYRiY3+nwfWVQYEaXDmGCQgj3RKoqTifLzP4= github.com/zyedidia/clipboard v0.0.0-20200421031010-7c45b8673834/go.mod h1:zykFnZUXX0ErxqvYLUFEq7QDJKId8rmh2FgD0/Y8cjA= +github.com/zyedidia/clipboard v1.0.3 h1:F/nCDVYMdbDWTmY8s8cJl0tnwX32q96IF09JHM14bUI= +github.com/zyedidia/clipboard v1.0.3/go.mod h1:zykFnZUXX0ErxqvYLUFEq7QDJKId8rmh2FgD0/Y8cjA= github.com/zyedidia/poller v1.0.1 h1:Tt9S3AxAjXwWGNiC2TUdRJkQDZSzCBNVQ4xXiQ7440s= github.com/zyedidia/poller v1.0.1/go.mod h1:vZXJOHGDcuK08GXhF6IAY0ZFd2WcgOR5DOTp84Uk5eE= go.etcd.io/bbolt v1.3.4 h1:hi1bXHMVrlQh6WwxAy+qZCV/SYIlqo+Ushwdpa4tAKg= go.etcd.io/bbolt v1.3.4/go.mod h1:G5EMThwa9y8QZGBClrRx5EY+Yw9kAhnjy3bSjsnlVTQ= +go.etcd.io/bbolt v1.3.5 h1:XAzx9gjCb0Rxj7EoqcClPD1d5ZBxZJk0jbuoPHenBt0= +go.etcd.io/bbolt v1.3.5/go.mod h1:G5EMThwa9y8QZGBClrRx5EY+Yw9kAhnjy3bSjsnlVTQ= golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2 h1:VklqNMn3ovrHsnt90PveolxSbWFaJdECFbxSq0Mqo2M= golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w= golang.org/x/crypto v0.0.0-20200622213623-75b288015ac9 h1:psW17arqaxU48Z5kZ0CQnkZWQJsqcURM6tKiBApRjXI= @@ -85,6 +95,8 @@ golang.org/x/crypto v0.0.0-20200622213623-75b288015ac9/go.mod h1:LzIPMQfyMNhhGPh golang.org/x/image v0.0.0-20191009234506-e7c1f5e7dbb8/go.mod h1:FeLwcggjj3mMvU+oOTbSwawSJRM1uh48EjtB4UJZlP0= golang.org/x/image v0.0.0-20200430140353-33d19683fad8 h1:6WW6V3x1P/jokJBpRQYUJnMHRP6isStQwCozxnU7XQw= golang.org/x/image v0.0.0-20200430140353-33d19683fad8/go.mod h1:FeLwcggjj3mMvU+oOTbSwawSJRM1uh48EjtB4UJZlP0= +golang.org/x/image v0.0.0-20200927104501-e162460cd6b5 h1:QelT11PB4FXiDEXucrfNckHoFxwt8USGY1ajP1ZF5lM= +golang.org/x/image v0.0.0-20200927104501-e162460cd6b5/go.mod h1:FeLwcggjj3mMvU+oOTbSwawSJRM1uh48EjtB4UJZlP0= golang.org/x/net v0.0.0-20180218175443-cbe0f9307d01/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4= golang.org/x/net v0.0.0-20190404232315-eb5bcb51f2a3/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg= golang.org/x/net v0.0.0-20200202094626-16171245cfb2/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s= @@ -93,6 +105,8 @@ golang.org/x/net v0.0.0-20200602114024-627f9648deb9 h1:pNX+40auqi2JqRfOP1akLGtYc golang.org/x/net v0.0.0-20200602114024-627f9648deb9/go.mod h1:qpuaurCH72eLCgpAm/N6yyVIVM9cpaDIP3A8BGJEC5A= golang.org/x/net v0.0.0-20200822124328-c89045814202 h1:VvcQYSHwXgi7W+TpUR6A9g6Up98WAHf3f/ulnJ62IyA= golang.org/x/net v0.0.0-20200822124328-c89045814202/go.mod h1:/O7V0waA8r7cgGh81Ro3o1hOxt32SMVPicZroKQ2sZA= +golang.org/x/net v0.0.0-20201022231255-08b38378de70 h1:Z6x4N9mAi4oF0TbHweCsH618MO6OI6UFgV0FP5n0wBY= +golang.org/x/net v0.0.0-20201022231255-08b38378de70/go.mod h1:sp8m0HH+o8qH0wwXwYZr8TS3Oi6o0r6Gce1SSxlDquU= golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= golang.org/x/sys v0.0.0-20190412213103-97732733099d/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20200116001909-b77594299b42/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= @@ -102,9 +116,13 @@ golang.org/x/sys v0.0.0-20200323222414-85ca7c5b95cd/go.mod h1:h1NjWce9XRLGQEsW7w golang.org/x/sys v0.0.0-20200413165638-669c56c373c4/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20200501145240-bc7a7d42d5c3 h1:5B6i6EAiSYyejWfvc5Rc9BbI3rzIsrrXfAQBWnYfn+w= golang.org/x/sys v0.0.0-20200501145240-bc7a7d42d5c3/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= +golang.org/x/sys v0.0.0-20200930185726-fdedc70b468f h1:+Nyd8tzPX9R7BWHguqsrbFdRx3WQ/1ib8I44HXV5yTA= +golang.org/x/sys v0.0.0-20200930185726-fdedc70b468f/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ= golang.org/x/text v0.3.2 h1:tW2bmiBqwgJj/UpqtC8EpXEZVYOwU0yG4iWbprSVAcs= golang.org/x/text v0.3.2/go.mod h1:bEr9sfX3Q8Zfm5fL9x+3itogRgK3+ptLWKqgva+5dAk= +golang.org/x/text v0.3.3 h1:cokOdA+Jmi5PJGXLlLllQSgYigAEfHXJAERHVMaCc2k= +golang.org/x/text v0.3.3/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ= golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ= gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405 h1:yhCVgyC4o1eVCa2tZl7eS0r+SDo693bJlVdllGtEeKM= gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= @@ -119,6 +137,8 @@ gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C maunium.net/go/maulogger/v2 v2.1.1/go.mod h1:TYWy7wKwz/tIXTpsx8G3mZseIRiC5DoMxSZazOHy68A= maunium.net/go/mautrix v0.7.6 h1:jB9oCimPq0mVyolwQBC/9N1fu21AU+Ryq837cLf4gOo= maunium.net/go/mautrix v0.7.6/go.mod h1:Va/74MijqaS0DQ3aUqxmFO54/PMfr1LVsCOcGRHbYmo= +maunium.net/go/mautrix v0.7.13 h1:qfnvLxvQafvLgHbdZF/+9qs9gyArYf8fUnzfQbjgQaU= +maunium.net/go/mautrix v0.7.13/go.mod h1:Jn0ijwXwMFvJFIN9IljirIVKpZQbZP/Dk7pdX2qDmXk= maunium.net/go/mauview v0.1.1 h1:wfTXyPx3LGAGpTskh+UbBv/QItUWnEpaneHmywoYnfY= maunium.net/go/mauview v0.1.1/go.mod h1:3QBUiuLct9moP1LgDhCGIg0Ovxn38Bd2sGndnUOuj4o= maunium.net/go/mauview v0.1.2 h1:6Y3GpyckIlzCNkry6k025YhWg8oh5XJFj3RAMf4VwWo= diff --git a/matrix/crypto.go b/matrix/crypto.go index c549e8a..62a4266 100644 --- a/matrix/crypto.go +++ b/matrix/crypto.go @@ -19,10 +19,9 @@ package matrix import ( + "fmt" "path/filepath" - "github.com/pkg/errors" - "maunium.net/go/mautrix/crypto" "maunium.net/go/gomuks/debug" @@ -53,14 +52,14 @@ func isBadEncryptError(err error) bool { func (c *Container) initCrypto() error { cryptoStore, err := crypto.NewGobStore(filepath.Join(c.config.DataDir, "crypto.gob")) if err != nil { - return errors.Wrap(err, "failed to open crypto store") + return fmt.Errorf("failed to open crypto store: %w", err) } crypt := crypto.NewOlmMachine(c.client, cryptoLogger{}, cryptoStore, c.config.Rooms) crypt.AllowUnverifiedDevices = !c.config.SendToVerifiedOnly c.crypto = crypt err = c.crypto.Load() if err != nil { - return errors.Wrap(err, "failed to create olm machine") + return fmt.Errorf("failed to create olm machine: %w", err) } return nil } diff --git a/matrix/matrix.go b/matrix/matrix.go index bac95b9..19ba419 100644 --- a/matrix/matrix.go +++ b/matrix/matrix.go @@ -32,8 +32,7 @@ import ( "runtime" dbg "runtime/debug" "time" - - "github.com/pkg/errors" + "errors" "maunium.net/go/mautrix" "maunium.net/go/mautrix/crypto/attachment" @@ -115,7 +114,7 @@ func (c *Container) InitClient() error { var err error c.client, err = mautrix.NewClient(c.config.HS, mxid, accessToken) if err != nil { - return errors.Wrap(err, "failed to create mautrix client") + return fmt.Errorf("failed to create mautrix client: %w", err) } c.client.UserAgent = fmt.Sprintf("gomuks %s (with mautrix-go %s)", c.gmx.Version(), mautrix.Version) c.client.Logger = mxLogger{} @@ -123,13 +122,13 @@ func (c *Container) InitClient() error { err = c.initCrypto() if err != nil { - return errors.Wrap(err, "failed to initialize crypto") + return fmt.Errorf("failed to initialize crypto: %w", err) } if c.history == nil { c.history, err = NewHistoryManager(c.config.HistoryPath) if err != nil { - return errors.Wrap(err, "failed to initialize history") + return fmt.Errorf("failed to initialize history: %w", err) } } @@ -430,8 +429,9 @@ func (c *Container) Start() { return default: if err := c.client.Sync(); err != nil { - if httpErr, ok := err.(mautrix.HTTPError); ok && httpErr.Code == http.StatusUnauthorized { + if errors.Is(err, mautrix.MUnknownToken) { debug.Print("Sync() errored with ", err, " -> logging out") + // TODO support soft logout c.Logout() } else { debug.Print("Sync() errored", err) @@ -944,7 +944,7 @@ func (c *Container) UploadMedia(path string, encrypt bool) (*ifc.UploadedMediaIn var err error path, err = filepath.Abs(path) if err != nil { - return nil, errors.Wrap(err, "failed to get absolute path") + return nil, fmt.Errorf("failed to get absolute path: %w", err) } msgtype, info, err := getMediaInfo(path) @@ -954,12 +954,12 @@ func (c *Container) UploadMedia(path string, encrypt bool) (*ifc.UploadedMediaIn file, err := os.Open(path) if err != nil { - return nil, errors.Wrap(err, "failed to open file") + return nil, fmt.Errorf("failed to open file: %w", err) } stat, err := file.Stat() if err != nil { - return nil, errors.Wrap(err, "failed to get file info") + return nil, fmt.Errorf("failed to get file info: %w", err) } uploadFileName := stat.Name() diff --git a/matrix/mediainfo.go b/matrix/mediainfo.go index 6f6d51f..5de4171 100644 --- a/matrix/mediainfo.go +++ b/matrix/mediainfo.go @@ -25,22 +25,22 @@ import ( "time" "github.com/gabriel-vasile/mimetype" - "github.com/pkg/errors" "gopkg.in/vansante/go-ffprobe.v2" - "maunium.net/go/gomuks/debug" "maunium.net/go/mautrix/event" + + "maunium.net/go/gomuks/debug" ) func getImageInfo(path string) (event.FileInfo, error) { var info event.FileInfo file, err := os.Open(path) if err != nil { - return info, errors.Wrap(err, "failed to open image to get info") + return info, fmt.Errorf("failed to open image to get info: %w", err) } cfg, _, err := image.DecodeConfig(file) if err != nil { - return info, errors.Wrap(err, "failed to get image info") + return info, fmt.Errorf("failed to get image info: %w", err) } info.Width = cfg.Width info.Height = cfg.Height @@ -53,7 +53,7 @@ func getFFProbeInfo(mimeClass, path string) (msgtype event.MessageType, info eve var probedInfo *ffprobe.ProbeData probedInfo, err = ffprobe.ProbeURL(ctx, path) if err != nil { - err = errors.Wrap(err, fmt.Sprintf("failed to get %s info with ffprobe", mimeClass)) + err = fmt.Errorf("failed to get %s info with ffprobe: %w", mimeClass, err) return } if mimeClass == "audio" { @@ -78,7 +78,7 @@ func getMediaInfo(path string) (msgtype event.MessageType, info event.FileInfo, var mime *mimetype.MIME mime, err = mimetype.DetectFile(path) if err != nil { - err = errors.Wrap(err, "failed to get content type") + err = fmt.Errorf("failed to get content type: %w", err) return } diff --git a/matrix/rooms/roomcache.go b/matrix/rooms/roomcache.go index 168278b..b97b61c 100644 --- a/matrix/rooms/roomcache.go +++ b/matrix/rooms/roomcache.go @@ -19,16 +19,17 @@ package rooms import ( "compress/gzip" "encoding/gob" + "fmt" "os" "path/filepath" "time" - "github.com/pkg/errors" sync "github.com/sasha-s/go-deadlock" - "maunium.net/go/gomuks/debug" "maunium.net/go/mautrix/event" "maunium.net/go/mautrix/id" + + "maunium.net/go/gomuks/debug" ) // RoomCache contains room state info in a hashmap and linked list. @@ -114,14 +115,14 @@ func (cache *RoomCache) LoadList() error { if os.IsNotExist(err) { return nil } - return errors.Wrap(err, "failed to open room list file for reading") + return fmt.Errorf("failed to open room list file for reading: %w", err) } defer debugPrintError(file.Close, "Failed to close room list file after reading") // Open gzip reader for room list file cmpReader, err := gzip.NewReader(file) if err != nil { - return errors.Wrap(err, "failed to read gzip room list") + return fmt.Errorf("failed to read gzip room list: %w", err) } defer debugPrintError(cmpReader.Close, "Failed to close room list gzip reader") @@ -131,7 +132,7 @@ func (cache *RoomCache) LoadList() error { var size int err = dec.Decode(&size) if err != nil { - return errors.Wrap(err, "failed to read size of room list") + return fmt.Errorf("failed to read size of room list: %w", err) } // Read list @@ -167,7 +168,7 @@ func (cache *RoomCache) SaveList() error { // Open room list file file, err := os.OpenFile(cache.listPath, os.O_WRONLY|os.O_CREATE, 0600) if err != nil { - return errors.Wrap(err, "failed to open room list file for writing") + return fmt.Errorf("failed to open room list file for writing: %w", err) } defer debugPrintError(file.Close, "Failed to close room list file after writing") @@ -180,7 +181,7 @@ func (cache *RoomCache) SaveList() error { // Write number of items in list err = enc.Encode(len(cache.Map)) if err != nil { - return errors.Wrap(err, "failed to write size of room list") + return fmt.Errorf("failed to write size of room list: %w", err) } // Write list diff --git a/ui/commands.go b/ui/commands.go index 8235c15..2160943 100644 --- a/ui/commands.go +++ b/ui/commands.go @@ -18,6 +18,7 @@ package ui import ( "encoding/json" + "errors" "fmt" "io" "math" @@ -34,7 +35,6 @@ import ( "unicode" "github.com/lucasb-eyer/go-colorful" - "github.com/pkg/errors" "github.com/russross/blackfriday/v2" "maunium.net/go/mautrix" @@ -225,7 +225,7 @@ func readRoomAlias(cmd *Command) (alias id.RoomAlias, err error) { param := strings.Join(cmd.Args[1:], " ") if strings.ContainsRune(param, ':') { if param[0] != '#' { - return "", errors.New("Full aliases must start with #") + return "", errors.New("full aliases must start with #") } alias = id.RoomAlias(param) diff --git a/ui/room-view.go b/ui/room-view.go index 13ba700..e6c63a4 100644 --- a/ui/room-view.go +++ b/ui/room-view.go @@ -24,7 +24,7 @@ import ( "time" "unicode" - "github.com/kyokomi/emoji" + "github.com/kyokomi/emoji/v2" "github.com/mattn/go-runewidth" "github.com/zyedidia/clipboard" From 114940eef67491d6eefbb63b575599024726c82d Mon Sep 17 00:00:00 2001 From: Tulir Asokan Date: Sat, 24 Oct 2020 15:35:40 +0300 Subject: [PATCH 9/9] Update exec.Command on all OSes --- lib/open/open.go | 14 +++++++++----- lib/open/open_darwin.go | 25 ++----------------------- lib/open/open_windows.go | 8 ++------ lib/open/open_xdg.go | 6 ++++++ 4 files changed, 19 insertions(+), 34 deletions(-) create mode 100644 lib/open/open_xdg.go diff --git a/lib/open/open.go b/lib/open/open.go index 935018f..c128494 100644 --- a/lib/open/open.go +++ b/lib/open/open.go @@ -1,5 +1,3 @@ -// +build !windows,!darwin - // gomuks - A terminal Matrix client written in Go. // Copyright (C) 2020 Tulir Asokan // @@ -20,16 +18,22 @@ package open import ( "os/exec" + "maunium.net/go/gomuks/debug" ) func Open(input string) error { - cmd := exec.Command("xdg-open", input) + cmd := exec.Command(Command, append(Args, input)...) err := cmd.Start() if err != nil { - debug.Print("xdg-open error:", err) + debug.Printf("Failed to start %s: %v", Command, err) } else { - go cmd.Wait() + go func() { + waitErr := cmd.Wait() + if waitErr != nil { + debug.Printf("Failed to run %s: %v", Command, err) + } + }() } return err } diff --git a/lib/open/open_darwin.go b/lib/open/open_darwin.go index 7a35818..625ec54 100644 --- a/lib/open/open_darwin.go +++ b/lib/open/open_darwin.go @@ -1,25 +1,4 @@ -// gomuks - A terminal Matrix client written in Go. -// Copyright (C) 2020 Tulir Asokan -// -// This program is free software: you can redistribute it and/or modify -// it under the terms of the GNU Affero General Public License as published by -// the Free Software Foundation, either version 3 of the License, or -// (at your option) any later version. -// -// This program is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -// GNU Affero General Public License for more details. -// -// You should have received a copy of the GNU Affero General Public License -// along with this program. If not, see . - package open -import ( - "os/exec" -) - -func Open(input string) error { - return exec.Command("open", input).Start() -} +const Command = "open" +var Args []string diff --git a/lib/open/open_windows.go b/lib/open/open_windows.go index eee606b..1586e2b 100644 --- a/lib/open/open_windows.go +++ b/lib/open/open_windows.go @@ -18,14 +18,10 @@ package open import ( "os" - "os/exec" "path/filepath" ) const FileProtocolHandler = "url.dll,FileProtocolHandler" -var RunDLL32 = filepath.Join(os.Getenv("SYSTEMROOT"), "System32", "rundll32.exe") - -func Open(input string) error { - return exec.Command(RunDLL32, FileProtocolHandler, input).Start() -} +var Command = filepath.Join(os.Getenv("SYSTEMROOT"), "System32", "rundll32.exe") +var Args = []string{FileProtocolHandler} diff --git a/lib/open/open_xdg.go b/lib/open/open_xdg.go new file mode 100644 index 0000000..e107a8a --- /dev/null +++ b/lib/open/open_xdg.go @@ -0,0 +1,6 @@ +// +build !windows,!darwin + +package open + +const Command = "xdg-open" +var Args []string