Skip to content

Commit

Permalink
configurable colors; fixed error detection
Browse files Browse the repository at this point in the history
  • Loading branch information
wagoodman committed Feb 4, 2018
1 parent da02808 commit e04d9ec
Show file tree
Hide file tree
Showing 5 changed files with 33 additions and 14 deletions.
16 changes: 16 additions & 0 deletions config.go
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,18 @@ type OptionsConfig struct {
// CollapseOnCompletion indicates when a task with child tasks should be "rolled up" into a single line after all tasks have been executed
CollapseOnCompletion bool `yaml:"collapse-on-completion"`

// ColorRunning is the color of the vertical progress bar when the task is running (# in the 256 palett)
ColorRunning int `yaml:"running-status-color"`

// ColorPending is the color of the vertical progress bar when the task is waiting to be ran (# in the 256 palett)
ColorPending int `yaml:"pending-status-color"`

// ColorSuccessg is the color of the vertical progress bar when the task has finished successfully (# in the 256 palett)
ColorSuccess int `yaml:"success-status-color"`

// ColorError is the color of the vertical progress bar when the task has failed (# in the 256 palett)
ColorError int `yaml:"error-status-color"`

// EventDriven indicates if the screen should be updated on any/all task stdout/stderr events or on a polling schedule
EventDriven bool `yaml:"event-driven"`

Expand Down Expand Up @@ -106,6 +118,10 @@ type OptionsConfig struct {
// NewOptionsConfig creates a new OptionsConfig populated with sane default values
func NewOptionsConfig() (obj OptionsConfig) {
obj.BulletChar = "•"
obj.ColorError = 160
obj.ColorPending = 22
obj.ColorRunning = 22
obj.ColorSuccess = 10
obj.EventDriven = true
obj.ExecReplaceString = "<exec>"
obj.IgnoreFailure = false
Expand Down
1 change: 1 addition & 0 deletions example/06-with-errors.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
config:
# Want to keep a running count of errors in the summary footer? Enable this...
show-summary-errors: true
log-path: build.log

tasks:
# This task will fail and be counted as a failure, however,
Expand Down
6 changes: 6 additions & 0 deletions example/08-complicated.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,12 @@ config:
# with a command running)
show-task-times: true

# Change the color of each task status in the vertical progress bar
success-status-color: 2
running-status-color: 3
pending-status-color: 4
error-status-color: 1

x-reference-data:
all-apps: &app-names
- some-lib-4
Expand Down
18 changes: 7 additions & 11 deletions task.go
Original file line number Diff line number Diff line change
Expand Up @@ -152,16 +152,16 @@ const (
func (status CommandStatus) Color(attributes string) string {
switch status {
case statusRunning:
return color.ColorCode("22+" + attributes) //28
return color.ColorCode(strconv.Itoa(config.Options.ColorRunning) + "+" + attributes)

case statusPending:
return color.ColorCode("22+" + attributes)
return color.ColorCode(strconv.Itoa(config.Options.ColorPending) + "+" + attributes)

case statusSuccess:
return color.ColorCode("green+h" + attributes)
return color.ColorCode(strconv.Itoa(config.Options.ColorSuccess) + "+" + attributes)

case statusError:
return color.ColorCode("red+h" + attributes)
return color.ColorCode(strconv.Itoa(config.Options.ColorError) + "+" + attributes)

}
return "INVALID COMMAND STATUS"
Expand Down Expand Up @@ -261,7 +261,7 @@ func (task *Task) inflateCmd() {
readFd, writeFd, err := os.Pipe()
checkError(err, "Could not open env pipe for child shell")

task.Command.Cmd = exec.Command(shell, "-c", task.Config.CmdString+"; env >&3")
task.Command.Cmd = exec.Command(shell, "-c", task.Config.CmdString+"; BASHFUL_RC=$?; env >&3; exit $BASHFUL_RC")

// allow the child process to provide env vars via a pipe (FD3)
task.Command.Cmd.ExtraFiles = []*os.File{writeFd}
Expand Down Expand Up @@ -554,7 +554,7 @@ func (task *Task) runSingleCmd(resultChan chan CmdEvent, waiter *sync.WaitGroup,
}
task.Command.StopTime = time.Now()

logToMain("Completed Task: "+task.Config.Name+" (rc: "+returnCodeMsg+")", infoFormat)
logToMain("Completed Task: "+task.Config.Name+" (rc:"+strconv.Itoa(returnCode)+")", infoFormat)

// close the write end of the pipe since the child shell is positively no longer writting to it
task.Command.Cmd.ExtraFiles[0].Close()
Expand Down Expand Up @@ -643,7 +643,7 @@ func (task *Task) Completed(rc int) {
func (task *Task) listenAndDisplay(environment map[string]string) {
scr := newScreen()
// just wait for stuff to come back
WhileRunningCommands:

for TaskStats.runningCmds > 0 {
select {
case <-ticker.C:
Expand Down Expand Up @@ -707,10 +707,6 @@ WhileRunningCommands:
scr.MovePastFrame(false)
}

if exitSignaled {
break WhileRunningCommands
}

}

}
Expand Down
6 changes: 3 additions & 3 deletions task_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,18 +15,18 @@ func TestTaskString(t *testing.T) {
CmdString: "/bin/true",
}
task := NewTask(taskConfig, 1, "2")
task.Display.Values = LineInfo{Status: statusSuccess.Color("i"), Title: task.Config.Name, Msg: "some message", Prefix: "$", Eta: "SOMEETAVALUE"}
task.Display.Values = LineInfo{Status: statusSuccess.Color(""), Title: task.Config.Name, Msg: "some message", Prefix: "$", Eta: "SOMEETAVALUE"}

testOutput = task.String(50)
expectedOutput = " \x1b[7;92m \x1b[0m • some name! som...SOMEETAVALUE"
expectedOutput = " \x1b[38;5;10m \x1b[0m • some name! som...SOMEETAVALUE"
if expectedOutput != testOutput {
t.Error("TestTaskString (default): Expected", repr.String(expectedOutput), "got", repr.String(testOutput))
}

config.Options.ShowTaskEta = false
task.Display.Values.Title = "123456789qwertyuiopasdfghjklzxcvbnm234567890qwertyuiopasdfghjklzxcvbnm123456789qwertyuiopasdfghjklzxcvbnm234567890qwertyuiopasdfghjklzxcvbnm"
testOutput = task.String(20)
expectedOutput = " \x1b[7;92m \x1b[0m • 123456789qwertyuiopasdfghjklzxcvbnm234567890qwertyuiopasdfghjklzxcvbnm123456789qwertyuiopasdfghjklzxcvbnm234567890qwertyuiopasdfghjklzxcvbnm s...SOMEETAVALUE"
expectedOutput = " \x1b[38;5;10m \x1b[0m • 123456789qwertyuiopasdfghjklzxcvbnm234567890qwertyuiopasdfghjklzxcvbnm123456789qwertyuiopasdfghjklzxcvbnm234567890qwertyuiopasdfghjklzxcvbnm s...SOMEETAVALUE"
if expectedOutput != testOutput {
t.Error("TestTaskString (eta, truncate): Expected", repr.String(expectedOutput), "got", repr.String(testOutput))
}
Expand Down

0 comments on commit e04d9ec

Please sign in to comment.