Skip to content

Commit e1418c0

Browse files
update
1 parent 36e2536 commit e1418c0

13 files changed

Lines changed: 33 additions & 35 deletions

File tree

packages/cli/package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
"description": "@git-diff-view/cli",
44
"author": "MrWangJustToDo",
55
"license": "MIT",
6-
"version": "0.1.5",
6+
"version": "0.1.6",
77
"main": "index.mjs",
88
"type": "module",
99
"types": "index.d.ts",
@@ -51,7 +51,7 @@
5151
"cli diff component"
5252
],
5353
"dependencies": {
54-
"@git-diff-view/core": "^0.1.5",
54+
"@git-diff-view/core": "^0.1.6",
5555
"@types/hast": "^3.0.0",
5656
"chalk": "^5.6.2",
5757
"highlight.js": "^11.11.0",

packages/cli/src/components/CodeView.tsx

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
import { _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

77
import { buildAnsiStringOptimized, splitCharsIntoRows, styleText } from "./ansiString";
88
import { buildTheme } from "./color";
@@ -16,7 +16,6 @@ import {
1616
import type { CharStyle, StyledChar } from "./ansiString";
1717
import type { DiffViewColorTheme, ResolvedDiffViewColorTheme } from "./color";
1818
import type { DiffHighlighter, DiffHighlighterLang, File } from "@git-diff-view/core";
19-
import type { DOMElement } from "ink";
2019
import 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

165164
const 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";
186187
const 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}

packages/cli/src/hooks/useTerminalSize.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ import type { DOMElement } from "ink";
77

88
export const TERMINAL_PADDING_X = 4;
99

10-
const safeGetProcessColumn = () => {
10+
export const safeGetProcessColumn = () => {
1111
if (typeof process === "object") {
1212
return process.stdout.columns;
1313
}

packages/core/package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
"description": "@git-diff-view/core",
44
"author": "MrWangJustToDo",
55
"license": "MIT",
6-
"version": "0.1.5",
6+
"version": "0.1.6",
77
"main": "index.js",
88
"types": "index.d.ts",
99
"files": [
@@ -53,7 +53,7 @@
5353
"diff parse"
5454
],
5555
"dependencies": {
56-
"@git-diff-view/lowlight": "^0.1.5",
56+
"@git-diff-view/lowlight": "^0.1.6",
5757
"highlight.js": "^11.11.0",
5858
"lowlight": "^3.3.0",
5959
"fast-diff": "^1.3.0"

packages/file/package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
"description": "@git-diff-view/file",
44
"author": "MrWangJustToDo",
55
"license": "MIT",
6-
"version": "0.1.5",
6+
"version": "0.1.6",
77
"main": "index.js",
88
"types": "index.d.ts",
99
"files": [
@@ -53,7 +53,7 @@
5353
"diff parse"
5454
],
5555
"dependencies": {
56-
"@git-diff-view/core": "^0.1.5",
56+
"@git-diff-view/core": "^0.1.6",
5757
"diff": "^8.0.3",
5858
"highlight.js": "^11.11.0",
5959
"lowlight": "^3.3.0",

packages/lowlight/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
"description": "@git-diff-view/lowlight",
44
"author": "MrWangJustToDo",
55
"license": "MIT",
6-
"version": "0.1.5",
6+
"version": "0.1.6",
77
"main": "index.js",
88
"types": "index.d.ts",
99
"files": [

packages/react/package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
"description": "@git-diff-view/react",
44
"author": "MrWangJustToDo",
55
"license": "MIT",
6-
"version": "0.1.5",
6+
"version": "0.1.6",
77
"main": "index.js",
88
"types": "index.d.ts",
99
"files": [
@@ -67,7 +67,7 @@
6767
"react diff component"
6868
],
6969
"dependencies": {
70-
"@git-diff-view/core": "^0.1.5",
70+
"@git-diff-view/core": "^0.1.6",
7171
"@types/hast": "^3.0.0",
7272
"fast-diff": "^1.3.0",
7373
"highlight.js": "^11.11.0",

packages/shiki/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
"description": "@git-diff-view/shiki",
44
"author": "MrWangJustToDo",
55
"license": "MIT",
6-
"version": "0.1.5",
6+
"version": "0.1.6",
77
"types": "index.d.ts",
88
"main": "./dist/esm/index.mjs",
99
"type": "module",

packages/solid/package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
"description": "@git-diff-view/solid",
44
"author": "MrWangJustToDo",
55
"license": "MIT",
6-
"version": "0.1.5",
6+
"version": "0.1.6",
77
"main": "./dist/solid-git-diff-view.mjs",
88
"type": "module",
99
"types": "index.d.ts",
@@ -41,7 +41,7 @@
4141
"solid diff component"
4242
],
4343
"dependencies": {
44-
"@git-diff-view/core": "^0.1.5",
44+
"@git-diff-view/core": "^0.1.6",
4545
"@types/hast": "^3.0.0",
4646
"highlight.js": "^11.11.0",
4747
"lowlight": "^3.3.0",

packages/svelte/package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@git-diff-view/svelte",
3-
"version": "0.1.5",
3+
"version": "0.1.6",
44
"scripts": {
55
"dev": "vite dev",
66
"build": "svelte-kit sync && svelte-package",
@@ -35,7 +35,7 @@
3535
"./package.json": "./package.json"
3636
},
3737
"dependencies": {
38-
"@git-diff-view/core": "^0.1.5",
38+
"@git-diff-view/core": "^0.1.6",
3939
"@types/hast": "^3.0.0",
4040
"highlight.js": "^11.11.0",
4141
"lowlight": "^3.3.0",

0 commit comments

Comments
 (0)