- commit
- d90ffaae9267f48df776fc42dff6fde41f56f453
- parent
- 9a95b8616bc9d416e42323be15663f3dbc65c999
- Author
- Tobias Bengfort <tobias.bengfort@posteo.de>
- Date
- 2024-07-20 15:22
use wcwidth
Diffstat
| M | sheet/term.py | 24 | +++++++++++++++--------- |
1 files changed, 15 insertions, 9 deletions
diff --git a/sheet/term.py b/sheet/term.py
@@ -1,19 +1,25 @@ -1 1 from wcwidth import wcswidth -1 2 -1 3 1 4 def align_right(s, width):2 -1 if len(s) > width:3 -1 s = '###'4 -1 return ' ' * (width - len(s)) + s-1 5 w = wcswidth(s) -1 6 if w > width: -1 7 return '#' * width -1 8 return ' ' * (width - w) + s 5 9 6 10 7 11 def align_left(s, width):8 -1 if len(s) > width:9 -1 s = '###'10 -1 return s + ' ' * (width - len(s))-1 12 w = wcswidth(s) -1 13 if w > width: -1 14 return '#' * width -1 15 return s + ' ' * (width - w) 11 16 12 17 13 18 def align_center(s, width):14 -1 if len(s) > width:15 -1 s = '###'16 -1 t = width - len(s)-1 19 w = wcswidth(s) -1 20 if w > width: -1 21 return '#' * width -1 22 t = width - w 17 23 return ' ' * (t // 2) + s + ' ' * (t - t // 2) 18 24 19 25