diff options
| author | Julian Hurst <julian.hurst@digdash.com> | 2025-03-20 14:47:03 +0100 |
|---|---|---|
| committer | Julian Hurst <julian.hurst@digdash.com> | 2025-03-20 14:47:03 +0100 |
| commit | 2b33d4766affc5ead30eceba310a15780443ac83 (patch) | |
| tree | 172a5b2465e5a34d41d82350c5e6080e99b07af8 /tui/width.ha | |
| parent | 5e93fe240e489ff13a90a7ff29fee415c8113cc9 (diff) | |
| parent | 5efb8c021fe2166648591e46591144a49bf575bf (diff) | |
| download | hare-tui-2b33d4766affc5ead30eceba310a15780443ac83.tar.gz | |
Merge branch 'master' into nomem
Diffstat (limited to 'tui/width.ha')
| -rw-r--r-- | tui/width.ha | 14 |
1 files changed, 14 insertions, 0 deletions
diff --git a/tui/width.ha b/tui/width.ha index 6f9631c..ed498e6 100644 --- a/tui/width.ha +++ b/tui/width.ha @@ -30,3 +30,17 @@ export fn strwidth(s: str) uint = { }; return sum; }; + +export fn subwidth(s: str, end: (size | strings::end)) str = { + const runes = strings::torunes(s); + defer free(runes); + let sum = 0u; + for (let i = 0z; i < len(runes); i += 1) { + const r = runes[i]; + sum += runewidth(r); + if (sum > end: uint) { + return strings::sub(s, 0, i - 1); + }; + }; + return s; +}; |
