| 869 | self.scr.refresh() |
| 870 | |
| 871 | def strpad(self, s, width): |
| 872 | if width < 1: |
| 873 | return str() |
| 874 | if '\n' in s: |
| 875 | s = s.replace('\n', '\\n') |
| 876 | |
| 877 | # take into account double-width characters |
| 878 | buf = str() |
| 879 | buf_width = 0 |
| 880 | for c in s: |
| 881 | w = 2 if unicodedata.east_asian_width(c) == 'W' else 1 |
| 882 | if buf_width + w > width: |
| 883 | break |
| 884 | buf_width += w |
| 885 | buf += c |
| 886 | |
| 887 | if len(buf) < len(s): |
| 888 | # truncation occurred |
| 889 | while buf_width + len(self.trunc_char) > width: |
| 890 | c = buf[-1] |
| 891 | w = 2 if unicodedata.east_asian_width(c) == 'W' else 1 |
| 892 | buf = buf[0:-1] |
| 893 | buf_width -= w |
| 894 | buf += ' ' * (width - buf_width - len(self.trunc_char)) |
| 895 | buf += self.trunc_char |
| 896 | elif buf_width < width: |
| 897 | # padding required |
| 898 | buf += ' ' * (width - buf_width) |
| 899 | |
| 900 | return buf |
| 901 | |
| 902 | def hdrstr(self, x, width): |
| 903 | "Format the content of the requested header for display" |