From b9ffcbe97f101f8d517444f9f744c172ee61ab71 Mon Sep 17 00:00:00 2001 From: kevin olson Date: Sun, 26 May 2024 19:46:32 -0500 Subject: [PATCH 1/2] =?UTF-8?q?=F0=9F=9A=A7=20HideView=20boolean=20with=20?= =?UTF-8?q?docs?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- models.go | 2 ++ mvc.go | 12 ++++++++++++ readme.md | 24 ++++++++++++++++++++++++ 3 files changed, 38 insertions(+) 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..ce97560 100644 --- a/readme.md +++ b/readme.md @@ -62,3 +62,27 @@ https://github.com/fumeapp/taskin/blob/3cd766c21e5eaba5edb33f38d3781d6cf814f9f9/ ![Multi](/multi.gif) + + +## Functionality in a task + +### 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 +} + +``` From efd8f8e56aea25b48e646e6d75bd7f3f0249f853 Mon Sep 17 00:00:00 2001 From: kevin olson Date: Sun, 26 May 2024 19:49:10 -0500 Subject: [PATCH 2/2] =?UTF-8?q?=F0=9F=8E=A8=20readme=20updates?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- readme.md | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/readme.md b/readme.md index ce97560..650e0e5 100644 --- a/readme.md +++ b/readme.md @@ -64,7 +64,8 @@ https://github.com/fumeapp/taskin/blob/3cd766c21e5eaba5edb33f38d3781d6cf814f9f9/ -## Functionality in a task +## 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