11import React from "react" ;
2- import { Box , Text , useWindowSize } from "ink" ;
2+ import { Box , Text } from "ink" ;
33import { renderMarkdown } from "./markdown" ;
44import type { SessionMessage } from "../session" ;
55
66type Props = {
77 message : SessionMessage ;
88 collapsed ?: boolean ;
9+ width ?: number ;
910} ;
1011
11- export function MessageView ( { message, collapsed } : Props ) : React . ReactElement | null {
12- const { columns } = useWindowSize ( ) ;
12+ export function MessageView ( { message, collapsed, width = 80 } : Props ) : React . ReactElement | null {
1313 if ( ! message . visible ) {
1414 return null ;
1515 }
@@ -54,12 +54,15 @@ export function MessageView({ message, collapsed }: Props): React.ReactElement |
5454 ) ;
5555 }
5656
57+ const containerWidth = Math . max ( 1 , width - 2 ) ;
58+ const contentWidth = Math . max ( 1 , width - 4 ) ;
59+
5760 return (
58- < Box marginLeft = { 1 } marginBottom = { 1 } width = { columns - 2 } gap = { 1 } marginY = { 0 } flexDirection = "row" >
61+ < Box marginLeft = { 1 } marginBottom = { 1 } width = { containerWidth } gap = { 1 } marginY = { 0 } flexDirection = "row" >
5962 < Box alignSelf = "stretch" >
6063 < Text color = "#229ac3" > ✦</ Text >
6164 </ Box >
62- < Box flexGrow = { 1 } width = { columns - 4 } >
65+ < Box flexGrow = { 1 } width = { contentWidth } >
6366 { content ? < Text wrap = "wrap" > { renderMarkdown ( content ) } </ Text > : null }
6467 </ Box >
6568 </ Box >
@@ -82,7 +85,7 @@ export function MessageView({ message, collapsed }: Props): React.ReactElement |
8285 }
8386
8487 if ( message . role === "system" ) {
85- // 渲染模型变更消息
88+ // Render model change messages in the same style as user commands.
8689 if ( message . meta ?. isModelChange ) {
8790 return (
8891 < Box marginY = { 0 } marginLeft = { 1 } marginBottom = { 1 } flexGrow = { 1 } flexDirection = "row" gap = { 1 } >
0 commit comments