11import { _cacheMap , getFile } from "@git-diff-view/core" ;
2- import { Box , Text } from "ink" ;
3- import { forwardRef , memo , useImperativeHandle , useMemo , useRef } from "react" ;
2+ import { Box , Text , useStdout } from "ink" ;
3+ import { forwardRef , memo , useImperativeHandle , useMemo } from "react" ;
44
5- import { getValidColumns , TERMINAL_PADDING_X } from "../hooks/useTerminalSize" ;
5+ import { getValidColumns , safeGetProcessColumn , TERMINAL_PADDING_X } from "../hooks/useTerminalSize" ;
66
77import { buildAnsiStringOptimized , splitCharsIntoRows , styleText } from "./ansiString" ;
88import { buildTheme } from "./color" ;
@@ -16,7 +16,6 @@ import {
1616import type { CharStyle , StyledChar } from "./ansiString" ;
1717import type { DiffViewColorTheme , ResolvedDiffViewColorTheme } from "./color" ;
1818import type { DiffHighlighter , DiffHighlighterLang , File } from "@git-diff-view/core" ;
19- import type { DOMElement } from "ink" ;
2019import type { ForwardedRef , JSX } from "react" ;
2120
2221_cacheMap . name = "@git-diff-view/cli" ;
@@ -151,7 +150,7 @@ export function buildCodeViewAnsiString(props: CodeViewProps): string {
151150 const columns =
152151 typeof props . width === "number"
153152 ? props . width
154- : getValidColumns ( ( process . stdout . columns || 60 ) - TERMINAL_PADDING_X ) ;
153+ : getValidColumns ( ( safeGetProcessColumn ( ) || 60 ) - TERMINAL_PADDING_X ) ;
155154
156155 return buildCodeViewString ( resolvedFile , theme , columns , {
157156 enableHighlight : ! ! props . codeViewHighlight ,
@@ -164,10 +163,12 @@ export function buildCodeViewAnsiString(props: CodeViewProps): string {
164163
165164const InternalCodeView = memo (
166165 ( { file, theme, width, options } : { file : File ; theme : "light" | "dark" ; width ?: number ; options : BuildOptions } ) => {
166+ const { stdout } = useStdout ( ) ;
167+
167168 const columns = useMemo ( ( ) => {
168169 if ( typeof width === "number" ) return width ;
169- return getValidColumns ( ( process . stdout . columns || 60 ) - TERMINAL_PADDING_X ) ;
170- } , [ width ] ) ;
170+ return getValidColumns ( ( safeGetProcessColumn ( ) || stdout . columns || 60 ) - TERMINAL_PADDING_X ) ;
171+ } , [ stdout , width ] ) ;
171172
172173 const output = useMemo ( ( ) => buildCodeViewString ( file , theme , columns , options ) , [ file , theme , columns , options ] ) ;
173174
@@ -186,8 +187,6 @@ InternalCodeView.displayName = "InternalCodeView";
186187const CodeViewContainerWithRef = ( props : CodeViewProps , ref : ForwardedRef < { getFileInstance : ( ) => File | null } > ) => {
187188 const { registerHighlighter, data, codeViewTheme, file, width, ...restProps } = props ;
188189
189- const domRef = useRef < DOMElement > ( null ) ;
190-
191190 const theme = codeViewTheme || "light" ;
192191
193192 const finalFile = useMemo ( ( ) => {
@@ -232,7 +231,6 @@ const CodeViewContainerWithRef = (props: CodeViewProps, ref: ForwardedRef<{ getF
232231
233232 return (
234233 < Box
235- ref = { domRef }
236234 width = { width }
237235 flexGrow = { typeof width === "number" ? undefined : 1 }
238236 flexShrink = { typeof width === "number" ? 0 : undefined }
0 commit comments