mirror of
https://github.com/IllusionMan1212/ffui.git
synced 2026-10-24 02:12:35 +00:00
feat/fix: fix panic and small additions
This commit is contained in:
@@ -4,3 +4,5 @@
|
|||||||
## TODO: print the name of the current file being encoded e.g `Encoding "Video Example Test 1"...`.
|
## 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: 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)
|
## 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
|
||||||
|
|||||||
@@ -13,6 +13,8 @@ import (
|
|||||||
"github.com/gabriel-vasile/mimetype"
|
"github.com/gabriel-vasile/mimetype"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
var checkmark = lipgloss.NewStyle().Foreground(lipgloss.Color("#22FF33")).Render("✔")
|
||||||
|
|
||||||
type model struct {
|
type model struct {
|
||||||
IsDirectory bool
|
IsDirectory bool
|
||||||
Path string
|
Path string
|
||||||
@@ -22,6 +24,7 @@ type model struct {
|
|||||||
Spinner spinner.Model
|
Spinner spinner.Model
|
||||||
Progress float64
|
Progress float64
|
||||||
Program *tea.Program
|
Program *tea.Program
|
||||||
|
Quitting bool
|
||||||
}
|
}
|
||||||
|
|
||||||
func initialModel(fileInfo os.FileInfo, absolutePath string) *model {
|
func initialModel(fileInfo os.FileInfo, absolutePath string) *model {
|
||||||
@@ -37,6 +40,7 @@ func initialModel(fileInfo os.FileInfo, absolutePath string) *model {
|
|||||||
Files: make([]string, 0),
|
Files: make([]string, 0),
|
||||||
Spinner: s,
|
Spinner: s,
|
||||||
Progress: 0.0,
|
Progress: 0.0,
|
||||||
|
Quitting: false,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -68,10 +72,17 @@ func (m model) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
|
|||||||
case finishedEncodingVideo:
|
case finishedEncodingVideo:
|
||||||
m.Files = m.Files[:len(m.Files)-1]
|
m.Files = m.Files[:len(m.Files)-1]
|
||||||
|
|
||||||
|
if len(m.Files) == 0 {
|
||||||
|
return m, m.gracefullyQuit
|
||||||
|
}
|
||||||
|
|
||||||
return m, encodeVideo
|
return m, encodeVideo
|
||||||
case updateProgress:
|
case updateProgress:
|
||||||
m.Progress = msg.progress
|
m.Progress = msg.progress
|
||||||
return m, nil
|
return m, nil
|
||||||
|
case quitMsg:
|
||||||
|
m.Quitting = true
|
||||||
|
return m, tea.Quit
|
||||||
}
|
}
|
||||||
|
|
||||||
m.Spinner, cmd = m.Spinner.Update(msg)
|
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 {
|
func (m model) View() string {
|
||||||
if m.IsDirectory {
|
if m.Quitting {
|
||||||
return fmt.Sprintf("%s %d/%d files encoded\n%.0f%% done", m.Spinner.View(), m.FileCount-len(m.Files), m.FileCount, m.Progress)
|
return fmt.Sprintf("%s %d/%d files encoded\n", checkmark, m.FileCount-len(m.Files), m.FileCount)
|
||||||
} else {
|
|
||||||
return fmt.Sprintf("%s %d file\n%.0f%% done", m.Spinner.View(), m.FileCount, m.Progress)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
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 {
|
type initUi struct {
|
||||||
@@ -126,7 +137,12 @@ type finishedEncodingVideo struct{}
|
|||||||
type updateProgress struct {
|
type updateProgress struct {
|
||||||
progress float64
|
progress float64
|
||||||
}
|
}
|
||||||
|
type quitMsg struct{}
|
||||||
|
|
||||||
func encodeVideo() tea.Msg {
|
func encodeVideo() tea.Msg {
|
||||||
return encodeVideoMsg{}
|
return encodeVideoMsg{}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (m model) gracefullyQuit() tea.Msg {
|
||||||
|
return quitMsg{}
|
||||||
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user