-
Notifications
You must be signed in to change notification settings - Fork 31
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
Use text/tabwriter to align human output #317
Conversation
output looks good on some:
but for docker it is a little ragged:
|
This is going to need some manual reviews. I set the tabwriter.Debug flag, to make it easier to see what it's doing to the text. We need to decide the parameters to pass into the tabwriter struct, take a look at line 142 in the diff and the tabwriter docs. |
@stevendborrelli that output actually looks completely fine to me. Are you saying you want it aligned on the arrows as well? |
@BrianHicks yes, it should be consistent. One test I had they were lined up, the other one they were not. |
let me make sure I've got this. Do you want this?
(I think that's less clear than ragged-right text, personally) |
hmm. Maybe we could make the arrow bright and then collapse that space? We're likely to run quite a bit over 80 characters if we align everything. |
We could also make the tabs narrower. Set the tabstop to 4 or 2 instead of 8 |
Doesn’t tabwriter convert to the smallest number of spaces anyway? On 29 Sep 2016, at 11:29, Sam Hatfield wrote:
|
There are controls for adding a number of spaces to each text cell before calculating anything else, as well as a minimum tab width. |
What about a tab width of 1 and boldening the arrows? On 29 Sep 2016, at 11:39, Sam Hatfield wrote:
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
it looks like tests might need to be updated and the branch is out of date with master. but, if that last screenshot reflects the new output: lgtm
@@ -173,7 +173,8 @@ func (p *Printer) diff(before, after string) (string, error) { | |||
// remember when modifying these that diff is responsible for leading | |||
// whitespace | |||
if !strings.Contains(strings.TrimSpace(before), "\n") && !strings.Contains(strings.TrimSpace(after), "\n") { | |||
return fmt.Sprintf("%q\t=>\t%q", strings.TrimSpace(before), strings.TrimSpace(after)), nil | |||
sprintf := []string{"%q\t", "\x1b[1m", "=>", "\x1b[22m", "\t%q"} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
why are you doing the extra allocation for this?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is an attempt at readability, but I can make it change it back
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That'd be great. We don't need to allocate a list every time 👍
@@ -197,7 +197,7 @@ func TestDrawNodeError(t *testing.T) { | |||
testDrawNodes( | |||
t, | |||
Printable{"error": "x"}, | |||
"root:\n Error: x\n Messages:\n Has Changes: yes\n Changes:\n error: \"\" => \"x\"\n\n", | |||
"root:\n Error: x\n Messages:\n Has Changes: yes\n Changes:\n error: \"\" \x1b[1m=>\x1b[22m \"x\"\n\n", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this should be using the same coloration logic as the rest of the human printer.
You mean the terminal escape sequence?
|
Yep On 5 Oct 2016, at 10:27, Sam Hatfield wrote:
|
This approach bolds the whole diff, not just the arrow. The |
yeah, it should only bold the error. Just add it as another field in the Sprintf call :) |
This commit adds the text/tabwriter package to the human prettyprinter package, and updates test case inputs. This aligns values based on a new tab inserted to the right of the colon. Fixes #244
Previous to this commit, I had terminal escape chars embedded in the diff function. With this, I moved that functionality to it's own definition in the prettyprinter's func map. This approach actually bolds more than the arrow, so it may have to be adjusted.
ea503d1
to
42c438a
Compare
@BrianHicks @ryane This has been rebased and finished up. Could y'all double check my work and merge, plz? |
…values Use text/tabwriter to align human output
This commit adds the text/tabwriter package to the human prettyprinter
package, and updates test case inputs. This aligns values based on a new
tab inserted to the right of the colon.
Fixes #244