Skip to content

Commit

Permalink
Set the text color of a task row depending on its state
Browse files Browse the repository at this point in the history
  • Loading branch information
moncho committed May 5, 2017
1 parent 3aa0414 commit 987fbeb
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 2 deletions.
2 changes: 1 addition & 1 deletion appui/swarm/node_tasks.go
Expand Up @@ -163,7 +163,7 @@ func taskTableHeader() *termui.TableHeader {
header.AddColumn(fields[2])
header.AddColumn(fields[3])
header.AddFixedWidthColumn(fields[4], 13)
header.AddColumn(fields[5])
header.AddFixedWidthColumn(fields[5], 22)
header.AddColumn(fields[6])
header.AddColumn(fields[7])

Expand Down
16 changes: 16 additions & 0 deletions appui/swarm/task_row.go
Expand Up @@ -52,6 +52,7 @@ func NewTaskRow(swarmClient docker.SwarmAPI, task swarm.Task, table drytermui.Ta
row.Error,
row.Ports,
}
updateStateColumns(row)

return row

Expand All @@ -75,3 +76,18 @@ func (row *TaskRow) changeTextColor(fg, bg termui.Attribute) {
row.ID.TextFgColor = fg
row.ID.TextBgColor = bg
}

//updateStateColumns changes the color of state-related column depending
//on the task state
func updateStateColumns(row *TaskRow) {
var color termui.Attribute
if row.DesiredState.Text == "Running" {
color = appui.Running
} else {
color = appui.NotRunning
}
row.DesiredState.TextFgColor = color
row.CurrentState.TextFgColor = color
row.Error.TextFgColor = color

}
10 changes: 9 additions & 1 deletion appui/theme.go
@@ -1,6 +1,14 @@
package appui

import "github.com/moncho/dry/ui"
import (
"github.com/gizak/termui"
"github.com/moncho/dry/ui"
)

const (
Running = termui.Attribute(ui.Color108)
NotRunning = termui.Attribute(ui.Color161)
)

//Default16 default theme for 16-color mode
var Default16 = &ui.ColorTheme{
Expand Down

0 comments on commit 987fbeb

Please sign in to comment.