Skip to content

Support unicode chars in ListViews and TextFields #146

@awaescher

Description

@awaescher

I am not sure if I just repeat issue #93 here. Sorry if I do.

Issue

I am currently using some unicode signs like: ≡ ⌂ ↑ ↓ …

unicodesguics

While rendering them in a ListView or TextField, I got a IndexOutOfRangeException. In Labels, everything is okay.

   at System.Rune.bisearch(UInt32 rune, UInt32[,] table, Int32 max)
   at System.Rune.ColumnWidth(Rune rune)
   at Terminal.Gui.ListView.ListWrapper.RenderUstr(ustring ustr, Int32 col, Int32 line, Int32 width)
   at Terminal.Gui.ListView.ListWrapper.Render(Boolean marked, Int32 item, Int32 col, Int32 line, Int32 width)
   at Terminal.Gui.ListView.Redraw(Rect region)
   at Terminal.Gui.View.Redraw(Rect region)
   at Terminal.Gui.Window.Redraw(Rect bounds)
   at Terminal.Gui.View.Redraw(Rect region)
   at Terminal.Gui.Application.Redraw(View view)
   at Terminal.Gui.Application.Begin(Toplevel toplevel)
   at Terminal.Gui.Application.Run(Toplevel view)
   at grrui.Program.Main(String[] args) in D:\Develop\GitHub\RepoZ\grrui\Program.cs:line 43

It turns out that "\u2261" for example, returns Rune 8801. Rune.ColumnWidth(8801) throws.

indexoutofrangeexception

How to reproduce

Simply replace the Example\demo.cs in your solution and hit F5.

using Terminal.Gui;

static class Demo {
    static void Main()
    {
	Application.Init();
	var top = Application.Top;
	var tframe = top.Frame;

	var win = new Window("Unicode chars") {
	    X = 0,
	    Y = 0,
	    Width = Dim.Fill(),
	    Height = Dim.Fill()
	};

	var unicodeChars = "\u2261 \u2302 \u2191 \u2193 \u2026";

	var lbl = new Label("They work in Labels: " + unicodeChars) 
	{
	    X = 1,
	    Y = 2
	};

	// ** COMMENT THIS OUT TO SEE THE CRASH **
	unicodeChars = "--CENSORED--";

	var txt = new TextField("But they won't work in TextFields: " + unicodeChars)
	{
	    X = Pos.Left(lbl),
	    Y = Pos.Bottom(lbl) + 1,
	    Width = 50
	};

	var lst = new ListView(new string[] {
	    "They won't work in ListViews as well.",
	    "Here they come: " + unicodeChars,
	    "If you want to try this out by yourself,",
	    "simply remove that line saying \"CENSORED\" in code."
	    }
	) {
	    X = Pos.Left(lbl),
	    Y = 6,
	    Width = Dim.Fill(),
	    Height = Dim.Fill()
	};
	lst.SelectedItem = 0;

	win.Add(lbl);
	win.Add(txt);
	win.Add(lst);
	top.Add(win);

	Application.Run();
    }
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions