import { DIM_INFO, ranked } from './emotion' import { bar, lineWidth } from './seg' import type { Seg } from './seg' import type { View } from './core' // 精力隨作息起伏,不列入主要情緒;取最強的兩種 const top2 = (v: View) => ranked(v.emotions).filter(d => d !== 'energy').slice(0, 2) // 由完整版往下捨棄次要資訊:氣泡 → 待辦 → 情緒條 → 好感階段;緊湊版只留「顏文字 名字 心情」 function line(v: View, level: number, compact: boolean, bubble?: string): Seg[] { const out: Seg[] = [ { text: `${v.kaomoji} `, color: 'claude' }, { text: v.core.name, bold: true }, { text: ' ' }, { text: v.label, color: 'suggestion' }, ] if (compact) return out const dot = { text: ' · ', dim: true } if (level < 3) out.push(dot, { text: top2(v).map(d => `${DIM_INFO[d].name}${bar(v.emotions[d] * 100, 4)}`).join(' '), dim: true }) if (level < 4) out.push(dot, { text: v.stage }) if (level < 2 && v.todos > 0) out.push(dot, { text: `☐${v.todos}`, color: 'warning' }) if (level < 1 && bubble) out.push(dot, { text: `💬 ${bubble}`, dim: true }) return out } export const COMPANION_MAX_LEVEL = 4 export function fitCompanion(v: View, columns: number, compact = false, bubble?: string): Seg[] { if (compact) return line(v, 0, true) for (let level = 0; level <= COMPANION_MAX_LEVEL; level++) { const l = line(v, level, false, bubble) if (lineWidth(l) <= columns) return l } return line(v, 0, true) }