Skip to content

codespace: progress indicator, stdlib logger#4555

Merged
mislav merged 24 commits intotrunkfrom
jg/universe-prep
Oct 21, 2021
Merged

codespace: progress indicator, stdlib logger#4555
mislav merged 24 commits intotrunkfrom
jg/universe-prep

Conversation

@josebalius
Copy link
Contributor

@josebalius josebalius commented Oct 18, 2021

I've merged the progress indicator into this PR. I think it is ready for review. The major TODO outstanding is figuring out the spinner color.

progress-indicator


OP:

  • Updates the NewApp to accept an iostreams.IOStreams pointer instead of an output.Logger
  • App now creates an error logger, and checks for interactivity (TTY)
  • The application still needs to Print UI-like behavior (for example . as a progress indicator) - Ideally this would be done with the spinner, I have another PR that does this but trying to keep the diffs reasonable. In order to support a dotter-like UI, we are using *App.Print and *App.Println to do so which noops in non-interactive environments, matching the existing behavior.
  • I couldn't use a*log.Logger for app printing, because *log.Logger automatically appends a \n to all logs, so it is impossible to use the logger to print to the same line, once we switch to a progress indicator, we can switch to a logger like this since we don't need same-line printing.

This PR should essentially retain the exact same behavior we have today except without *output.Logger

@josebalius josebalius requested review from a team as code owners October 18, 2021 15:55
@josebalius josebalius requested review from samcoe and removed request for a team October 18, 2021 15:55
@josebalius josebalius changed the title codespace: use iostreams, stop using output.Logger codespace: progress indicator, stdlib logger Oct 18, 2021
@josebalius josebalius requested a review from mislav October 18, 2021 23:49
@josebalius
Copy link
Contributor Author

I think this is ready for 👀 - I plan to look at how we can possibility set the right spinner color tomorrow based on terminal bg. I think that's the only thing blocking from this shipping (apart from reviews). Feel free to pull down the PR and run a few commands, it "feels" snappier, I like the spinner.

@josebalius josebalius self-assigned this Oct 19, 2021
@adonovan
Copy link
Contributor

I plan to look at how we can possibility set the right spinner color

What's wrong with simply using the foreground color? Presumably the user chose it for its contrast against the background.

@josebalius
Copy link
Contributor Author

What's wrong with simply using the foreground color? Presumably the user chose it for its contrast against the background.

Nothing, I am actually starting to think it's my terminal that's messed up.

  1. The termenv pkg the CLI uses seems to think I have a dark bg (it's grayish)
  2. If I pass fgBlack as a color to the spinner, I get the light non-visible color.

🤔

@josebalius
Copy link
Contributor Author

I've updated the logic to make it fgBlack on light themes instead of using the default white. It is still doesn't for me but I think it's due to my config.

// 11 means Braille. See https://github.com/briandowns/spinner#available-character-sets
sp := spinner.New(spinner.CharSets[11], 400*time.Millisecond, opts...)

if s.TerminalTheme() == "light" {
Copy link
Contributor

@adonovan adonovan Oct 19, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I can't really guess what this does: a "terminal theme" is not a concept in the ANSI terminal spec; it appears to be a heuristic inferred from a handful of nonstandard environment variables such as COLORTERM, NO_COLOR, CLICOLOR, and CLICOLOR_FORCE.

I would hope that saying nothing at all about color here would yield a sensible behavior. Indeed, it does for me, when I run this PR without this line: I see gray braille animated against a white background.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It has to be my setup then 😭 - happy to remove this. I think @mislav was going to take a look.

- Use "cyan" instead of "white" color which is barely legible on light
  terminal backgrounds
- Use 120ms instead of 400ms rendering delay so that the spinner
  feels faster
- Rename StartProgressIndicatorWithSuffix to
  StartProgressIndicatorWithLabel to be agnostic to presentation logic
- Enable changing the label of the currently active progress indicator
- Make Start/StopProgressIndicator methods parallelism-safe
@mislav mislav merged commit bbea5ac into trunk Oct 21, 2021
@mislav mislav deleted the jg/universe-prep branch October 21, 2021 16:04
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants