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

text: add correct handling of hyperlink escape sequences (https://gis… #256

Merged
merged 5 commits into from
Feb 25, 2023

Conversation

vsemichev
Copy link
Contributor

…t.github.com/egmontkob/eb114294efbcd5adb1944c9f3cb5feda)

Proposed Changes

The changes I introduced to the text/string.go will allow the text functions to correctly handle the hyperlink escape sequences described in https://gist.github.com/egmontkob/eb114294efbcd5adb1944c9f3cb5feda

@coveralls
Copy link

coveralls commented Feb 20, 2023

Pull Request Test Coverage Report for Build 4268303129

  • 48 of 48 (100.0%) changed or added relevant lines in 1 file are covered.
  • No unchanged relevant lines lost coverage.
  • Overall coverage remained the same at 100.0%

Totals Coverage Status
Change from base Build 4080508282: 0.0%
Covered Lines: 3272
Relevant Lines: 3272

💛 - Coveralls

Makefile Outdated
@@ -11,7 +11,7 @@ bench:
go test -bench=. -benchmem

cyclo:
gocyclo -over 13 ./*/*.go
gocyclo -over 18 ./*/*.go
Copy link
Owner

Choose a reason for hiding this comment

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

Please don't do this. Increasing it to make this step pass is not the ideal solution, can you find a way to refactor the functionality (break logic into new functions if possible)?

Or if it is too much to do, I don't mind ignoring this comment - I can fix it later and refactor the functions to stay within complexity limits I've set for myself.

list/render.go Outdated
// - Is
// - Known
// - The Dark Tower
// - The Gunslinger
Copy link
Owner

Choose a reason for hiding this comment

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

Please undo this and all the other changes to comment blocks.

@@ -74,7 +88,7 @@ func LongestLineLen(str string) int {
maxLength = currLength
}
currLength = 0
} else if !isEscSeq {
} else if !isEscSeq && !isEscSeqAlt {
currLength += RuneWidth(c)
}
}
Copy link
Owner

Choose a reason for hiding this comment

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

Can you add unit-tests for the changes? Call the affected functions with text containing an escape sequence with a URL as defined in the spec linked?

text/string.go Outdated
Comment on lines 12 to 18
EscapeReset = EscapeStart + "0" + EscapeStop
EscapeStart = "\x1b["
EscapeStartAlt = "\x1b]8"
EscapeStartRune = rune(27) // \x1b
EscapeStop = "m"
EscapeStopRune = 'm'
EscapeStopRuneAlt = '\\'
Copy link
Owner

Choose a reason for hiding this comment

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

I wonder if there is a better way to do this for now and the future, in case another pattern needs to be supported. But this is a good start.

@vsemichev
Copy link
Contributor Author

vsemichev commented Feb 22, 2023 via email

@vsemichev
Copy link
Contributor Author

vsemichev commented Feb 24, 2023 via email

Copy link
Owner

@jedib0t jedib0t left a comment

Choose a reason for hiding this comment

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

Thanks for the refactor. Looks awesome now.

You still haven't reverted the white-space changes to all the comment blocks. And can you address the new comment on EscKind and EscSeq?

Can you fix that please and I can merge.

text/string.go Outdated
@@ -21,12 +25,48 @@ var (
rwCondition = runewidth.NewCondition()
)

type EscKind int
Copy link
Owner

Choose a reason for hiding this comment

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

Can you make EscKind and EscSeq private to this package? They don't need to be public.

@vsemichev
Copy link
Contributor Author

vsemichev commented Feb 24, 2023 via email

@vsemichev
Copy link
Contributor Author

Ok. I've fixed the comment formatting and reverted back to what it was prior to "go fmt" messing it up. I've also changed EscSeq and EscKind to be private to the text package. I'll add a unit test for the URL escape sequence, just to make sure it is handled correctly and then we'll be ready to merge (hopefully) :)

@sonarcloud
Copy link

sonarcloud bot commented Feb 25, 2023

Kudos, SonarCloud Quality Gate passed!    Quality Gate passed

Bug A 0 Bugs
Vulnerability A 0 Vulnerabilities
Security Hotspot A 0 Security Hotspots
Code Smell A 0 Code Smells

No Coverage information No Coverage information
No Duplication information No Duplication information

@vsemichev
Copy link
Contributor Author

Hey Naveen, I've added some unit test cases for hyperlink escape sequences, so we should be ready to merge.
Please, take a look and let me know if you have any concerns.

Copy link
Owner

@jedib0t jedib0t left a comment

Choose a reason for hiding this comment

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

Looks awesome! Thanks for the contribution!

@jedib0t jedib0t merged commit e2e2386 into jedib0t:main Feb 25, 2023
@jedib0t
Copy link
Owner

jedib0t commented Feb 27, 2023

@vsemichev I've just cut a new tag with this change: https://github.com/jedib0t/go-pretty/releases/tag/v6.4.5

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.

None yet

4 participants