MCPcopy Create free account
hub / github.com/aaPanel/BaoTa / get_char_width

Method get_char_width

script/btcli.py:85–95  ·  view source on GitHub ↗

获取单个字符的实际显示宽度

(char)

Source from the content-addressed store, hash-verified

83
84 @staticmethod
85 def get_char_width(char):
86 """获取单个字符的实际显示宽度"""
87 # 判断是否为中文字符或其他双字节字符
88 if '\u4e00' <= char <= '\u9fff' or \
89 '\u3400' <= char <= '\u4dbf' or \
90 '\uf900' <= char <= '\ufaff' or \
91 '\u3040' <= char <= '\u309f' or \
92 '\u30a0' <= char <= '\u30ff':
93 return 2 # 中文字符占2个字符宽度
94 else:
95 return 1 # 英文字符占1个字符宽度
96
97 @staticmethod
98 def get_string_display_width(s):

Callers 1

Calls

no outgoing calls

Tested by

no test coverage detected