Skip to content

Commit

Permalink
Merge pull request #8 from fumeapp/hide-view
Browse files Browse the repository at this point in the history
🚧 HideView boolean with docs
  • Loading branch information
acidjazz committed May 27, 2024
2 parents 867de39 + efd8f8e commit 2e6119e
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 0 deletions.
2 changes: 2 additions & 0 deletions models.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ type Task struct {
Bar progress.Model
Config Config
Tasks Tasks
HideView bool
}

type TaskProgress struct {
Expand All @@ -46,6 +47,7 @@ type Runners []Runner

type Model struct {
Runners Runners
HideView bool
Shutdown bool
ShutdownError error
}
12 changes: 12 additions & 0 deletions mvc.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
25 changes: 25 additions & 0 deletions readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
}

```

0 comments on commit 2e6119e

Please sign in to comment.