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

Initial support for rendering wrapped, bulleted lists. #3576

Merged
merged 4 commits into from
Nov 6, 2024

Conversation

mitchell-as
Copy link
Contributor

@mitchell-as mitchell-as commented Oct 31, 2024

TaskDX-2829 Failure messages remain indented with line breaks

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.

Screenshot 2024-11-01 at 6 07 26 PM

Also do not put wrapped links on their own line.
Copy link
Member

@Naatan Naatan left a 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.

@mitchell-as mitchell-as requested a review from Naatan November 1, 2024 22:12
@@ -7,82 +7,82 @@ import (
"testing"
)

func Test_GetCroppedText(t *testing.T) {
Copy link
Member

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".

@@ -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 {
Copy link
Member

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.

Comment on lines 87 to 88
logging.Debug("continuation: '%s'", continuation)
logging.Debug("wrapped: '%s'", wrapped)
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
logging.Debug("continuation: '%s'", continuation)
logging.Debug("wrapped: '%s'", wrapped)

return &bulletList{prefix, items, bullets}
}

func (b *bulletList) MarshalOutput(format output.Format) interface{} {
Copy link
Member

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..

Copy link
Member

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.

Comment on lines 41 to 44
if len(bullets) != 4 {
multilog.Error("Invalid bullet list: 4 bullets required")
bullets = BulletTree
}
Copy link
Member

Choose a reason for hiding this comment

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

Should return the error.

Copy link
Contributor Author

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.

Comment on lines 29 to 30
// ├─ two
// │ wrapped
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
// ├─ two
// │ wrapped
// ├─ two
// │ wrapped

// ├─ two
// │ wrapped
// └─ three
var BulletTree = []string{output.TreeMid, output.TreeMid, output.TreeLink + " ", output.TreeEnd}
Copy link
Member

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))
Copy link
Member

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].

Copy link
Contributor Author

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))
Copy link
Member

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))
Copy link
Member

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?

Copy link
Contributor Author

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.

var indentRegexp = regexp.MustCompile(`^([ ]+)`)
var isLinkRegexp = regexp.MustCompile(`\s*(\[[^\]]+\])?https?://`)

func Wrap(text string, maxLen int, includeLineEnds bool, continuation string) WrappedLines {
Copy link
Contributor Author

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 {
Copy link
Contributor Author

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) {
Copy link
Contributor Author

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.

@mitchell-as mitchell-as requested a review from Naatan November 6, 2024 17:16
Copy link
Member

@Naatan Naatan left a 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..

@mitchell-as mitchell-as closed this Nov 6, 2024
@mitchell-as mitchell-as reopened this Nov 6, 2024
@mitchell-as mitchell-as merged commit fb1c600 into version/0-48-0-RC1 Nov 6, 2024
12 of 15 checks passed
@mitchell-as mitchell-as deleted the mitchell/dx-2829-2 branch November 6, 2024 19:30
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.

2 participants