Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

plan: pretty-printing terminal output #22

Merged
merged 29 commits into from
Jun 8, 2016

Conversation

langston-barrett
Copy link
Contributor

Will detect (just like logrus) if there is a color terminal available. Can be manually disabled. Colors can easily be changed, but for now they are:

  • path: bold black
  • current status: yellow if willchange, blue otherwise
  • willchange: yellow if true, blue if false

fixes #12

@langston-barrett langston-barrett force-pushed the feature/plan-pretty-printing branch from 4066b59 to 28cb6bb Compare June 2, 2016 10:42
@langston-barrett
Copy link
Contributor Author

I'm having some trouble with godep... I can't make it save to vendor/ instead of Godeps/_workspace. Can someone help me out with this?


"github.com/Sirupsen/logrus"
"github.com/asteris-llc/converge/exec"
"github.com/asteris-llc/converge/load"
"github.com/spf13/cobra"
)

var nocolor bool
Copy link
Contributor

@BrianHicks BrianHicks Jun 2, 2016

Choose a reason for hiding this comment

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

please find a way to do this without introducing a global variable. We'll need this in more than one place. (hint: viper)

@BrianHicks
Copy link
Contributor

For the vendoring issue, what version of Go are you using? It should be 1.6+ and with the latest version of godep. From there, make vendor ought to be the ticket.

@BrianHicks
Copy link
Contributor

Also, could you attach a screenshot of the colored and plain output, please?

@langston-barrett langston-barrett force-pushed the feature/plan-pretty-printing branch from 28cb6bb to 17fc025 Compare June 2, 2016 20:36
@langston-barrett
Copy link
Contributor Author

@BrianHicks Ah, it was my version of Godep. Still not working, though :/

converge ➤ godep version
godep v74 (linux/amd64/go1.6.2)
converge ➤ go get ./... 
converge ➤ godep get ./...
converge ➤ make vendor        
godep save -t ./...
godep: Package (github.com/fsnotify/fsnotify) not found
Makefile:15: recipe for target 'vendor' failed
make: *** [vendor] Error 1

@langston-barrett
Copy link
Contributor Author

langston-barrett commented Jun 2, 2016

Here's the screenshot of the latest commit (f880891). Sorry for the crappy quality!

screenshot

@@ -25,6 +26,8 @@ import (
"github.com/spf13/viper"
)

var nocolor bool
Copy link
Contributor

Choose a reason for hiding this comment

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

this is still hangin' out here unused

Copy link
Contributor Author

Choose a reason for hiding this comment

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

hah! Thanks :)

@BrianHicks
Copy link
Contributor

BrianHicks commented Jun 3, 2016

just thinking about future extensibility here: I know we're going to have ApplyResult too. What if we made it so that PlanResult and ApplyResult both implemented an interface, then Results was just a slice of that interface? I'm thinking something like this:

type PrettyPrinter interface {
    fmt.Stringer
    Pretty() string
}

@langston-barrett
Copy link
Contributor Author

@BrianHicks What do you think the ApplyResult stuct should look like? Do you think that they'll have similar enough fields to make a shared interface sensible?

@BrianHicks
Copy link
Contributor

https://github.com/asteris-llc/converge/blob/master/exec/apply.go#L26-L31 but they don't need to have similar fields, they just need to be able to pretty print. You could do it with any list of objects. I actually think we're going to have to have a stream of objects instead for quicker feedback, though.

@langston-barrett
Copy link
Contributor Author

langston-barrett commented Jun 3, 2016

Okay, I've implemented a prettyPrinter interface for both ApplyResults and PlanResults, and used templates in both. All of them have tests which are now conceptually separate. Here's what it looks like:

screenshot

(note that while those trues look more red than green in the screenshot, I'm pretty sure that's just because of my terminal's color pallete. I tried in another terminal and it showed up just green)

Let me know what you think!

@BrianHicks
Copy link
Contributor

I'd like to see a blank line between each set, but otherwise that looks good. :)

}

// condFmt returns a function that only formats its input if a condition is true.
func condFmt(cond bool, format func(interface{}) string) func(interface{}) string {
Copy link
Contributor

Choose a reason for hiding this comment

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

this is used in both, so it belongs in a utility package. exec/utils.go springs to mind.

@langston-barrett
Copy link
Contributor Author

So in a29f8cb24f9b6a314b6ae1776372fa217eed8802, I attempted to add a newline between each Result, but when I try it in my shell, it doesn't show up 😨 Do you have any idea why that might be?

@langston-barrett langston-barrett force-pushed the feature/plan-pretty-printing branch from 41d9a32 to c1575c5 Compare June 6, 2016 11:33
@BrianHicks
Copy link
Contributor

Just to close the loop on my "streaming output" comment earlier, there is now streaming status. The list interface should be unaffected. :)

tmplStr += `Status: "{{blueOrYellow (trimNewline .OldStatus)}}" `
tmplStr += `=> "{{blueOrYellow (trimNewline .NewStatus)}}"`
tmplStr += "\n\tSuccess: {{redOrGreen .Success}}"
tmplStr := `{{plusOrMinus}}{{redOrGreen .Path}}:
Copy link
Contributor

Choose a reason for hiding this comment

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

space here, please. {{plusOrMinus}} {{redOrGreen .Path}}

@langston-barrett langston-barrett modified the milestone: 0.1 Jun 6, 2016
@langston-barrett langston-barrett mentioned this pull request Jun 7, 2016
@BrianHicks
Copy link
Contributor

I'll let you rewrite to use that utility function, it's merged :) When that's done, we'll merge this, looks good. Thanks for all your effort!

@langston-barrett
Copy link
Contributor Author

There's only one problem! That utility function is now in cmd which imports exec, so we can't have exec import it. Should we put it in a third spot?


// Print implements a pretty printer that uses ANSI terminal colors when a color
// terminal is available.
func (rs Results) Print() string {
Copy link
Contributor

Choose a reason for hiding this comment

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

@siddharthist regarding your comment: how about Print(color bool)? This is not the place to determine that anyway.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Sure!

@langston-barrett
Copy link
Contributor Author

@BrianHicks this is ready for review

@BrianHicks BrianHicks merged commit 734c11f into master Jun 8, 2016
@BrianHicks BrianHicks deleted the feature/plan-pretty-printing branch June 8, 2016 13:56
BrianHicks added a commit that referenced this pull request Dec 22, 2016
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.

Nicer plan output
2 participants