refactor: statusbar、companion、herdr 外掛改名加上 jsc- 前綴
Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This commit is contained in:
co-authored by
Claude Sonnet 5.5
parent
f10b168c28
commit
58e2b2d26a
@@ -0,0 +1,17 @@
|
||||
// 角色行用的字串片段與寬度計算(與 statusbar 外掛各自獨立,不互相依賴)
|
||||
export type Seg = { text: string; color?: string; dim?: boolean; bold?: boolean }
|
||||
|
||||
export function bar(p: number, cells = 5): string {
|
||||
const n = Math.max(0, Math.min(cells, Math.round((p / 100) * cells)))
|
||||
return '▰'.repeat(n) + '▱'.repeat(cells - n)
|
||||
}
|
||||
|
||||
const WIDE = /[ᄀ-ᅟ⺀-가-힣豈-︰-﹏-⦆¢-₩]/
|
||||
|
||||
export function width(s: string): number {
|
||||
let w = 0
|
||||
for (const ch of s) w += WIDE.test(ch) ? 2 : 1
|
||||
return w
|
||||
}
|
||||
|
||||
export const lineWidth = (segs: Seg[]) => segs.reduce((w, s) => w + width(s.text), 0)
|
||||
Reference in New Issue
Block a user