Skip to content
This repository has been archived by the owner on Dec 16, 2021. It is now read-only.

Add hotkey to open message's image attachments in feh #256

Merged
merged 2 commits into from
Mar 3, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ var (
ShowUpdateNotifications: true,
IndicateChannelAccessRestriction: false,
ShowBottomBar: true,
ImageViewer: "feh",
}
)

Expand Down Expand Up @@ -133,6 +134,12 @@ type Config struct {
// ShowBottomBar decides whether an informational line is shown at the
// bottom of cordless or not.
ShowBottomBar bool

// The image viewer to open when the user uses the "view attached images"
// shortcut. This program will be passed a list of 1 or more image links
// as if it were called from the command line, so the selected program
// must be capable of opening image links.
ImageViewer string
}

// Account has a name and a token. The name is just for the users recognition.
Expand Down
2 changes: 2 additions & 0 deletions shortcuts/shortcuts.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,8 @@ var (
chatview, tcell.NewEventKey(tcell.KeyRune, 's', tcell.ModNone))
DeleteSelectedMessage = addShortcut("toggle_selected_message_spoilers", "Toggle spoilers in selected message",
chatview, tcell.NewEventKey(tcell.KeyDelete, 0, tcell.ModNone))
ViewSelectedMessageImages = addShortcut("view_selected_message_images", "View selected message's attached images",
chatview, tcell.NewEventKey(tcell.KeyRune, 'o', tcell.ModNone))

ExpandSelectionToLeft = addShortcut("expand_selection_word_to_left", "Expand selection word to left",
multilineTextInput, tcell.NewEventKey(tcell.KeyLeft, 0, tcell.ModShift))
Expand Down
17 changes: 17 additions & 0 deletions ui/window.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import (
"strings"
"time"
"unicode"
"os/exec"

"github.com/mattn/go-runewidth"
"github.com/mdp/qrterminal/v3"
Expand Down Expand Up @@ -385,6 +386,22 @@ func NewWindow(doRestart chan bool, app *tview.Application, session *discordgo.S
return nil
}

if shortcuts.ViewSelectedMessageImages.Equals(event) {
links := make([]string, 0, len(message.Attachments))
for _, file := range message.Attachments {
links = append(links, file.URL)
}
if len(links) > 0 {
cmd := exec.Command(config.Current.ImageViewer, links...)
err := cmd.Start()
if err != nil {
window.ShowErrorDialog(err.Error())
}
}

return nil
}

return event
})
window.messageContainer = window.chatView.GetPrimitive()
Expand Down