Skip to content

Commit

Permalink
add the enable-second-line parameter to show a task description next …
Browse files Browse the repository at this point in the history
…to the task name
  • Loading branch information
aleksandersh committed Aug 6, 2024
1 parent 53fe10b commit 72fc33e
Show file tree
Hide file tree
Showing 6 changed files with 36 additions and 15 deletions.
12 changes: 9 additions & 3 deletions app/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
14 changes: 11 additions & 3 deletions app/controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand All @@ -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) {
Expand Down
9 changes: 5 additions & 4 deletions app/pages/tasks/tasks.go
Original file line number Diff line number Diff line change
Expand Up @@ -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}
Expand Down Expand Up @@ -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)
Expand Down
5 changes: 5 additions & 0 deletions app/ui/config.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
package ui

type Config struct {
SecondLineEnabled bool
}
9 changes: 5 additions & 4 deletions cli/args.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
2 changes: 1 addition & 1 deletion main.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
}

0 comments on commit 72fc33e

Please sign in to comment.