diff --git a/mvc.go b/mvc.go index 56a049d..a105a95 100644 --- a/mvc.go +++ b/mvc.go @@ -112,18 +112,10 @@ func (m *Model) View() string { status := "" switch runner.State { case NotStarted: - if IsCI() { - status = runner.Config.Chars.NotStarted + " " + runner.Task.Title - } else { - status = lipgloss.NewStyle().Foreground(runner.Config.Colors.Pending).Render(runner.Config.Chars.NotStarted) + " " + runner.Task.Title // Gray bullet - } + status = Color(runner.Config.Colors.Pending, runner.Config.Chars.NotStarted) + " " + runner.Task.Title // Gray bullet case Running: if len(runner.Children) > 0 { - if IsCI() { - status = runner.Config.Chars.ParentStarted + " " + runner.Task.Title - } else { - status = lipgloss.NewStyle().Foreground(runner.Config.Colors.ParentStarted).Render(runner.Config.Chars.ParentStarted) + " " + runner.Task.Title - } + status = Color(runner.Config.Colors.ParentStarted, runner.Config.Chars.ParentStarted) + " " + runner.Task.Title } else { if runner.Task.ShowProgress.Total != 0 { percent := float64(runner.Task.ShowProgress.Current) / float64(runner.Task.ShowProgress.Total) @@ -141,18 +133,9 @@ func (m *Model) View() string { } } case Completed: - if IsCI() { - status = runner.Config.Chars.Success + " " + runner.Task.Title - } else { - status = lipgloss.NewStyle().Foreground(runner.Config.Colors.Success).Render(runner.Config.Chars.Success) + " " + runner.Task.Title // Green checkmark - } + status = Color(runner.Config.Colors.Success, runner.Config.Chars.Success) + " " + runner.Task.Title // Green checkmark case Failed: - if IsCI() { - status = runner.Config.Chars.Failure + " " + runner.Task.Title - } else { - status = lipgloss.NewStyle().Foreground(runner.Config.Colors.Failure).Render(runner.Config.Chars.Failure) + " " + runner.Task.Title // Red 'x' - - } + status = Color(runner.Config.Colors.Failure, runner.Config.Chars.Failure) + " " + runner.Task.Title // Red 'x' } view += lipgloss.NewStyle().Render(status) + "\n" @@ -160,11 +143,7 @@ func (m *Model) View() string { status = "" switch child.State { case NotStarted: - if IsCI() { - status = runner.Config.Chars.NotStarted + " " + child.Task.Title - } else { - status = lipgloss.NewStyle().Foreground(child.Config.Colors.Pending).Render(runner.Config.Chars.NotStarted) + " " + child.Task.Title // Gray bullet - } + status = Color(child.Config.Colors.Pending, runner.Config.Chars.NotStarted) + " " + child.Task.Title // Gray bullet case Running: if child.Task.ShowProgress.Total != 0 { percent := float64(child.Task.ShowProgress.Current) / float64(child.Task.ShowProgress.Total) @@ -181,17 +160,9 @@ func (m *Model) View() string { } } case Completed: - if IsCI() { - status = runner.Config.Chars.Success + " " + child.Task.Title - } else { - status = lipgloss.NewStyle().Foreground(child.Config.Colors.Success).Render(runner.Config.Chars.Success) + " " + child.Task.Title // Green checkmark - } + status = Color(child.Config.Colors.Success, runner.Config.Chars.Success) + " " + child.Task.Title // Green checkmark case Failed: - if IsCI() { - status = runner.Config.Chars.Failure + " " + child.Task.Title - } else { - status = lipgloss.NewStyle().Foreground(child.Config.Colors.Failure).Render(runner.Config.Chars.Failure) + " " + child.Task.Title // Red 'x' - } + status = Color(child.Config.Colors.Failure, runner.Config.Chars.Failure) + " " + child.Task.Title // Red 'x' } if IsCI() { view += " " + status + "\n" diff --git a/taskin.go b/taskin.go index 2ed2cad..bf926c4 100644 --- a/taskin.go +++ b/taskin.go @@ -51,11 +51,7 @@ func (task *Task) Progress(current, total int) { func (r *Runners) Run() error { m := &Model{Runners: *r, Shutdown: false, ShutdownError: nil} - if IsCI() { - program = tea.NewProgram(m, tea.WithInput(nil), tea.WithoutSignals(), tea.WithoutSignalHandler()) - } else { - program = tea.NewProgram(m, tea.WithInput(nil)) - } + program = tea.NewProgram(m, tea.WithInput(nil)) _, err := program.Run() if err != nil { program.Send(TerminateWithError{Error: err}) diff --git a/ui.go b/ui.go new file mode 100644 index 0000000..6d15008 --- /dev/null +++ b/ui.go @@ -0,0 +1,10 @@ +package taskin + +import "github.com/charmbracelet/lipgloss" + +func Color(c lipgloss.TerminalColor, r string) string { + if IsCI() { + return r + } + return lipgloss.NewStyle().Foreground(c).Render(r) +}