-
Notifications
You must be signed in to change notification settings - Fork 13
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
Initial support for rendering wrapped, bulleted lists. #3576
Conversation
Also do not put wrapped links on their own line.
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.
First review based on screenshot alone, I'll review the code once we get it looking right so we're not churning on code that's still gonna be changed.
- The indented message seems to be missing one space
- The indentation marks should not be given the color of the message (ie. they should remain black/default regardless of the message color).
I recognize the second point might require some significant business logic. Please move it back to triage if this creates a lot of additional work. This isn't worth a ton of investment, but we also shouldn't land the change as is since it's just trading one visual bug for another.
90b0b6c
to
55a07c0
Compare
internal/colorize/wrap_test.go
Outdated
@@ -7,82 +7,82 @@ import ( | |||
"testing" | |||
) | |||
|
|||
func Test_GetCroppedText(t *testing.T) { |
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.
Please add tests covering the new mechanic. Particularly color codes not covering the "continuation".
internal/colorize/wrap.go
Outdated
@@ -100,6 +115,19 @@ func inRange(pos int, ranges [][]int) bool { | |||
return false | |||
} | |||
|
|||
// colorTag returns the currently active color tag (if any) at the given position. | |||
func colorTag(pos int, ranges [][]int, names [][]string) string { |
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 assumes there's only ever one color tag, but we could have: [BOLD][RED]
, for example.
internal/colorize/wrap.go
Outdated
logging.Debug("continuation: '%s'", continuation) | ||
logging.Debug("wrapped: '%s'", wrapped) |
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.
logging.Debug("continuation: '%s'", continuation) | |
logging.Debug("wrapped: '%s'", wrapped) |
return &bulletList{prefix, items, bullets} | ||
} | ||
|
||
func (b *bulletList) MarshalOutput(format output.Format) interface{} { |
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.
Unless this creates some deep rabbit hole I'd prefer we don't address the magical output handling that we're slowly phasing out. So this could just be a String()
function, or whatever you feel is appropriate so long as it's not trying to satisfy the output interface.
That also means that use-cases of this functionality will need to handle structured vs non-structured themselves. That part might be a rabbit hole, depending on the use-cases we have..
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.
Also worth having a unit test for this.
if len(bullets) != 4 { | ||
multilog.Error("Invalid bullet list: 4 bullets required") | ||
bullets = BulletTree | ||
} |
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.
Should return the error.
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.
By making it typed as suggested later in the review, there cannot be an error to return anymore.
// ├─ two | ||
// │ wrapped |
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.
// ├─ two | |
// │ wrapped | |
// ├─ two | |
// │ wrapped |
// ├─ two | ||
// │ wrapped | ||
// └─ three | ||
var BulletTree = []string{output.TreeMid, output.TreeMid, output.TreeLink + " ", output.TreeEnd} |
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.
Since we're using presets anyway, can we make this typed so it's easier to understand the code while reading?
eg.
type Bullets {
Start string
Mid string
Link string
End string
}
@@ -130,8 +127,9 @@ func OutputChangeSummary(out output.Outputer, newBuildPlan *buildplan.BuildPlan, | |||
item = fmt.Sprintf("[ACTIONABLE]%s@%s[/RESET] → %s (%s)", oldVersion.Name, oldVersion.Version, item, locale.Tl("updated", "updated")) | |||
} | |||
|
|||
out.Notice(fmt.Sprintf(" [DISABLED]%s[/RESET] %s", prefix, item)) |
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 seems to be dropping the [DISABLED]
.
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.
There's a new BulletTreeDisabled
preset.
} | ||
|
||
out.Notice(renderers.NewBulletList(" ", renderers.BulletTree, items)) |
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.
Fwiw, with regards to dropping the magical output handing, this could simply become:
out.Notice(renderers.NewBulletList(" ", renderers.BulletTree, items).String())
@@ -44,10 +41,9 @@ func OutputSummary(out output.Outputer, directDependencies buildplan.Artifacts) | |||
subdepLocale = locale.Tl("summary_subdeps", "([ACTIONABLE]{{.V0}}[/RESET] sub-dependencies)", strconv.Itoa(numSubs)) | |||
} | |||
|
|||
item := fmt.Sprintf("[ACTIONABLE]%s@%s[/RESET] %s", ingredient.Name, ingredient.Version, subdepLocale) | |||
|
|||
out.Notice(fmt.Sprintf("[DISABLED]%s[/RESET] %s", prefix, item)) |
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 drop the DISABLED item here?
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.
There's a new BulletTreeDisabled
preset I'm using now.
…hod instead of output marshaler method.
e52ce9c
to
fe25e87
Compare
var indentRegexp = regexp.MustCompile(`^([ ]+)`) | ||
var isLinkRegexp = regexp.MustCompile(`\s*(\[[^\]]+\])?https?://`) | ||
|
||
func Wrap(text string, maxLen int, includeLineEnds bool, continuation string) WrappedLines { |
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.
Despite me doing a rename, GitHub thinks this entire file is new. I refactored this method and added colorTags()
below. That's it. Everything else is the same.
} | ||
|
||
// colorTags returns the currently active color tags (if any) at the given position. | ||
func colorTags(pos int, ranges [][]int, names [][]string) []string { |
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 new after the rename.
} | ||
} | ||
|
||
func TestWrapBullet(t *testing.T) { |
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.
Despite renaming this file, GitHub thinks all of its contents are new. I added this test and the one that follows. The tests above I left alone.
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.
Nice work! Almost felt like I was reviewing a Komodo PR..
Also do not put wrapped links on their own line. Links are not wrapped and indented because they would not be copy-pastable into browsers without manual removal of spaces and/or newlines.