Skip to content

Commit

Permalink
Add new jobs to the top of the table
Browse files Browse the repository at this point in the history
  • Loading branch information
philip-gai committed Jul 23, 2022
1 parent cf0095b commit 2c0c48b
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 8 deletions.
2 changes: 1 addition & 1 deletion tui/tui.go
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,7 @@ func createJobTable() *widgets.Table {
jobTable := widgets.NewTable()
jobTable.Title = "Jobs"
jobTable.Rows = [][]string{
{"#", "Action", "At", "Status"},
utils.JobTableHeader,
}
jobTable.TextStyle = termui.NewStyle(termui.ColorWhite)
jobTable.TextAlignment = termui.AlignCenter
Expand Down
23 changes: 16 additions & 7 deletions utils/tui.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ import (
"github.com/gizak/termui/v3/widgets"
)

var JobTableHeader = []string{"#", "Action", "At", "Status"}

func PushListRow(text string, list *widgets.List) {
textRows := strings.Split(text, "\n")
list.Rows = append(list.Rows, textRows...)
Expand All @@ -26,16 +28,23 @@ func BackspaceListRow(list *widgets.List) {
}

func PushJobRow(job JobInfo, jobTable *widgets.Table) {
jobTable.Rows = append(jobTable.Rows, []string{
fmt.Sprintf("%d", job.ID),
job.Action,
job.ScheduledFor,
job.Status,
})
jobTableEntry := [][]string{
JobTableHeader,
{
fmt.Sprintf("%d", job.ID),
job.Action,
job.ScheduledFor,
job.Status,
}}
if len(jobTable.Rows) > 1 {
jobTable.Rows = append(jobTableEntry, jobTable.Rows[1:]...)
} else {
jobTable.Rows = jobTableEntry
}
termui.Render(jobTable)
}

func UpdateJobRow(job JobInfo, jobTable *widgets.Table) {
jobTable.Rows[job.ID][3] = job.Status
jobTable.Rows[len(jobTable.Rows)-job.ID][3] = job.Status
termui.Render(jobTable)
}

0 comments on commit 2c0c48b

Please sign in to comment.