chenbhao Claude Opus 4.6 commited on
Commit
603297b
·
1 Parent(s): c4d362b

fix: improve ImageShowTool cursor handling and dynamic image rows; update tsconfig ignoreDeprecations

Browse files
src/tools/ImageShowTool/ImageShowTool.tsx CHANGED
@@ -9,7 +9,6 @@ import { buildTool, type ToolDef } from '../../Tool.js'
9
  import { logForDebugging } from '../../utils/debug.js'
10
  import {
11
  detectImageProtocol,
12
- getImageRowsCount,
13
  renderImageWithTimgSync,
14
  } from '../../utils/terminalImage.js'
15
 
@@ -51,17 +50,22 @@ function getToolUseSummary(input: Partial<Input>): string | null {
51
  * vertical space with empty RawAnsi lines so Ink doesn't overwrite the
52
  * image area.
53
  */
54
- function KittyImage({ kittyOutput, imageRows }: { kittyOutput: string; imageRows: number }) {
 
 
 
 
 
 
 
 
55
  const writeRaw = useContext(TerminalWriteContext)
56
 
57
  useEffect(() => {
58
  if (writeRaw && kittyOutput) {
59
- // After Ink renders the reserved empty lines, cursor is at the bottom.
60
- // Move cursor up to the top so the image renders at the start of the
61
- // reserved space.
62
- writeRaw(`\x1b[${imageRows}A${kittyOutput}`)
63
  }
64
- }, [kittyOutput, imageRows, writeRaw])
65
 
66
  const width = process.stdout.columns ?? 80
67
  const lines = new Array<string>(imageRows).fill('')
@@ -290,7 +294,8 @@ export const ImageShowTool = buildTool({
290
  // Pass the raw timg output directly through writeRaw — no need to
291
  // strip cursor sequences since writeRaw bypasses Ink's screen buffer.
292
  kittyOutput = wrapForMultiplexer(rawKitty.trimEnd())
293
- imageRows = getImageRowsCount(buffer, format)
 
294
  logForDebugging(
295
  `ImageShow: generated Kitty protocol output, image rows = ${imageRows}`,
296
  )
 
9
  import { logForDebugging } from '../../utils/debug.js'
10
  import {
11
  detectImageProtocol,
 
12
  renderImageWithTimgSync,
13
  } from '../../utils/terminalImage.js'
14
 
 
50
  * vertical space with empty RawAnsi lines so Ink doesn't overwrite the
51
  * image area.
52
  */
53
+ function KittyImage({
54
+ kittyOutput,
55
+ imageRows,
56
+ offset = 4,
57
+ }: {
58
+ kittyOutput: string
59
+ imageRows: number
60
+ offset?: number
61
+ }) {
62
  const writeRaw = useContext(TerminalWriteContext)
63
 
64
  useEffect(() => {
65
  if (writeRaw && kittyOutput) {
66
+ writeRaw(`\x1b[${imageRows + offset}A${kittyOutput}\x1b[${imageRows + offset}B`)
 
 
 
67
  }
68
+ }, [kittyOutput, imageRows, offset, writeRaw])
69
 
70
  const width = process.stdout.columns ?? 80
71
  const lines = new Array<string>(imageRows).fill('')
 
294
  // Pass the raw timg output directly through writeRaw — no need to
295
  // strip cursor sequences since writeRaw bypasses Ink's screen buffer.
296
  kittyOutput = wrapForMultiplexer(rawKitty.trimEnd())
297
+ const termRows = process.stdout.rows ?? 40
298
+ imageRows = Math.max(10, Math.floor(termRows * 0.5))
299
  logForDebugging(
300
  `ImageShow: generated Kitty protocol output, image rows = ${imageRows}`,
301
  )
tsconfig.json CHANGED
@@ -4,6 +4,7 @@
4
  "target": "ESNext",
5
  "module": "Preserve",
6
  "moduleDetection": "force",
 
7
  "jsx": "react-jsx",
8
  "allowJs": true,
9
  "types": ["bun"],
 
4
  "target": "ESNext",
5
  "module": "Preserve",
6
  "moduleDetection": "force",
7
+ "ignoreDeprecations": "6.0",
8
  "jsx": "react-jsx",
9
  "allowJs": true,
10
  "types": ["bun"],