Skip to content

Commit

Permalink
fix various bar rendering issues
Browse files Browse the repository at this point in the history
* fix bar rendering leftovers in the output
* fix artifacts in bar format like missing symbols or different colors
* clear bar on the exit
* add default bar theme both for dark and light backgrounds
* update successfully executed nodes count
* fix missing bar when no stdin is given
  • Loading branch information
seletskiy committed Jul 29, 2016
1 parent 3091d27 commit 626baff
Show file tree
Hide file tree
Showing 5 changed files with 58 additions and 32 deletions.
4 changes: 4 additions & 0 deletions log.go
Expand Up @@ -105,6 +105,8 @@ func fatalf(format string, args ...interface{}) {

logger.Fatalf(`%s`, wrapNewLines(format, args...))

clearStatus()

exit(1)
}

Expand Down Expand Up @@ -137,6 +139,8 @@ func setStatus(status interface{}) {
}

bar.SetStatus(status)

drawStatus()
}

func shouldDrawStatus() bool {
Expand Down
59 changes: 35 additions & 24 deletions main.go
Expand Up @@ -185,13 +185,13 @@ Output format and colors options:
For example, run orgalorg with '-vv' flag.
Two embedded themes are available by their names:
` + themeDark + ` and ` + themeLight + `
[default: ` + themeDark + `]
[default: ` + themeDefault + `]
--log-format <f> Format for the logs.
See https://github.com/reconquest/colorgful for more
info.
[default: ` + themeDark + `]
--dark Set all available formats to predefined dark theme.
--light Set all available formats to predefined light theme.
[default: ` + themeDefault + `]
--colors-dark Set all available formats to predefined dark theme.
--colors-light Set all available formats to predefined light theme.
--color <mode> Specify, whether to use colors:
* never - disable colors;
* auto - use colors only when TTY presents.
Expand Down Expand Up @@ -275,26 +275,7 @@ func main() {

pool = newThreadPool(poolSize)

barStyle, err := getStatusBarTheme(parseTheme("bar", args))
if err != nil {
errorf("%s", hierr.Errorf(
err,
`can't use given status bar style`,
))
}

if loreley.HasTTY(int(os.Stderr.Fd())) {
bar = barely.NewStatusBar(barStyle.Template)
} else {
bar = nil

sshPasswordPrompt = ""
sshPassphrasePrompt = ""
}

if loreley.HasTTY(int(os.Stdin.Fd())) {
bar = nil
}
setupInteractiveMode(args)

switch {
case args["--upload"].(bool):
Expand Down Expand Up @@ -863,6 +844,36 @@ func parseAddresses(
return getUniqueAddresses(addresses), nil
}

func setupInteractiveMode(args map[string]interface{}) {
var (
_, hasStdin = args["--stdin"].(string)

barLock = &sync.Mutex{}
)

barStyle, err := getStatusBarTheme(parseTheme("bar", args))
if err != nil {
errorf("%s", hierr.Errorf(
err,
`can't use given status bar style`,
))
}

if loreley.HasTTY(int(os.Stderr.Fd())) {
bar = barely.NewStatusBar(barStyle.Template)
bar.SetLock(barLock)
} else {
bar = nil

sshPasswordPrompt = ""
sshPassphrasePrompt = ""
}

if hasStdin && loreley.HasTTY(int(os.Stdin.Fd())) {
bar = nil
}
}

func generateRunID() string {
return time.Now().Format("20060102150405.999999")
}
Expand Down
2 changes: 2 additions & 0 deletions remote_execution.go
Expand Up @@ -75,6 +75,8 @@ func (execution *remoteExecution) wait() error {
continue
}

status.Success++

tracef(
`%s has successfully finished execution`,
result.node.node.String(),
Expand Down
4 changes: 1 addition & 3 deletions status_bar_update_writer.go
@@ -1,8 +1,6 @@
package main

import (
"io"
)
import "io"

type statusBarUpdateWriter struct {
writer io.WriteCloser
Expand Down
21 changes: 16 additions & 5 deletions themes.go
Expand Up @@ -9,8 +9,9 @@ import (
)

const (
themeDark = `dark`
themeLight = `light`
themeDefault = `default`
themeDark = `dark`
themeLight = `light`
)

var (
Expand All @@ -32,20 +33,30 @@ var (
statusBarThemes = map[string]string{
themeDark: fmt.Sprintf(
statusBarThemeTemplate,
99, 7, 22, 1, 25, 237, 46, 15, 214, 16, 140,
99, 7, 22, 1, 25, 237, 46, 15, 214, -1, 140,
),

themeLight: fmt.Sprintf(
statusBarThemeTemplate,
99, 7, 22, 1, 64, 254, 106, 16, 9, -1, 140,
),

themeDefault: fmt.Sprintf(
statusBarThemeTemplate,
234, 255, 22, 1, 19, 245, 85, 255, 160, -1, 140,
),
}

logFormat = `${time} ${level:[%s]:right:true} %s`
)

func getLoggerTheme(theme string) (lorg.Formatter, error) {
switch theme {
case "default":
return colorgful.ApplyDefaultTheme(
logFormat,
colorgful.Default,
)
case "dark":
return colorgful.ApplyDefaultTheme(
logFormat,
Expand Down Expand Up @@ -77,8 +88,8 @@ func getStatusBarTheme(theme string) (*loreley.Style, error) {
func parseTheme(target string, args map[string]interface{}) string {
var (
theme = args["--"+target+"-format"].(string)
light = args["--light"].(bool)
dark = args["--dark"].(bool)
light = args["--colors-light"].(bool)
dark = args["--colors-dark"].(bool)
)

switch {
Expand Down

0 comments on commit 626baff

Please sign in to comment.