Skip to content

Commit 1124ffb

Browse files
Andrea Falzettiroboquat
Andrea Falzetti
authored andcommitted
feat(gitpod-cli): highlight current task
1 parent 4091496 commit 1124ffb

File tree

1 file changed

+27
-1
lines changed

1 file changed

+27
-1
lines changed

components/gitpod-cli/cmd/tasks-list.go

Lines changed: 27 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ import (
1414
supervisor_helper "github.com/gitpod-io/gitpod/gitpod-cli/pkg/supervisor-helper"
1515
"github.com/gitpod-io/gitpod/gitpod-cli/pkg/utils"
1616
"github.com/gitpod-io/gitpod/supervisor/api"
17+
supervisor "github.com/gitpod-io/gitpod/supervisor/api"
1718
"github.com/spf13/cobra"
1819

1920
"github.com/olekukonko/tablewriter"
@@ -48,11 +49,36 @@ var listTasksCmd = &cobra.Command{
4849
2: tablewriter.FgHiBlackColor,
4950
}
5051

52+
mapCurrentToColor := map[bool]int{
53+
false: tablewriter.FgWhiteColor,
54+
true: tablewriter.FgHiGreenColor,
55+
}
56+
57+
ppid := int64(os.Getppid())
58+
5159
for _, task := range tasks {
5260
colors := []tablewriter.Colors{}
5361

62+
isCurrent := false
63+
64+
if task.State == api.TaskState_running {
65+
terminalClient, err := supervisor_helper.GetTerminalServiceClient(context.Background())
66+
if err != nil {
67+
log.Fatalf("cannot get terminal service: %s", err)
68+
}
69+
70+
terminal, err := terminalClient.Get(context.Background(), &supervisor.GetTerminalRequest{Alias: task.Terminal})
71+
if err != nil {
72+
panic(err)
73+
}
74+
75+
if ppid == terminal.Pid {
76+
isCurrent = true
77+
}
78+
}
79+
5480
if !noColor && utils.ColorsEnabled() {
55-
colors = []tablewriter.Colors{{}, {}, {mapStatusToColor[task.State]}}
81+
colors = []tablewriter.Colors{{mapCurrentToColor[isCurrent]}, {}, {mapStatusToColor[task.State]}}
5682
}
5783

5884
table.Rich([]string{task.Terminal, task.Presentation.Name, task.State.String()}, colors)

0 commit comments

Comments
 (0)