Skip to content

Commit

Permalink
Issue #128: Use - for empty values to improve TUI columns clarity
Browse files Browse the repository at this point in the history
  • Loading branch information
F1bonacc1 committed Jan 28, 2024
1 parent 363b0af commit 046de78
Show file tree
Hide file tree
Showing 4 changed files with 78 additions and 16 deletions.
9 changes: 7 additions & 2 deletions src/app/process.go
Original file line number Diff line number Diff line change
Expand Up @@ -352,6 +352,7 @@ func (p *Process) onProcessEnd(state string) {
}
p.stopProbes()
p.setState(state)
p.updateProcState()

p.Lock()
p.done = true
Expand Down Expand Up @@ -395,13 +396,17 @@ func (p *Process) getCommand() []string {
}

func (p *Process) updateProcState() {
if p.isRunning() {
isRunning := p.isRunning()
p.stateMtx.Lock()
defer p.stateMtx.Unlock()
if isRunning {
dur := time.Since(p.getStartTime())
p.procState.SystemTime = durationToString(dur)
p.procState.Age = dur
p.procState.IsRunning = true
p.procState.Name = p.getName()
}
p.procState.IsRunning = isRunning

}
func (p *Process) setStartTime(startTime time.Time) {
p.timeMutex.Lock()
Expand Down
74 changes: 64 additions & 10 deletions src/tui/proc-table.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,19 @@ import (
"time"
)

type tableRowValues struct {
icon string
iconColor tcell.Color
pid string
name string
ns string
status string
age string
health string
restarts string
exitCode string
}

func (pv *pcView) fillTableData() {
if pv.project == nil {
return
Expand All @@ -33,16 +46,8 @@ func (pv *pcView) fillTableData() {
pv.procTable.RemoveRow(row)
continue
}
icon, color := getIconForState(state)
pv.procTable.SetCell(row, int(ProcessStateIcon), tview.NewTableCell(icon).SetAlign(tview.AlignCenter).SetExpansion(0).SetTextColor(color))
pv.procTable.SetCell(row, int(ProcessStatePid), tview.NewTableCell(strconv.Itoa(state.Pid)).SetAlign(tview.AlignRight).SetExpansion(0).SetTextColor(tcell.ColorLightSkyBlue))
pv.procTable.SetCell(row, int(ProcessStateName), tview.NewTableCell(state.Name).SetAlign(tview.AlignLeft).SetExpansion(1).SetTextColor(tcell.ColorLightSkyBlue))
pv.procTable.SetCell(row, int(ProcessStateNamespace), tview.NewTableCell(state.Namespace).SetAlign(tview.AlignLeft).SetExpansion(1).SetTextColor(tcell.ColorLightSkyBlue))
pv.procTable.SetCell(row, int(ProcessStateStatus), tview.NewTableCell(state.Status).SetAlign(tview.AlignLeft).SetExpansion(1).SetTextColor(tcell.ColorLightSkyBlue))
pv.procTable.SetCell(row, int(ProcessStateAge), tview.NewTableCell(state.SystemTime).SetAlign(tview.AlignLeft).SetExpansion(1).SetTextColor(tcell.ColorLightSkyBlue))
pv.procTable.SetCell(row, int(ProcessStateHealth), tview.NewTableCell(state.Health).SetAlign(tview.AlignLeft).SetExpansion(1).SetTextColor(tcell.ColorLightSkyBlue))
pv.procTable.SetCell(row, int(ProcessStateRestarts), tview.NewTableCell(strconv.Itoa(state.Restarts)).SetAlign(tview.AlignRight).SetExpansion(0).SetTextColor(tcell.ColorLightSkyBlue))
pv.procTable.SetCell(row, int(ProcessStateExit), tview.NewTableCell(strconv.Itoa(state.ExitCode)).SetAlign(tview.AlignRight).SetExpansion(0).SetTextColor(tcell.ColorLightSkyBlue))
rowVals := getTableRowValues(state)
setRowValues(pv.procTable, row, rowVals)
if state.IsRunning {
runningProcCount += 1
}
Expand All @@ -68,6 +73,18 @@ func (pv *pcView) fillTableData() {
}
}

func setRowValues(procTable *tview.Table, row int, rowVals tableRowValues) {
procTable.SetCell(row, int(ProcessStateIcon), tview.NewTableCell(rowVals.icon).SetAlign(tview.AlignCenter).SetExpansion(0).SetTextColor(rowVals.iconColor))
procTable.SetCell(row, int(ProcessStatePid), tview.NewTableCell(rowVals.pid).SetAlign(tview.AlignRight).SetExpansion(0).SetTextColor(tcell.ColorLightSkyBlue))
procTable.SetCell(row, int(ProcessStateName), tview.NewTableCell(rowVals.name).SetAlign(tview.AlignLeft).SetExpansion(1).SetTextColor(tcell.ColorLightSkyBlue))
procTable.SetCell(row, int(ProcessStateNamespace), tview.NewTableCell(rowVals.ns).SetAlign(tview.AlignLeft).SetExpansion(1).SetTextColor(tcell.ColorLightSkyBlue))
procTable.SetCell(row, int(ProcessStateStatus), tview.NewTableCell(rowVals.status).SetAlign(tview.AlignLeft).SetExpansion(1).SetTextColor(tcell.ColorLightSkyBlue))
procTable.SetCell(row, int(ProcessStateAge), tview.NewTableCell(rowVals.age).SetAlign(tview.AlignLeft).SetExpansion(1).SetTextColor(tcell.ColorLightSkyBlue))
procTable.SetCell(row, int(ProcessStateHealth), tview.NewTableCell(rowVals.health).SetAlign(tview.AlignLeft).SetExpansion(1).SetTextColor(tcell.ColorLightSkyBlue))
procTable.SetCell(row, int(ProcessStateRestarts), tview.NewTableCell(rowVals.restarts).SetAlign(tview.AlignRight).SetExpansion(0).SetTextColor(tcell.ColorLightSkyBlue))
procTable.SetCell(row, int(ProcessStateExit), tview.NewTableCell(rowVals.exitCode).SetAlign(tview.AlignRight).SetExpansion(0).SetTextColor(tcell.ColorLightSkyBlue))
}

func (pv *pcView) onTableSelectionChange(_, _ int) {
name := pv.getSelectedProcName()
if len(name) == 0 {
Expand Down Expand Up @@ -226,3 +243,40 @@ func getIconForState(state types.ProcessState) (string, tcell.Color) {
return "●", tcell.ColorLightSkyBlue
}
}

func getStrForRestarts(restarts int) string {
if restarts == 0 {
return types.PlaceHolderValue
}
return strconv.Itoa(restarts)
}

func getStrForExitCode(state types.ProcessState) string {
// running no exit info yet
if state.IsRunning && state.ExitCode == 0 {
return types.PlaceHolderValue
}
// disabled foreground or pending state
if state.Status == types.ProcessStateDisabled ||
state.Status == types.ProcessStatePending ||
state.Status == types.ProcessStateForeground {
return types.PlaceHolderValue
}
return strconv.Itoa(state.ExitCode)
}

func getTableRowValues(state types.ProcessState) tableRowValues {
icon, color := getIconForState(state)
return tableRowValues{
icon: icon,
iconColor: color,
pid: strconv.Itoa(state.Pid),
name: state.Name,
ns: state.Namespace,
status: state.Status,
age: state.SystemTime,
health: state.Health,
restarts: getStrForRestarts(state.Restarts),
exitCode: getStrForExitCode(state),
}
}
6 changes: 4 additions & 2 deletions src/tui/procstate_sorter.go
Original file line number Diff line number Diff line change
Expand Up @@ -140,10 +140,12 @@ func getSorter(sortBy ColumnID, states *types.ProcessesState) sortFn {
}
case ProcessStateExit:
return func(i, j int) bool {
if states.States[i].ExitCode == states.States[j].ExitCode {
eci := getStrForExitCode(states.States[i])
ecj := getStrForExitCode(states.States[j])
if eci == ecj {
return states.States[i].Name < states.States[j].Name
} else {
return states.States[i].ExitCode < states.States[j].ExitCode
return eci < ecj
}
}
case ProcessStateName:
Expand Down
5 changes: 3 additions & 2 deletions src/types/process.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import (
)

const DefaultNamespace = "default"
const PlaceHolderValue = "-"

type Processes map[string]ProcessConfig
type Environment []string
Expand Down Expand Up @@ -67,7 +68,7 @@ func NewProcessState(proc *ProcessConfig) *ProcessState {
Name: proc.ReplicaName,
Namespace: proc.Namespace,
Status: ProcessStatePending,
SystemTime: "",
SystemTime: PlaceHolderValue,
Age: time.Duration(0),
IsRunning: false,
Health: ProcessHealthUnknown,
Expand Down Expand Up @@ -130,7 +131,7 @@ const (
const (
ProcessHealthReady = "Ready"
ProcessHealthNotReady = "Not Ready"
ProcessHealthUnknown = "N/A"
ProcessHealthUnknown = PlaceHolderValue
)

type RestartPolicyConfig struct {
Expand Down

0 comments on commit 046de78

Please sign in to comment.