Skip to content

Commit

Permalink
First working prototype
Browse files Browse the repository at this point in the history
It's somehow working.
  • Loading branch information
grisu48 committed Dec 16, 2024
1 parent eb85965 commit 447980e
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 17 deletions.
21 changes: 4 additions & 17 deletions cmd/openqa-revtui/openqa-revtui.go
Original file line number Diff line number Diff line change
Expand Up @@ -188,6 +188,7 @@ func main() {

// Run TUI and use the return code
tui = CreateTUI()
// Apply sorting of the first group
switch cf.GroupBy {
case "none", "":
tui.SetSorting(0)
Expand All @@ -206,7 +207,7 @@ func main() {
}
}

func refreshJobs() error {
func RefreshJobs() error {
// Get fresh jobs
status := tui.Status()
oldJobs := tui.Model.Jobs()
Expand Down Expand Up @@ -285,7 +286,7 @@ func tui_main() error {
if !refreshing {
refreshing = true
go func() {
if err := refreshJobs(); err != nil {
if err := RefreshJobs(); err != nil {
tui.SetStatus(fmt.Sprintf("Error while refreshing: %s", err))
}
refreshing = false
Expand Down Expand Up @@ -323,20 +324,6 @@ func tui_main() error {
}
}
tui.Update()
case 90: // Tab
cfi = (cfi + 1) % len(cfs)
refreshJobs()
tui.SetTemporaryStatus(fmt.Sprintf("Switched to %s", cfs[cfi].Name), 10)
tui.Update()
case 91: // Shift+Tab
if cfi == 0 {
cfi = len(cfs) - 1
} else {
cfi--
}
refreshJobs()
tui.SetTemporaryStatus(fmt.Sprintf("Switched to %s", cfs[cfi].Name), 10)
tui.Update()
default:
tui.Update()
}
Expand Down Expand Up @@ -432,7 +419,7 @@ func tui_main() error {
go func() {
for {
time.Sleep(time.Duration(cf.RefreshInterval) * time.Second)
if err := refreshJobs(); err != nil {
if err := RefreshJobs(); err != nil {
tui.SetStatus(fmt.Sprintf("Error while refreshing: %s", err))
}
}
Expand Down
15 changes: 15 additions & 0 deletions cmd/openqa-revtui/tui.go
Original file line number Diff line number Diff line change
Expand Up @@ -230,8 +230,21 @@ func (tui *TUI) readInput() {
max := max(0, (tui.Model.printLines - tui.screensize))
// Always leave one line overlap for better orientation
tui.Model.offset = min(max, tui.Model.offset+tui.screensize-1)
case 90: // Shift+Tab
cfi--
if cfi < 0 {
cfi = len(cfs) - 1
}
RefreshJobs()
tui.Update()
}
}
// Default keys
if k == 9 { // Tab
cfi = (cfi + 1) % len(cfs)
RefreshJobs()
tui.Update()
}

// Forward keypress to listener
if tui.Keypress != nil {
Expand Down Expand Up @@ -529,6 +542,8 @@ func (tui *TUI) buildScreen(width int) []string {
func (tui *TUI) Update() {
tui.Model.mutex.Lock()
defer tui.Model.mutex.Unlock()
tui.Model.jobs = cfs[cfi].jobs
tui.Model.jobGroups = cfs[cfi].jobGroups
width, height := terminalSize()
if width <= 0 || height <= 0 {
return
Expand Down

0 comments on commit 447980e

Please sign in to comment.