diff --git a/models.go b/models.go index 92f56c7..5466290 100644 --- a/models.go +++ b/models.go @@ -25,6 +25,7 @@ type Task struct { Bar progress.Model Config Config Tasks Tasks + HideView bool } type TaskProgress struct { @@ -46,6 +47,7 @@ type Runners []Runner type Model struct { Runners Runners + HideView bool Shutdown bool ShutdownError error } diff --git a/mvc.go b/mvc.go index 7bdc8d9..bb57094 100644 --- a/mvc.go +++ b/mvc.go @@ -95,6 +95,18 @@ func (m *Model) checkTasksState() (allDone, anyFailed bool) { } func (m *Model) View() string { + + for _, runner := range m.Runners { + if runner.Task.HideView { + return "" + } + for _, child := range runner.Children { + if child.Task.HideView { + return "" + } + } + } + var view string // check if CI is set, if it is then don't return the view until all tasks are completed or one has failed diff --git a/readme.md b/readme.md index 580f16a..650e0e5 100644 --- a/readme.md +++ b/readme.md @@ -62,3 +62,28 @@ https://github.com/fumeapp/taskin/blob/3cd766c21e5eaba5edb33f38d3781d6cf814f9f9/ ![Multi](/multi.gif) + + +## Usage inside a task +The `*taskin.Task` struct passeed into your task has some useful properties that you can use to customize the task view. + +### Change the title +Already demonstrated in most of the examples, you can change `t.Title` at any time + +### Hide a view +Sometimes you might need to temporarily hide you task view in order to prompt a user for input. +You can do this by toggling the task.HideView boolean. + +```go +Task: func(T *taskin.Task ) error { + t.HideView = true + if err := PromptForInput(); err != nil { + t.HideView = false + return err + } + t.HideView = false + t.Title = "Input received" + return nil +} + +```