Moved the session state color selection logic from list.go to a new shared/display.go file as ColorFuncForSessionState. This improves code reuse and maintainability by centralizing the color mapping for session states.
25 lines
580 B
Go
25 lines
580 B
Go
package shared
|
|
|
|
import (
|
|
"github.com/cli/cli/v2/pkg/cmd/agent-task/capi"
|
|
"github.com/cli/cli/v2/pkg/iostreams"
|
|
)
|
|
|
|
// ColorFuncForSessionState returns a function that colors the session state
|
|
func ColorFuncForSessionState(s capi.Session, cs *iostreams.ColorScheme) func(string) string {
|
|
var stateColor func(string) string
|
|
switch s.State {
|
|
case "completed":
|
|
stateColor = cs.Green
|
|
case "canceled":
|
|
stateColor = cs.Muted
|
|
case "in_progress", "queued":
|
|
stateColor = cs.Yellow
|
|
case "failed":
|
|
stateColor = cs.Red
|
|
default:
|
|
stateColor = cs.Muted
|
|
}
|
|
|
|
return stateColor
|
|
}
|