From 2f889d79bd61b1fd2f43372529975a65b792a7ae Mon Sep 17 00:00:00 2001 From: Garrett D'Amore Date: Fri, 30 Dec 2022 15:34:58 -0800 Subject: [PATCH] Make RUNEWIDTH_EASTASIAN=0 the default. fixes #578 Also, while here, create a look up table for performance reasons. This can be suppressed by a new TCELL_MINIMIZE environment variable, if RAM is precious. Tcell applications should work out of the box by default for most users in East Asian locales now. --- cell.go | 21 ++++++++++++++++++++- 1 file changed, 20 insertions(+), 1 deletion(-) diff --git a/cell.go b/cell.go index c7f8f1ad..c3390049 100644 --- a/cell.go +++ b/cell.go @@ -1,4 +1,4 @@ -// Copyright 2019 The TCell Authors +// Copyright 2022 The TCell Authors // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use file except in compliance with the License. @@ -15,6 +15,8 @@ package tcell import ( + "os" + runewidth "github.com/mattn/go-runewidth" ) @@ -175,3 +177,20 @@ func (cb *CellBuffer) Fill(r rune, style Style) { c.width = 1 } } + +var runeConfig *runewidth.Condition; +func init() { + // The defaults for the runewidth package are poorly chosen for terminal + // applications. We however will honor the setting in the environment if + // it is set. + if os.Getenv("RUNEWIDTH_EASTASIAN") == "" { + runewidth.DefaultCondition.EastAsianWidth = false; + } + + // For performance reasons, we create a lookup table. However some users + // might be more memory conscious. If that's you, set the TCELL_MINIMIZE + // environment variable. + if os.Getenv("TCELL_MINIMIZE") == "" { + runewidth.CreateLUT() + } +}