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

Improve escape sequence compatibility #656

Merged
merged 1 commit into from
Nov 14, 2024
Merged

Improve escape sequence compatibility #656

merged 1 commit into from
Nov 14, 2024

Conversation

noborus
Copy link
Owner

@noborus noborus commented Nov 14, 2024

  • Enhanced handling of invalid values in escape sequences to better match terminal and `less`` behavior.
  • Updated related functions to ensure compatibility.
  • Improved error handling and reporting for invalid escape sequences.

- Enhanced handling of invalid values in escape sequences
  to better match terminal and `less`` behavior.
- Updated related functions to ensure compatibility.
- Improved error handling and reporting for invalid escape sequences.
@noborus noborus merged commit b1b251b into master Nov 14, 2024
8 checks passed
@noborus noborus deleted the es-compatibility branch November 14, 2024 22:04
@@ -90,6 +96,9 @@ func (es *escapeSequence) convert(st *parseState) bool {
case mainc >= '0' && mainc <= 'f':
es.parameter.WriteRune(mainc)
return true
case mainc < 0x40:
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 a magical number here, you should either explain why it's 0x40, or add a constant with a meaningful name

0x40 is @ right? 0x41 is A

What is this if statement about?

Checking that anything before @ is handled in a common way? But then @ is not caught?

I'm still unsure about what the code does

num, err := strconv.Atoi(str)
if err != nil {
for _, char := range str {
if char >= 0x40 {
Copy link
Contributor

Choose a reason for hiding this comment

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

Same test with 0x40

}

// csColor parses 8-bit color and 24-bit color.
func csColor(fields []string) (int, string) {
if len(fields) < 2 {
return 0, ""
}
if fields[1] == "" {
return 1, ""
Copy link
Contributor

Choose a reason for hiding this comment

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

Please use constant for 0-5 and give them meaningful names

s.Bold = true
case "2", "02":
case 2:
Copy link
Contributor

Choose a reason for hiding this comment

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

Please use constants for all these numbers, and give them names

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