#157·gocui

Bad view title drawing with unicode characters.

Author: luengoiCreated Apr 23, 2018Updated Feb 1, 2022

Hello, I am using this API to build the user interface for my application. I am loving it so far, it is very simple and straightforward.

However, I have found an issue when using a View title that contains unicode characters. For instance, see this example:

go
    ...
    v.Frame = true
    v.Title = " ⣿ HELP ⣿ "
    ...
    // Expecting  ┌ ⣿ HELP ⣿ ──────┐
    // Getting    ┌ ⣿── HELP ⣿── ──┐instead

The reason behind this issue seems to be in this line: https://github.com/jroimartin/gocui/blob/c055c87ae801372cd74a0839b972db4f7697ae5f/gui.go#L538

Since v.Title is a string, when iterating over it you are writing over byte in the string, and because unicode encoded characters use more than one byte, we are getting that weird result. I have tried to replace that line with the following one:

go
    for i, ch := range []rune(v.Title) {

And it seems to get the job done. Changing the type of View.Title to rune seems to work as well. Although the last seems to be more inconvenient for the user (it's easier to declare a string literal). I've just learned Go a month ago so I may be saying silly things. Also there might be a more elegant solution to the issue, that is why I didn't venture to do a PR.

This is the first issue I write, I hope I've been clear enough. I don't know if this issue falls into the scope of this API but I think it would be nice to have the option to include unicode characters in the title. Thanks again for this awesome API!