Add /show-images command to toggle inline image display

- Add terminal.showImages setting to settings-manager.ts
- Add /show-images slash command (only visible if terminal supports images)
- ToolExecutionComponent checks both terminal support and user setting
- Shows text fallback when inline images are disabled
This commit is contained in:
Mario Zechner 2025-12-13 23:14:46 +01:00
parent 215c10664a
commit f68a933d2c
3 changed files with 87 additions and 7 deletions

View file

@ -30,6 +30,10 @@ function replaceTabs(text: string): string {
return text.replace(/\t/g, " ");
}
export interface ToolExecutionOptions {
showImages?: boolean; // default: true (only used if terminal supports images)
}
/**
* Component that renders a tool call with its result (updateable)
*/
@ -39,16 +43,18 @@ export class ToolExecutionComponent extends Container {
private toolName: string;
private args: any;
private expanded = false;
private showImages: boolean;
private result?: {
content: Array<{ type: string; text?: string; data?: string; mimeType?: string }>;
isError: boolean;
details?: any;
};
constructor(toolName: string, args: any) {
constructor(toolName: string, args: any, options: ToolExecutionOptions = {}) {
super();
this.toolName = toolName;
this.args = args;
this.showImages = options.showImages ?? true;
this.addChild(new Spacer(1));
this.contentText = new Text("", 1, 1, (text: string) => theme.bg("toolPendingBg", text));
this.addChild(this.contentText);
@ -94,7 +100,8 @@ export class ToolExecutionComponent extends Container {
const caps = getCapabilities();
for (const img of imageBlocks) {
if (caps.images && img.data && img.mimeType) {
// Show inline image only if terminal supports it AND user setting allows it
if (caps.images && this.showImages && img.data && img.mimeType) {
const imageComponent = new Image(
img.data,
img.mimeType,
@ -124,7 +131,8 @@ export class ToolExecutionComponent extends Container {
.join("\n");
const caps = getCapabilities();
if (imageBlocks.length > 0 && !caps.images) {
// Show text fallback if terminal doesn't support images OR if user disabled inline images
if (imageBlocks.length > 0 && (!caps.images || !this.showImages)) {
const imageIndicators = imageBlocks
.map((img: any) => {
const dims = img.data ? (getImageDimensions(img.data, img.mimeType) ?? undefined) : undefined;