chenbhao Claude Opus 4.6 commited on
Commit
8b35d5c
Β·
1 Parent(s): fcdf1d0

fix(ImageShowTool): use terminal height instead of width for dimension calculation

Browse files

Switch primary dimension from terminal columns to terminal rows so the
image scales proportionally regardless of terminal orientation.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>

src/tools/ImageShowTool/ImageShowTool.ts CHANGED
@@ -64,24 +64,25 @@ export async function loadImage(path: string) {
64
  export function calculateDimensions(
65
  imageWidth: number,
66
  imageHeight: number,
67
- terminalCols: number
68
  ): ImageDimensions {
69
- const targetW_chars = Math.floor(terminalCols * 0.1618);
70
- const targetW_pixels = targetW_chars * CELL_WIDTH;
71
- const targetH_pixels = Math.floor(targetW_pixels * (imageHeight / imageWidth));
72
- const minH_chars = 3;
73
 
74
- // Compute char height first, then back-compute pixelHeight to guarantee
75
- // pixelHeight === height * CELL_HEIGHT β€” no rounding gap between the
76
  // placeholder Box and the actual Kitty image.
77
- const targetH_chars = Math.max(Math.ceil(targetH_pixels / CELL_HEIGHT), minH_chars);
78
- const finalPixelHeight = targetH_chars * CELL_HEIGHT;
 
79
 
80
  return {
81
  width: targetW_chars,
82
  height: targetH_chars,
83
- pixelWidth: targetW_pixels,
84
- pixelHeight: finalPixelHeight,
85
  };
86
  }
87
 
@@ -175,11 +176,11 @@ export const ImageShowTool = buildTool({
175
  async call({ src }) {
176
  try {
177
  const image = await loadImage(src)
178
- const cols = process.stdout.columns ?? 80
179
  const dims = calculateDimensions(
180
  image.bitmap.width,
181
  image.bitmap.height,
182
- cols,
183
  )
184
 
185
  // Generate full-resolution Kitty protocol sequence via timg
 
64
  export function calculateDimensions(
65
  imageWidth: number,
66
  imageHeight: number,
67
+ terminalRows: number
68
  ): ImageDimensions {
69
+ // Height = 16.18% of terminal height; width derived from aspect ratio.
70
+ const targetH_chars = Math.floor(terminalRows * 0.1618);
71
+ const targetH_pixels = targetH_chars * CELL_HEIGHT;
72
+ const minW_chars = 3;
73
 
74
+ // Pixel width from aspect ratio, then back-compute char width to guarantee
75
+ // pixelWidth === width * CELL_WIDTH β€” no rounding gap between the
76
  // placeholder Box and the actual Kitty image.
77
+ const targetW_pixels = Math.floor(targetH_pixels * (imageWidth / imageHeight));
78
+ const targetW_chars = Math.max(Math.ceil(targetW_pixels / CELL_WIDTH), minW_chars);
79
+ const finalPixelWidth = targetW_chars * CELL_WIDTH;
80
 
81
  return {
82
  width: targetW_chars,
83
  height: targetH_chars,
84
+ pixelWidth: finalPixelWidth,
85
+ pixelHeight: targetH_pixels,
86
  };
87
  }
88
 
 
176
  async call({ src }) {
177
  try {
178
  const image = await loadImage(src)
179
+ const rows = process.stdout.rows ?? 24
180
  const dims = calculateDimensions(
181
  image.bitmap.width,
182
  image.bitmap.height,
183
+ rows,
184
  )
185
 
186
  // Generate full-resolution Kitty protocol sequence via timg
src/tools/ImageShowTool/UI.tsx CHANGED
@@ -154,13 +154,8 @@ export function ImageDisplay({
154
 
155
  // ── Tool rendering functions ──
156
 
157
- export function renderToolUseMessage(
158
- { src }: { src?: string },
159
- { verbose }: { theme?: string; verbose: boolean },
160
- ): React.ReactNode {
161
- if (!src) return null;
162
- if (verbose) return `src: "${src}"`;
163
- return src;
164
  }
165
 
166
  export function renderToolUseProgressMessage(): React.ReactNode {
 
154
 
155
  // ── Tool rendering functions ──
156
 
157
+ export function renderToolUseMessage(): React.ReactNode {
158
+ return "ImageShow";
 
 
 
 
 
159
  }
160
 
161
  export function renderToolUseProgressMessage(): React.ReactNode {
src/tools/ImageShowTool/standalone.tsx CHANGED
@@ -36,7 +36,7 @@ function App() {
36
  const dims = calculateDimensions(
37
  image.bitmap.width,
38
  image.bitmap.height,
39
- process.stdout.columns ?? 80,
40
  );
41
  setDimensions(dims);
42
  } catch (e) {
 
36
  const dims = calculateDimensions(
37
  image.bitmap.width,
38
  image.bitmap.height,
39
+ process.stdout.rows ?? 24,
40
  );
41
  setDimensions(dims);
42
  } catch (e) {