feat: 一大坨优化

This commit is contained in:
claude-code-best
2026-04-22 13:33:02 +08:00
parent 8bf645364f
commit 72cfb83de3
27 changed files with 3554 additions and 548 deletions

View File

@@ -146,7 +146,8 @@ export function companionReservedColumns(terminalColumns: number, speaking: bool
const name = getCreatureName(creature);
const nameWidth = stringWidth(name);
const bubble = speaking && !isFullscreenActive() ? BUBBLE_WIDTH : 0;
return spriteColWidth(nameWidth) + SPRITE_PADDING_X + bubble;
// Without sprite art, only need name row width + padding + optional bubble
return nameWidth + NAME_ROW_PAD + SPRITE_PADDING_X + bubble;
}
/**
@@ -275,11 +276,6 @@ export function CompanionSprite(): React.ReactNode {
const spriteColumn = (
<Box flexDirection="column" flexShrink={0} alignItems="center" width={colWidth}>
{displayLines.map((line, i) => (
<Text key={i} color={i === 0 && heartFrame ? 'autoAccept' : color}>
{line}
</Text>
))}
<Text italic bold={focused} dimColor={!focused} color={focused ? color : undefined} inverse={focused}>
{focused ? ` ${name} ` : name}
</Text>

View File

@@ -1,8 +1,7 @@
import React, { useState, useRef } from 'react'
import { useInput } from '@anthropic/ink'
import React, { useRef } from 'react'
import { useInput, useRegisterKeybindingContext } from '@anthropic/ink'
import {
loadBuddyData,
saveBuddyData,
getActiveCreature,
BattleFlow,
type BuddyData,
@@ -49,20 +48,18 @@ function BattlePanel({
buddyData: BuddyData
onClose: () => void
}) {
const [battleKey, setBattleKey] = useState(0)
const inputRef = useRef<BattleFlowHandle | null>(null)
useInput((input, key) => {
// Register keybinding context so our shortcuts take priority over Global
useRegisterKeybindingContext('Battle')
useInput((input, key, event) => {
// Consume ALL keyboard events to prevent PromptInput from intercepting
event.stopImmediatePropagation()
inputRef.current?.handleInput(input, key)
})
const handleClose = async () => {
const updated = await loadBuddyData()
setBattleKey(k => k + 1)
}
return React.createElement(BattleFlow, {
key: battleKey,
buddyData,
onClose,
isActive: true,