awesome-gocui / gocui

Minimalist Go package aimed at creating Console User Interfaces.
BSD 3-Clause "New" or "Revised" License
344 stars 39 forks source link

Fix how wide runes are displayed #109

Closed dankox closed 2 years ago

dankox commented 2 years ago

This PR should fix problems with wide characters displaying and editing and also SetWritePos function not working correctly.

Internal cell buffer represent each rune which should be displayed as a single cell. This cell buffer is translated into tcell representation in View.draw(). For wide runes, it will be set as one cell with the rune and following cell would be empty (until the width of the rune).

This was used before, but internal representation was using rune width in some places making it mixed and therefore creating some problems with the wide runes.

@aynakeya can you please check and test this PR for your problem? I think it should work with the wide characters now (as far as I tested). But I'm not sure what other problems you might have, so it would be helpful if you can try.

@coloursofnoise can you check if this one helps with the SetWritePos if you used it elsewhere? In tables.go it should work fine.

dankox commented 2 years ago

@mjarkk There is one more fix in this, where ViewBuffer and ViewBufferLines is updated to use viewLines cells instead of lines cells.
I find out this, that it was using lines which is the same as Buffer and BufferLines. So I've changed it to look more like the original implementation. However, I'm not sure if it's ok.
If not, I can revert that change

mjarkk commented 2 years ago

Awesome work, compared to master i can now properly edit lines with multi with terminal characters.

compared to master this now seems to be fixed: pasting in the demo.go example and then removing them would not correctly remove the characters

I still see 1 issue that's also in master, when i paste multiple in the demo.go while with screen with is not even and a line gets wrapped the visual cursor on screen gets moved one to the right while when edits still happens on the correct place.

coloursofnoise commented 2 years ago

@dankox this seems to fix the issue, I'll rebase my tables.go tweak onto it.

dankox commented 2 years ago

@mjarkk thanks... actually I was testing this scenario and saw it fixed. And now as I looked at it, it's not 🤦‍♀️ So I guess I had there something more which I accidentaly removed. Thanks for looking into it. Will fix that too.

dankox commented 2 years ago

@mjarkk it should be fixed. Hopefully I cover your case as I'm not sure I understand it completly (maybe I did:).
What the last commit fixes is that when you have a line which wraps and there is wide rune at the "wrapping point" it would disappear from the screen together with cursor (or maybe cursor not).

Now it should move correctly and display it correctly too.