Skip to content

Commit

Permalink
Add temporary status fields
Browse files Browse the repository at this point in the history
Introduce the SetTemporaryStatus method in the terminal user interface
(tui) and use it to display the browser error message only temporary.
  • Loading branch information
grisu48 committed Dec 20, 2023
1 parent 686414a commit 1cdf36c
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 1 deletion.
3 changes: 2 additions & 1 deletion cmd/openqa-revtui/openqa-revtui.go
Original file line number Diff line number Diff line change
Expand Up @@ -576,7 +576,8 @@ func tui_main(tui *TUI, instance *gopenqa.Instance) error {
if len(jobs) == 0 {
tui.SetStatus("No visible jobs")
} else if len(jobs) > 10 && key == 'o' {
tui.SetStatus("Refusing to open more than 10 job links. Use 'O' to override")
status := fmt.Sprintf("Refuse to open %d (>10) job links. Use 'O' to override", len(jobs))
tui.SetTemporaryStatus(status, 5)
} else {
if err := browserJobs(jobs); err != nil {
tui.SetStatus(fmt.Sprintf("error: %s", err))
Expand Down
17 changes: 17 additions & 0 deletions cmd/openqa-revtui/tui.go
Original file line number Diff line number Diff line change
Expand Up @@ -159,6 +159,23 @@ func (tui *TUI) SetStatus(status string) {
tui.status = status
}

func (tui *TUI) SetTemporaryStatus(status string, duration int) {
tui.Model.mutex.Lock()
old := tui.status
tui.status = status
tui.Model.mutex.Unlock()
tui.Update()

// Reset status text after waiting for duration. But only, if the status text has not been altered in the meantime
go func(old, status string, duration int) {
time.Sleep(time.Duration(duration) * time.Second)
if tui.status == status {
tui.status = old
tui.Update()
}
}(old, status, duration)
}

func (tui *TUI) Status() string {
return tui.status
}
Expand Down

0 comments on commit 1cdf36c

Please sign in to comment.