checkpoint: can now open images from an image viewer
This commit is contained in:
parent
a4872dff46
commit
cf3b08e726
3 changed files with 34 additions and 6 deletions
|
@ -32,6 +32,7 @@ func run() error {
|
||||||
configDir string
|
configDir string
|
||||||
cacheDir string
|
cacheDir string
|
||||||
pager string
|
pager string
|
||||||
|
imageViewer string
|
||||||
maxTerminalWidth int
|
maxTerminalWidth int
|
||||||
noColor *bool
|
noColor *bool
|
||||||
)
|
)
|
||||||
|
@ -39,6 +40,7 @@ func run() error {
|
||||||
flag.StringVar(&configDir, "config-dir", "", "Specify your config directory")
|
flag.StringVar(&configDir, "config-dir", "", "Specify your config directory")
|
||||||
flag.StringVar(&cacheDir, "cache-dir", "", "Specify your cache directory")
|
flag.StringVar(&cacheDir, "cache-dir", "", "Specify your cache directory")
|
||||||
flag.StringVar(&pager, "pager", "", "Specify your preferred pager to page through long outputs. This is disabled by default.")
|
flag.StringVar(&pager, "pager", "", "Specify your preferred pager to page through long outputs. This is disabled by default.")
|
||||||
|
flag.StringVar(&imageViewer, "image-viewer", "", "Specify your preferred image viewer for viewing images attached to statuses.")
|
||||||
flag.IntVar(&maxTerminalWidth, "max-terminal-width", 80, "Specify the maximum terminal width when displaying resources on screen.")
|
flag.IntVar(&maxTerminalWidth, "max-terminal-width", 80, "Specify the maximum terminal width when displaying resources on screen.")
|
||||||
|
|
||||||
flag.BoolFunc("no-color", "Disable ANSI colour output when displaying text on screen", func(value string) error {
|
flag.BoolFunc("no-color", "Disable ANSI colour output when displaying text on screen", func(value string) error {
|
||||||
|
@ -173,6 +175,7 @@ func run() error {
|
||||||
printer,
|
printer,
|
||||||
configDir,
|
configDir,
|
||||||
cacheDir,
|
cacheDir,
|
||||||
|
imageViewer,
|
||||||
executor.CommandShow,
|
executor.CommandShow,
|
||||||
executor.CommandSummaryLookup(executor.CommandShow),
|
executor.CommandSummaryLookup(executor.CommandShow),
|
||||||
),
|
),
|
||||||
|
|
|
@ -36,16 +36,18 @@ type ShowExecutor struct {
|
||||||
pollID string
|
pollID string
|
||||||
attachmentID string
|
attachmentID string
|
||||||
fromResourceType string
|
fromResourceType string
|
||||||
|
imageViewer string
|
||||||
limit int
|
limit int
|
||||||
}
|
}
|
||||||
|
|
||||||
func NewShowExecutor(printer *printer.Printer, configDir, cacheRoot, name, summary string) *ShowExecutor {
|
func NewShowExecutor(printer *printer.Printer, configDir, cacheRoot, imageViewer, name, summary string) *ShowExecutor {
|
||||||
showExe := ShowExecutor{
|
showExe := ShowExecutor{
|
||||||
FlagSet: flag.NewFlagSet(name, flag.ExitOnError),
|
FlagSet: flag.NewFlagSet(name, flag.ExitOnError),
|
||||||
|
|
||||||
printer: printer,
|
printer: printer,
|
||||||
configDir: configDir,
|
configDir: configDir,
|
||||||
cacheRoot: cacheRoot,
|
cacheRoot: cacheRoot,
|
||||||
|
imageViewer: imageViewer,
|
||||||
}
|
}
|
||||||
|
|
||||||
showExe.BoolVar(&showExe.myAccount, flagMyAccount, false, "Set to true to lookup your account")
|
showExe.BoolVar(&showExe.myAccount, flagMyAccount, false, "Set to true to lookup your account")
|
||||||
|
@ -455,6 +457,7 @@ func (s *ShowExecutor) showMediaFromStatus(gtsClient *client.Client) error {
|
||||||
return FlagNotSetError{flagText: flagStatusID}
|
return FlagNotSetError{flagText: flagStatusID}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
status, err := gtsClient.GetStatus(s.statusID)
|
status, err := gtsClient.GetStatus(s.statusID)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return fmt.Errorf("unable to retrieve the status: %w", err)
|
return fmt.Errorf("unable to retrieve the status: %w", err)
|
||||||
|
@ -501,8 +504,9 @@ func (s *ShowExecutor) showMediaFromStatus(gtsClient *client.Client) error {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO: display the file in the image viewer.
|
if err := utilities.OpenMedia(s.imageViewer, mediaFilePath); err != nil {
|
||||||
fmt.Println("checkpoint: the media file is now on disk; just need to open it in an image viewer...")
|
return fmt.Errorf("unable to open the image viewer: %w", err)
|
||||||
|
}
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,6 +1,13 @@
|
||||||
|
// SPDX-FileCopyrightText: 2024 Dan Anglin <d.n.i.anglin@gmail.com>
|
||||||
|
//
|
||||||
|
// SPDX-License-Identifier: GPL-3.0-or-later
|
||||||
|
|
||||||
package utilities
|
package utilities
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"errors"
|
||||||
|
"fmt"
|
||||||
|
"os/exec"
|
||||||
"regexp"
|
"regexp"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -9,3 +16,17 @@ func GetFQDN(url string) string {
|
||||||
|
|
||||||
return r.ReplaceAllString(url, "")
|
return r.ReplaceAllString(url, "")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func OpenMedia(viewer, path string) error {
|
||||||
|
if viewer == "" {
|
||||||
|
return errors.New("the image viewer is not specified")
|
||||||
|
}
|
||||||
|
|
||||||
|
command := exec.Command(viewer, path)
|
||||||
|
|
||||||
|
if err := command.Start(); err != nil {
|
||||||
|
return fmt.Errorf("received an error after starting the image viewer: %w", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
Loading…
Reference in a new issue