Browse Source

add delete-temp-files

pull/253/head
Rasmus Lindroth 3 years ago
parent
commit
5c1ed3e47e
  1. 6
      config.example.toml
  2. 38
      config/config.go
  3. 6
      config/default_config.go
  4. 9
      config/toml.go
  5. 1
      config/toml_default.go
  6. 10
      docs/man/tut.5
  7. 4
      docs/man/tut.5.md
  8. 14
      ui/media.go
  9. 12
      ui/tutview.go

6
config.example.toml

@ -253,6 +253,12 @@ leader-timeout=1000
# shortcut=""
[media]
# Media files will be removed directly after they've been opened. Some programs
# doesn't like this, so if your media doesn't open, try set this to false. Tut
# will remove all files once you close the program.
# default=true
delete-temp-files=true
[media.image]
# The program to open images. TUT_OS_DEFAULT equals xdg-open on Linux, open on
# MacOS and start on Windows.

38
config/config.go

@ -248,24 +248,25 @@ type Style struct {
}
type Media struct {
ImageViewer string
ImageArgs []string
ImageTerminal bool
ImageSingle bool
ImageReverse bool
VideoViewer string
VideoArgs []string
VideoTerminal bool
VideoSingle bool
VideoReverse bool
AudioViewer string
AudioArgs []string
AudioTerminal bool
AudioSingle bool
AudioReverse bool
LinkViewer string
LinkArgs []string
LinkTerminal bool
DeleteTmpFiles bool
ImageViewer string
ImageArgs []string
ImageTerminal bool
ImageSingle bool
ImageReverse bool
VideoViewer string
VideoArgs []string
VideoTerminal bool
VideoSingle bool
VideoReverse bool
AudioViewer string
AudioArgs []string
AudioTerminal bool
AudioSingle bool
AudioReverse bool
LinkViewer string
LinkArgs []string
LinkTerminal bool
}
type Pattern struct {
@ -770,6 +771,7 @@ func getViewer(v *ViewerTOML, def *ViewerTOML) (program, args string, terminal,
func parseMedia(cfg MediaTOML) Media {
media := Media{}
media.DeleteTmpFiles = NilDefaultBool(cfg.DeleteTmpFiles, ConfigDefault.Media.DeleteTmpFiles)
var program, args string
var terminal, single, reverse bool

6
config/default_config.go

@ -255,6 +255,12 @@ leader-timeout=1000
# shortcut=""
[media]
# Media files will be removed directly after they've been opened. Some programs
# doesn't like this, so if your media doesn't open, try set this to false. Tut
# will remove all files once you close the program.
# default=true
delete-temp-files=true
[media.image]
# The program to open images. TUT_OS_DEFAULT equals xdg-open on Linux, open on
# MacOS and start on Windows.

9
config/toml.go

@ -119,10 +119,11 @@ type ViewerTOML struct {
}
type MediaTOML struct {
Image *ViewerTOML `toml:"image"`
Video *ViewerTOML `toml:"video"`
Audio *ViewerTOML `toml:"audio"`
Link *ViewerTOML `toml:"link"`
DeleteTmpFiles *bool `toml:"delete-temp-files"`
Image *ViewerTOML `toml:"image"`
Video *ViewerTOML `toml:"video"`
Audio *ViewerTOML `toml:"audio"`
Link *ViewerTOML `toml:"link"`
}
type PatternTOML struct {

1
config/toml_default.go

@ -90,6 +90,7 @@ var ConfigDefault = ConfigTOML{
TimelineNameText: sp("#808080"),
},
Media: MediaTOML{
DeleteTmpFiles: bt,
Image: &ViewerTOML{
Program: sp("TUT_OS_DEFAULT"),
Args: sp(""),

10
docs/man/tut.5

@ -506,6 +506,16 @@ A shortcut to run this action with your leader-key + this shortcut.
.SH MEDIA
.PP
This section is [media] in your configuration file
.SS delete-temp-files
.PP
Media files will be removed directly after they\[aq]ve been opened.
Some programs doesn\[aq]t like this, so if your media doesn\[aq]t open,
try set this to false.
Tut will remove all files once you close the program.
.PD 0
.P
.PD
\f[B]delete-temp-files\f[R]=\f[I]true\f[R]
.SH MEDIA.IMAGE
.PP
This section is [media.image] in your configuration file

4
docs/man/tut.5.md

@ -265,6 +265,10 @@ A shortcut to run this action with your leader-key + this shortcut.
# MEDIA
This section is \[media\] in your configuration file
## delete-temp-files
Media files will be removed directly after they\'ve been opened. Some programs doesn\'t like this, so if your media doesn\'t open, try set this to false. Tut will remove all files once you close the program.
**delete-temp-files**=*true*
# MEDIA.IMAGE
This section is \[media.image\] in your configuration file

14
ui/media.go

@ -155,18 +155,22 @@ func openMediaType(tv *TutView, filenames []string, mediaType string) {
go func() {
for _, ext := range external {
exec.Command(ext.Name, ext.Args...).Run()
deleteFiles(ext.Filenames)
deleteFiles(tv, ext.Filenames)
}
}()
for _, term := range terminal {
openInTerminal(tv, term.Name, term.Args...)
deleteFiles(term.Filenames)
deleteFiles(tv, term.Filenames)
}
}
func deleteFiles(filenames []string) {
for _, filename := range filenames {
os.Remove(filename)
func deleteFiles(tv *TutView, filenames []string) {
if tv.tut.Config.Media.DeleteTmpFiles {
for _, filename := range filenames {
os.Remove(filename)
}
} else {
tv.FileList = append(tv.FileList, filenames...)
}
}

12
ui/tutview.go

@ -71,9 +71,18 @@ type TutView struct {
HelpView *HelpView
EditorView *EditorView
ModalView *ModalView
FileList []string
}
func (tv *TutView) CleanExit(code int) {
if !tv.tut.Config.Media.DeleteTmpFiles {
for _, t := range TutViews.Views {
for _, f := range t.FileList {
os.Remove(f)
}
}
}
os.Exit(code)
}
@ -123,7 +132,8 @@ func NewTutView(selectedUser string) {
App: App,
Config: Config,
},
View: tview.NewPages(),
View: tview.NewPages(),
FileList: []string{},
}
tv.Leader = NewLeader(tv)
tv.Shared = NewShared(tv)

Loading…
Cancel
Save