- jsc-mod-statusline:/jsc-mod-statusline:enable、compact、disable - jsc-mod-companion:/jsc-mod-companion:status、switch、disable、setup、todo、quiet - 同步更新 plugin.json、marketplace.json 與各 README - 補上 statusline band 測試缺少的 ui.render 底層處理 Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
18 lines
644 B
TypeScript
18 lines
644 B
TypeScript
// 角色行用的字串片段與寬度計算(與 jsc-mod-statusline 外掛各自獨立,不互相依賴)
|
|
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)
|