makew0rld / amfora

A fancy terminal browser for the Gemini protocol.
GNU General Public License v3.0
1.14k stars 65 forks source link

ANSI color is shifted off by one by close bracket #264

Open mntn-xyz opened 2 years ago

mntn-xyz commented 2 years ago

Source file:

```
^[[0mThis is a short [^[[1m^[[37m^[[40mMarkdown^[[0m](^[[36m^[[40mhttps://en.wikipedia.org/wiki/Markdown^[[0m) line.
```

Result: image

How it looks with cat:

image

mntn-xyz commented 2 years ago

It might not be the fault of the close bracket but I suspect it since that's seemingly where the problem begins.

Edit: Here's the simplest possible case for replication:

```
[TEST^[[0m]^[[36mTEST
```

Removing the open bracket, the text between the brackets, the ^[[0m, or the close bracket will allow the colored text at the end of the line to work properly.

makew0rld commented 2 years ago

Thanks for the report and test case. This most likely an upstream issue with cview. I can open an issue with them at some point, after testing and confirming the issue is with that library.

makew0rld commented 2 years ago

Do you think this is the same as https://code.rocketnine.space/tslocum/cview/issues/48 as you mentioned in #263?

mntn-xyz commented 2 years ago

Thanks. I'm not sure anymore... in #263, I made a test program that uses cview and was not able to replicate it with a simple cview setup. But it's possible that some of the cview settings used by Amfora causes the bug to surface.

makew0rld commented 2 years ago

Ah I see that now. Thanks, I'll look into it when I can. Feel free to let me know what you find as well.

Also, I feel I should let you know I'm not devoting a lot of time to Amfora these days. The project is not abandoned, and PRs will be reviewed and merged. But I'm not working much on the issues myself. This might change in the future, but it's how it is right now. I appreciate you reporting bugs and making PRs though, so thank you.

mntn-xyz commented 2 years ago

No problem, that's understandable as it does seem to be mostly complete as is. I'll do my best to track down these issues myself; my schedule is just unpredictable so I'm not able to consistently work on it. But slow progress is better than none :)

makew0rld commented 2 years ago

For sure, no worries.

mntn-xyz commented 2 years ago

It's a cview bug, probably in cview's escaping. I was able to replicate by adding a call to cview.Escape before the TranslateANSI call.

package main

import (
        "code.rocketnine.space/tslocum/cview"
)

func main() {
        app := cview.NewApplication()

        tv := cview.NewTextView()
        tv.SetDynamicColors(true)
        tv.SetText(cview.TranslateANSI(cview.Escape("[TEST\033[0m]\033[36mTEST")))
        app.SetRoot(tv, true)
        if err := app.Run(); err != nil {
                panic(err)
        }
}

Edit: It also cuts off the last character!

makew0rld commented 2 years ago

Thanks for confirming. I've opened https://code.rocketnine.space/tslocum/cview/issues/79 upstream.