vty 6.3 → 6.4
raw patch · 3 files changed
+31/−7 lines, 3 filesdep ~utf8-string
Dependency ranges changed: utf8-string
Files
- CHANGELOG.md +11/−0
- cbits/mk_wcwidth.c +19/−6
- vty.cabal +1/−1
CHANGELOG.md view
@@ -1,4 +1,15 @@ +6.4+---++* Updated the behavior of character width computations when a custom+ character width table has been installed. Now when a custom character+ width table doesn't provide a width for a character, rather than+ defaulting to 1 column, the built-in table is consulted. This change+ shouldn't affect users using width tables generated by `vty-unix`'s+ table-building tool since that tool generates tables that will provide+ widths for all supported characters.+ 6.3 ---
cbits/mk_wcwidth.c view
@@ -72,6 +72,9 @@ // built-in tree search logic is used. static uint8_t* custom_table = NULL; +// Unused table cell value.+static uint8_t UNUSED_CELL = 0xff;+ // The size of the custom table, in entries. This should only be set // if custom_table is not NULL. Its value should be the size of the // custom_table array.@@ -228,14 +231,24 @@ // Return the width, in terminal cells, of the specified character. // // If the global custom width table is present, that table will be-// consulted for the character's width. If the character is not in-// the table, zero will be returned. If the custom width table is not-// present, the built-in width table will be used.+// consulted for the character's width. If the character is not in the+// table, this will fall back to the built-in table. If the character is+// in neither table, zero will be returned. If the custom width table is+// not present, the built-in width table will be used. HsInt vty_mk_wcwidth(HsChar ch) { if (custom_table_ready) { if ((ch >= 0) && (ch < custom_table_size)) {- return custom_table[ch];+ uint8_t result = custom_table[ch];++ // The table is filled with UNUSED_CELL values for+ // uninitialized ranges so we can defer to the built-in+ // table in those cases.+ if (result == UNUSED_CELL) {+ return builtin_wcwidth(ch);+ } else {+ return result;+ } } else { return -1; }@@ -249,7 +262,7 @@ // This allocates a new character width table of the specified size // (in characters). If a custom table has already been allocated, this // returns 1. Otherwise it allocates a new table, initializes all of its-// entries to 1, and returns zero.+// entries to UNUSED_CELL, and returns zero. // // Note that this does *not* mark the table as ready for use. Until the // table is marked ready, it will not be used by vty_mk_wcwidth. To mark@@ -261,7 +274,7 @@ if (size > 0 && size <= MAX_CUSTOM_TABLE_SIZE) { custom_table_ready = 0; custom_table = malloc(size);- memset(custom_table, 1, size);+ memset(custom_table, UNUSED_CELL, size); custom_table_size = size; return 0; } else {
vty.cabal view
@@ -1,5 +1,5 @@ name: vty-version: 6.3+version: 6.4 license: BSD3 license-file: LICENSE author: AUTHORS