Skip to content

Commit 7a096db

Browse files
committed
allow configuring command for image to text conversion
1 parent a797795 commit 7a096db

File tree

3 files changed

+19
-8
lines changed

3 files changed

+19
-8
lines changed

config/settings.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ type General struct {
2525
DownloadPath string
2626
PreviewPath string
2727
CmdPrefix string
28+
ShowCommand string
2829
EnableNotifications bool
2930
NotificationTimeout int64
3031
}
@@ -70,6 +71,7 @@ var Config = IniFile{
7071
DownloadPath: GetHomeDir() + "Downloads",
7172
PreviewPath: GetHomeDir() + "Downloads",
7273
CmdPrefix: "/",
74+
ShowCommand: "jp2a --color",
7375
EnableNotifications: false,
7476
NotificationTimeout: 60,
7577
},

main.go

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import (
44
"bufio"
55
"fmt"
66
"io"
7+
"os"
78
"os/exec"
89
"strings"
910

@@ -356,9 +357,9 @@ func PrintHelp() {
356357
fmt.Fprintln(textView, "")
357358
fmt.Fprintln(textView, "[-::-]Message panel focused:[-::-]")
358359
fmt.Fprintln(textView, "[::b] Up/Down[::-] = select message")
359-
fmt.Fprintln(textView, "[::b]", config.Config.Keymap.MessageDownload, "[::-] = download attachment -> ", config.Config.General.DownloadPath)
360-
fmt.Fprintln(textView, "[::b]", config.Config.Keymap.MessageOpen, "[::-] = download & open attachment -> ", config.Config.General.PreviewPath)
361-
fmt.Fprintln(textView, "[::b]", config.Config.Keymap.MessageShow, "[::-] = download & show image using jp2a -> ", config.Config.General.PreviewPath)
360+
fmt.Fprintln(textView, "[::b]", config.Config.Keymap.MessageDownload, "[::-] = download attachment to", config.Config.General.DownloadPath)
361+
fmt.Fprintln(textView, "[::b]", config.Config.Keymap.MessageOpen, "[::-] = download & open attachment in", config.Config.General.PreviewPath)
362+
fmt.Fprintln(textView, "[::b]", config.Config.Keymap.MessageShow, "[::-] = download & show image using"+config.Config.General.ShowCommand, config.Config.General.PreviewPath+string(os.PathSeparator)+"filename.file")
362363
fmt.Fprintln(textView, "[::b]", config.Config.Keymap.MessageUrl, "[::-] = find URL in message and open it")
363364
fmt.Fprintln(textView, "[::b]", config.Config.Keymap.MessageRevoke, "[::-] = revoke message")
364365
fmt.Fprintln(textView, "[::b]", config.Config.Keymap.MessageInfo, "[::-] = info about message")
@@ -473,7 +474,15 @@ func PrintErrorMsg(text string, err error) {
473474
// prints an image attachment to the TextView (by message id)
474475
func PrintImage(path string) {
475476
var err error
476-
cmd := exec.Command("jp2a", "--color", path)
477+
cmdParts := strings.Split(config.Config.General.ShowCommand, " ")
478+
cmdParts = append(cmdParts, path)
479+
var cmd *exec.Cmd
480+
size := len(cmdParts)
481+
if size > 1 {
482+
cmd = exec.Command(cmdParts[0], cmdParts[1:]...)
483+
} else if size > 0 {
484+
cmd = exec.Command(cmdParts[0])
485+
}
477486
var stdout io.ReadCloser
478487
if stdout, err = cmd.StdoutPipe(); err == nil {
479488
if err = cmd.Start(); err == nil {

messages/session_manager.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -359,7 +359,7 @@ func (sm *SessionManager) execCommand(command Command) {
359359
}
360360
}
361361
} else {
362-
sm.uiHandler.PrintText("[red]Usage:[-] upload [/path/to/file[]")
362+
sm.uiHandler.PrintText("[red]Usage:[-] upload /path/to/file")
363363
}
364364
sm.uiHandler.PrintError(err)
365365
case "sendimage":
@@ -384,7 +384,7 @@ func (sm *SessionManager) execCommand(command Command) {
384384
}
385385
}
386386
} else {
387-
sm.uiHandler.PrintText("[red]Usage:[-] sendimage [/path/to/file[]")
387+
sm.uiHandler.PrintText("[red]Usage:[-] sendimage /path/to/file")
388388
}
389389
sm.uiHandler.PrintError(err)
390390
case "sendvideo":
@@ -409,7 +409,7 @@ func (sm *SessionManager) execCommand(command Command) {
409409
}
410410
}
411411
} else {
412-
sm.uiHandler.PrintText("[red]Usage:[-] sendvideo [/path/to/file[]")
412+
sm.uiHandler.PrintText("[red]Usage:[-] sendvideo /path/to/file")
413413
}
414414
sm.uiHandler.PrintError(err)
415415
case "sendaudio":
@@ -434,7 +434,7 @@ func (sm *SessionManager) execCommand(command Command) {
434434
}
435435
}
436436
} else {
437-
sm.uiHandler.PrintText("[red]Usage:[-] sendaudio [/path/to/file[]")
437+
sm.uiHandler.PrintText("[red]Usage:[-] sendaudio /path/to/file")
438438
}
439439
sm.uiHandler.PrintError(err)
440440
case "revoke":

0 commit comments

Comments
 (0)