From 8ad8fbbced521176bcba2b60d0c94bfedb74bcc6 Mon Sep 17 00:00:00 2001 From: IllusionMan1212 Date: Sun, 20 Mar 2022 15:51:34 +0200 Subject: [PATCH] feat/fix: fix panic and small additions --- TODO.md | 2 ++ app.go | 24 ++++++++++++++++++++---- 2 files changed, 22 insertions(+), 4 deletions(-) diff --git a/TODO.md b/TODO.md index 2392c76..f2d89bd 100644 --- a/TODO.md +++ b/TODO.md @@ -4,3 +4,5 @@ ## TODO: print the name of the current file being encoded e.g `Encoding "Video Example Test 1"...`. ## TODO: customizable encoding settings, using tui elements to control and select them. (not gonna work on this in the near future) ## TODO: ask user if they want the old videos deleted. (probably not gonna work on this in the near future too) +## FIXME: tui is stuck forever if file is already encoded. +## TODO: when passing in a directory, list all video files in that directory and have the user choose which ones they want encoded diff --git a/app.go b/app.go index b5a7582..8c1693b 100644 --- a/app.go +++ b/app.go @@ -13,6 +13,8 @@ import ( "github.com/gabriel-vasile/mimetype" ) +var checkmark = lipgloss.NewStyle().Foreground(lipgloss.Color("#22FF33")).Render("✔") + type model struct { IsDirectory bool Path string @@ -22,6 +24,7 @@ type model struct { Spinner spinner.Model Progress float64 Program *tea.Program + Quitting bool } func initialModel(fileInfo os.FileInfo, absolutePath string) *model { @@ -37,6 +40,7 @@ func initialModel(fileInfo os.FileInfo, absolutePath string) *model { Files: make([]string, 0), Spinner: s, Progress: 0.0, + Quitting: false, } } @@ -68,10 +72,17 @@ func (m model) Update(msg tea.Msg) (tea.Model, tea.Cmd) { case finishedEncodingVideo: m.Files = m.Files[:len(m.Files)-1] + if len(m.Files) == 0 { + return m, m.gracefullyQuit + } + return m, encodeVideo case updateProgress: m.Progress = msg.progress return m, nil + case quitMsg: + m.Quitting = true + return m, tea.Quit } m.Spinner, cmd = m.Spinner.Update(msg) @@ -80,11 +91,11 @@ func (m model) Update(msg tea.Msg) (tea.Model, tea.Cmd) { } func (m model) View() string { - if m.IsDirectory { - return fmt.Sprintf("%s %d/%d files encoded\n%.0f%% done", m.Spinner.View(), m.FileCount-len(m.Files), m.FileCount, m.Progress) - } else { - return fmt.Sprintf("%s %d file\n%.0f%% done", m.Spinner.View(), m.FileCount, m.Progress) + if m.Quitting { + return fmt.Sprintf("%s %d/%d files encoded\n", checkmark, m.FileCount-len(m.Files), m.FileCount) } + + return fmt.Sprintf("%s %d/%d files encoded\n%.0f%% done", m.Spinner.View(), m.FileCount-len(m.Files), m.FileCount, m.Progress) } type initUi struct { @@ -126,7 +137,12 @@ type finishedEncodingVideo struct{} type updateProgress struct { progress float64 } +type quitMsg struct{} func encodeVideo() tea.Msg { return encodeVideoMsg{} } + +func (m model) gracefullyQuit() tea.Msg { + return quitMsg{} +}