Skip to content

Commit 7f74a7f

Browse files
committed
allow input to extend to half the screen height
1 parent 2ef8f47 commit 7f74a7f

File tree

3 files changed

+32
-28
lines changed

3 files changed

+32
-28
lines changed

cli/src/chat.tsx

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ export const Chat = ({
7575
}) => {
7676
const scrollRef = useRef<ScrollBoxRenderable | null>(null)
7777

78-
const { separatorWidth, terminalWidth } = useTerminalDimensions()
78+
const { separatorWidth, terminalWidth, terminalHeight } = useTerminalDimensions()
7979

8080
const theme = useTheme()
8181
const markdownPalette = useMemo(() => createMarkdownPalette(theme), [theme])
@@ -574,9 +574,9 @@ export const Chat = ({
574574
layoutContent,
575575
cursorProbe,
576576
cols,
577-
maxHeight: 5,
577+
maxHeight: Math.floor(terminalHeight / 2),
578578
})
579-
}, [inputValue, cursorPosition, inputWidth])
579+
}, [inputValue, cursorPosition, inputWidth, terminalHeight])
580580
const isMultilineInput = inputLayoutMetrics.heightLines > 1
581581
const shouldCenterInputVertically = !hasSuggestionMenu && !isMultilineInput
582582
const statusIndicatorState = getStatusIndicatorState({
@@ -764,7 +764,7 @@ export const Chat = ({
764764
onSubmit={handleSubmit}
765765
placeholder={inputPlaceholder}
766766
focused={inputFocused}
767-
maxHeight={5}
767+
maxHeight={Math.floor(terminalHeight / 2)}
768768
width={inputWidth}
769769
onKeyIntercept={handleSuggestionMenuKey}
770770
textAttributes={theme.messageTextAttributes}

cli/src/components/multiline-input.tsx

Lines changed: 21 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -266,20 +266,27 @@ export const MultilineInput = forwardRef<
266266
const isPlaceholder = value.length === 0 && placeholder.length > 0
267267
const displayValue = isPlaceholder ? placeholder : value
268268
const showCursor = focused
269-
269+
270270
// Replace tabs with spaces for proper rendering
271271
// Terminal tab stops are typically 8 columns, but 4 is more readable
272272
const TAB_WIDTH = 4
273-
const displayValueForRendering = displayValue.replace(/\t/g, ' '.repeat(TAB_WIDTH))
274-
273+
const displayValueForRendering = displayValue.replace(
274+
/\t/g,
275+
' '.repeat(TAB_WIDTH),
276+
)
277+
275278
// Calculate cursor position in the expanded string (accounting for tabs)
276279
let renderCursorPosition = 0
277280
for (let i = 0; i < cursorPosition && i < displayValue.length; i++) {
278281
renderCursorPosition += displayValue[i] === '\t' ? TAB_WIDTH : 1
279282
}
280-
281-
const beforeCursor = showCursor ? displayValueForRendering.slice(0, renderCursorPosition) : ''
282-
const afterCursor = showCursor ? displayValueForRendering.slice(renderCursorPosition) : ''
283+
284+
const beforeCursor = showCursor
285+
? displayValueForRendering.slice(0, renderCursorPosition)
286+
: ''
287+
const afterCursor = showCursor
288+
? displayValueForRendering.slice(renderCursorPosition)
289+
: ''
283290
const activeChar = afterCursor.charAt(0) || ' '
284291
const shouldHighlight =
285292
showCursor &&
@@ -773,22 +780,12 @@ export const MultilineInput = forwardRef<
773780
[layoutContent, cursorProbe, getEffectiveCols, maxHeight],
774781
)
775782

776-
const height = layoutMetrics.heightLines
777-
778-
const shouldRenderBottomGutter = layoutMetrics.gutterEnabled
779-
780783
const inputColor = isPlaceholder
781784
? theme.muted
782785
: focused
783786
? theme.inputFocusedFg
784787
: theme.inputFg
785788

786-
const textStyle: Record<string, unknown> = {
787-
bg: 'transparent',
788-
fg: inputColor,
789-
}
790-
791-
const cursorFg = theme.info
792789
const highlightBg = '#7dd3fc' // Lighter blue for highlight background
793790

794791
return (
@@ -803,7 +800,7 @@ export const MultilineInput = forwardRef<
803800
flexShrink: 0,
804801
rootOptions: {
805802
width: '100%',
806-
height: height,
803+
height: layoutMetrics.heightLines,
807804
backgroundColor: 'transparent',
808805
flexGrow: 0,
809806
flexShrink: 0,
@@ -818,7 +815,10 @@ export const MultilineInput = forwardRef<
818815
},
819816
}}
820817
>
821-
<text ref={textRef} style={{ ...textStyle, wrapMode: 'word' }}>
818+
<text
819+
ref={textRef}
820+
style={{ bg: 'transparent', fg: inputColor, wrapMode: 'word' }}
821+
>
822822
{showCursor ? (
823823
<>
824824
{beforeCursor}
@@ -831,10 +831,7 @@ export const MultilineInput = forwardRef<
831831
{activeChar === ' ' ? '\u00a0' : activeChar}
832832
</span>
833833
) : (
834-
<span
835-
{...(cursorFg ? { fg: cursorFg } : undefined)}
836-
attributes={TextAttributes.BOLD}
837-
>
834+
<span fg={theme.info} attributes={TextAttributes.BOLD}>
838835
{CURSOR_CHAR}
839836
</span>
840837
)}
@@ -843,12 +840,12 @@ export const MultilineInput = forwardRef<
843840
? afterCursor.slice(1)
844841
: ''
845842
: afterCursor}
846-
{shouldRenderBottomGutter ? '\n' : ''}
843+
{layoutMetrics.gutterEnabled ? '\n' : ''}
847844
</>
848845
) : (
849846
<>
850847
{displayValueForRendering}
851-
{shouldRenderBottomGutter ? '\n' : ''}
848+
{layoutMetrics.gutterEnabled ? '\n' : ''}
852849
</>
853850
)}
854851
</text>

cli/src/hooks/use-terminal-dimensions.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,13 @@ export const useTerminalDimensions = () => {
1919
[measuredWidth, renderer?.width],
2020
)
2121

22+
const resolvedTerminalHeight = useMemo(
23+
() => sanitizeDimension(renderer?.height) ?? 24,
24+
[renderer?.height],
25+
)
26+
2227
const terminalWidth = resolvedTerminalWidth
28+
const terminalHeight = resolvedTerminalHeight
2329
const separatorWidth = useMemo(
2430
() => Math.max(1, Math.floor(terminalWidth) - 2),
2531
[terminalWidth],
@@ -32,6 +38,7 @@ export const useTerminalDimensions = () => {
3238

3339
return {
3440
terminalWidth,
41+
terminalHeight,
3542
separatorWidth,
3643
contentMaxWidth,
3744
}

0 commit comments

Comments
 (0)