From 72fc33ef3e5f2eff3e294408d1090fac08a62e7c Mon Sep 17 00:00:00 2001 From: aleksandersh Date: Tue, 6 Aug 2024 22:26:49 +0200 Subject: [PATCH] add the enable-second-line parameter to show a task description next to the task name --- app/app.go | 12 +++++++++--- app/controller.go | 14 +++++++++++--- app/pages/tasks/tasks.go | 9 +++++---- app/ui/config.go | 5 +++++ cli/args.go | 9 +++++---- main.go | 2 +- 6 files changed, 36 insertions(+), 15 deletions(-) create mode 100644 app/ui/config.go diff --git a/app/app.go b/app/app.go index a9c9d6a..a54fd37 100644 --- a/app/app.go +++ b/app/app.go @@ -4,21 +4,27 @@ import ( "context" "fmt" + "github.com/aleksandersh/task-tui/app/ui" + "github.com/aleksandersh/task-tui/cli" "github.com/aleksandersh/task-tui/domain" "github.com/aleksandersh/task-tui/task" "github.com/rivo/tview" ) type App struct { + config *ui.Config } -func New() *App { - return &App{} +func New(args *cli.Args) *App { + cfg := ui.Config{ + SecondLineEnabled: args.EnableSecondLine, + } + return &App{config: &cfg} } func (a *App) Start(ctx context.Context, task *task.Task, taskfile *domain.Taskfile) error { app := tview.NewApplication() - contoller := newController(ctx, task, app, taskfile) + contoller := newController(ctx, task, app, taskfile, a.config) contoller.StartUi() if err := app.Run(); err != nil { diff --git a/app/controller.go b/app/controller.go index 36987f2..9e761c3 100644 --- a/app/controller.go +++ b/app/controller.go @@ -18,13 +18,21 @@ type controller struct { ctx context.Context task *task.Task taskfile *domain.Taskfile + config *ui.Config app *tview.Application pagesView *tview.Pages } -func newController(ctx context.Context, task *task.Task, app *tview.Application, taskfile *domain.Taskfile) ui.Controller { +func newController(ctx context.Context, task *task.Task, app *tview.Application, taskfile *domain.Taskfile, config *ui.Config) ui.Controller { pagesView := tview.NewPages() - return &controller{ctx: ctx, task: task, app: app, pagesView: pagesView, taskfile: taskfile} + return &controller{ + ctx: ctx, + task: task, + taskfile: taskfile, + config: config, + app: app, + pagesView: pagesView, + } } func (c *controller) StartUi() { @@ -33,7 +41,7 @@ func (c *controller) StartUi() { } func (c *controller) ShowTasks() { - c.pagesView.AddAndSwitchToPage(pageNameTasks, tasks.New(c.ctx, c.task, c, c.taskfile), true) + c.pagesView.AddAndSwitchToPage(pageNameTasks, tasks.New(c.ctx, c.task, c.config, c, c.taskfile), true) } func (c *controller) Focus(view tview.Primitive) { diff --git a/app/pages/tasks/tasks.go b/app/pages/tasks/tasks.go index db0d05c..8b07bea 100644 --- a/app/pages/tasks/tasks.go +++ b/app/pages/tasks/tasks.go @@ -15,8 +15,8 @@ type view struct { filter *tview.TextArea } -func New(ctx context.Context, task *task.Task, uiController ui.Controller, taskfile *domain.Taskfile) *tview.Grid { - tasksView := createTasksView() +func New(ctx context.Context, task *task.Task, config *ui.Config, uiController ui.Controller, taskfile *domain.Taskfile) *tview.Grid { + tasksView := createTasksView(config) filterView := createFilterView() v := &view{tasks: tasksView, filter: filterView} @@ -66,10 +66,11 @@ func (v *view) startFilterChangesHandling(c *controller) { }) } -func createTasksView() *tview.List { +func createTasksView(config *ui.Config) *tview.List { view := tview.NewList() view.SetHighlightFullLine(true). - ShowSecondaryText(false). + ShowSecondaryText(config.SecondLineEnabled). + SetSecondaryTextColor(tcell.Color16). SetWrapAround(false). SetTitle(" Taskfile "). SetBorder(true) diff --git a/app/ui/config.go b/app/ui/config.go new file mode 100644 index 0000000..67f12f1 --- /dev/null +++ b/app/ui/config.go @@ -0,0 +1,5 @@ +package ui + +type Config struct { + SecondLineEnabled bool +} diff --git a/cli/args.go b/cli/args.go index e062e39..c152461 100644 --- a/cli/args.go +++ b/cli/args.go @@ -3,10 +3,11 @@ package cli import "github.com/alexflint/go-arg" type Args struct { - ExitCode bool `arg:"-x,--exit-code" default:"false" help:"Pass-through the exit code of the task command."` - Global bool `arg:"-g,--global" default:"false" help:"Runs global Taskfile, from $HOME/Taskfile.{yml,yaml}."` - Sort string `arg:"--sort" default:"default" help:"Changes the order of the tasks when listed."` - Taskfile string `arg:"-t,--taskfile" help:"Path to Taskfile."` + ExitCode bool `arg:"-x,--exit-code" default:"false" help:"Pass-through the exit code of the task command."` + Global bool `arg:"-g,--global" default:"false" help:"Runs global Taskfile, from $HOME/Taskfile.{yml,yaml}."` + Sort string `arg:"--sort" default:"default" help:"Changes the order of the tasks when listed."` + Taskfile string `arg:"-t,--taskfile" help:"Path to Taskfile."` + EnableSecondLine bool `arg:"--enable-second-line" default:"false" help:"Show the description next to the task name."` } func GetArgs() *Args { diff --git a/main.go b/main.go index 79c5222..3dedf83 100644 --- a/main.go +++ b/main.go @@ -21,7 +21,7 @@ func main() { log.Fatalf("failed to load taskfile: %v", err) } - if err := app.New().Start(ctx, task, taskfile); err != nil { + if err := app.New(args).Start(ctx, task, taskfile); err != nil { log.Fatalf("failed to start application: %v", err) } }