Skip to content

Node-based terminal manager for AI coding agents — tmux-backed terminals and parallel agent sessions as draggable nodes on an infinite pan/zoom canvas. macOS, Linux, and a browser Server Edition.

feat(editor): image preview for image files instead of binary text

enesdb067f2ecf9f
diff --git a/src/main/index.ts b/src/main/index.ts
index 9e4c9e05d..dde9d7817 100644
--- a/src/main/index.ts
+++ b/src/main/index.ts
@@ -145,6 +145,15 @@ app.whenReady().then(() => {
}
})
+ ipcMain.handle(IPC.fsReadBinary, async (_e, filePath: string) => {
+ try {
+ const buf = await fs.readFile(filePath)
+ return buf.toString('base64')
+ } catch {
+ return ''
+ }
+ })
+
ipcMain.handle(IPC.fsWrite, async (_e, filePath: string, content: string) => {
try {
await fs.writeFile(filePath, content, 'utf-8')
diff --git a/src/preload/index.ts b/src/preload/index.ts
index 6bae01b9d..a2a9d938d 100644
--- a/src/preload/index.ts
+++ b/src/preload/index.ts
@@ -72,6 +72,7 @@ const api: NodeTerminalApi = {
fs: {
list: (dirPath: string) => ipcRenderer.invoke(IPC.fsList, dirPath),
read: (filePath: string) => ipcRenderer.invoke(IPC.fsRead, filePath),
+ readBinary: (filePath: string) => ipcRenderer.invoke(IPC.fsReadBinary, filePath),
write: (filePath: string, content: string) => ipcRenderer.invoke(IPC.fsWrite, filePath, content)
},
updates: {
diff --git a/src/renderer/nodes/EditorNode.tsx b/src/renderer/nodes/EditorNode.tsx
index 5cb8a6fa9..ae8851d09 100644
--- a/src/renderer/nodes/EditorNode.tsx
+++ b/src/renderer/nodes/EditorNode.tsx
@@ -5,9 +5,23 @@ import { renderMarkdown } from '../lib/markdown'
import { useSettings } from '../state/settings'
import type { CanvasNode } from '../state/workspace'
+// Image extensions get a visual preview instead of the Monaco text editor.
+const IMAGE_MIME: Record<string, string> = {
+ png: 'image/png',
+ jpg: 'image/jpeg',
+ jpeg: 'image/jpeg',
+ gif: 'image/gif',
+ webp: 'image/webp',
+ bmp: 'image/bmp',
+ ico: 'image/x-icon',
+ svg: 'image/svg+xml',
+ avif: 'image/avif'
+}
+
/**
* A code editor node backed by Monaco. Reads the file on mount, auto-detects the language
- * from the path, and saves back with ⌘S (or the Save button).
+ * from the path, and saves back with ⌘S (or the Save button). Image files are shown as a
+ * preview instead of being opened as (binary) text.
*/
export function EditorNode({ id, data, selected }: NodeProps<CanvasNode>) {
const { deleteElements } = useReactFlow()
@@ -18,10 +32,15 @@ export function EditorNode({ id, data, selected }: NodeProps<CanvasNode>) {
const [dirty, setDirty] = useState(false)
const [preview, setPreview] = useState(false)
const [previewHtml, setPreviewHtml] = useState('')
+ const [imageSrc, setImageSrc] = useState('')
+ const [imageDims, setImageDims] = useState('')
const filePath = (data.filePath as string) ?? ''
const fileName = filePath.split('/').pop() || 'untitled'
+ const ext = fileName.includes('.') ? fileName.split('.').pop()!.toLowerCase() : ''
+ const isImage = ext in IMAGE_MIME
const togglePreview = () => {
+ if (isImage) return
setPreview((p) => {
const next = !p
if (next && editorRef.current) setPreviewHtml(renderMarkdown(editorRef.current.getValue()))
@@ -46,8 +65,21 @@ export function EditorNode({ id, data, selected }: NodeProps<CanvasNode>) {
saveRef.current = save
useEffect(() => {
+ if (!filePath) return
+
+ // Images: load as a data URL and render an <img> preview (no Monaco).
+ if (isImage) {
+ let disposed = false
+ window.nodeTerminal.fs.readBinary(filePath).then((b64) => {
+ if (!disposed && b64) setImageSrc(`data:${IMAGE_MIME[ext]};base64,${b64}`)
+ })
+ return () => {
+ disposed = true
+ }
+ }
+
const el = bodyRef.current
- if (!el || !filePath) return
+ if (!el) return
let disposed = false
let editor: monaco.editor.IStandaloneCodeEditor | null = null
let model: monaco.editor.ITextModel | null = null
@@ -101,19 +133,30 @@ export function EditorNode({ id, data, selected }: NodeProps<CanvasNode>) {
<div className="term-node__header">
<span className="term-node__title-text" title={filePath}>
{fileName}
- {dirty ? ' ●' : ''}
+ {!isImage && dirty ? ' ●' : ''}
</span>
<span className="term-node__spacer" />
- <button
- className="editor-node__toggle"
- title="Toggle markdown preview (⌘M)"
- onClick={togglePreview}
- >
- {preview ? 'Edit' : 'Preview'}
- </button>
- <button className="editor-node__save" disabled={!dirty} title="Save (⌘S)" onClick={save}>
- Save
- </button>
+ {isImage ? (
+ imageDims && <span className="editor-node__dims">{imageDims}</span>
+ ) : (
+ <>
+ <button
+ className="editor-node__toggle"
+ title="Toggle markdown preview (⌘M)"
+ onClick={togglePreview}
+ >
+ {preview ? 'Edit' : 'Preview'}
+ </button>
+ <button
+ className="editor-node__save"
+ disabled={!dirty}
+ title="Save (⌘S)"
+ onClick={save}
+ >
+ Save
+ </button>
+ </>
+ )}
<button
className="term-node__close"
title="Close"
@@ -124,15 +167,37 @@ export function EditorNode({ id, data, selected }: NodeProps<CanvasNode>) {
</div>
<div className="editor-node__body">
- <div className="editor-node__monaco nodrag nowheel" ref={bodyRef} />
- {preview && (
- <div className="term-md nodrag nowheel">
- <div className="term-md__bar">
- <span>Preview</span>
- <span className="term-md__hint">⌘M to edit</span>
- </div>
- <div className="term-md__content" dangerouslySetInnerHTML={{ __html: previewHtml }} />
+ {isImage ? (
+ <div className="editor-node__image nodrag nowheel">
+ {imageSrc ? (
+ <img
+ src={imageSrc}
+ alt={fileName}
+ onLoad={(e) => {
+ const img = e.currentTarget
+ if (img.naturalWidth) setImageDims(`${img.naturalWidth} × ${img.naturalHeight}`)
+ }}
+ />
+ ) : (
+ <span className="editor-node__loading">Loading…</span>
+ )}
</div>
+ ) : (
+ <>
+ <div className="editor-node__monaco nodrag nowheel" ref={bodyRef} />
+ {preview && (
+ <div className="term-md nodrag nowheel">
+ <div className="term-md__bar">
+ <span>Preview</span>
+ <span className="term-md__hint">⌘M to edit</span>
+ </div>
+ <div
+ className="term-md__content"
+ dangerouslySetInnerHTML={{ __html: previewHtml }}
+ />
+ </div>
+ )}
+ </>
)}
</div>
</div>
diff --git a/src/renderer/styles.css b/src/renderer/styles.css
index e89a76b87..c89c3174a 100644
--- a/src/renderer/styles.css
+++ b/src/renderer/styles.css
@@ -988,6 +988,44 @@ body,
opacity: 0.6;
}
+/* Image preview (shown instead of Monaco for image files). */
+.editor-node__image {
+ position: absolute;
+ inset: 0;
+ display: flex;
+ align-items: center;
+ justify-content: center;
+ padding: 16px;
+ overflow: auto;
+ /* checkerboard so transparency in the image is visible */
+ background-color: #1a1a1a;
+ background-image: linear-gradient(45deg, #242424 25%, transparent 25%),
+ linear-gradient(-45deg, #242424 25%, transparent 25%),
+ linear-gradient(45deg, transparent 75%, #242424 75%),
+ linear-gradient(-45deg, transparent 75%, #242424 75%);
+ background-size: 20px 20px;
+ background-position: 0 0, 0 10px, 10px -10px, -10px 0;
+}
+
+.editor-node__image img {
+ max-width: 100%;
+ max-height: 100%;
+ object-fit: contain;
+ border-radius: 4px;
+}
+
+.editor-node__loading {
+ color: var(--muted);
+ font-size: 12px;
+}
+
+.editor-node__dims {
+ color: var(--muted);
+ font-size: 11px;
+ font-variant-numeric: tabular-nums;
+ flex-shrink: 0;
+}
+
/* ---- Sticky note node ---- */
.sticky-node {
width: 100%;
diff --git a/src/shared/ipc.ts b/src/shared/ipc.ts
index 9191eed1a..9f27491ed 100644
--- a/src/shared/ipc.ts
+++ b/src/shared/ipc.ts
@@ -26,6 +26,7 @@ export const IPC = {
shellOpenPath: 'shell:open-path',
fsList: 'fs:list',
fsRead: 'fs:read',
+ fsReadBinary: 'fs:read-binary',
fsWrite: 'fs:write',
settingsLoad: 'settings:load',
settingsSave: 'settings:save',
diff --git a/src/shared/types.ts b/src/shared/types.ts
index ebd589f5e..26d62c47f 100644
--- a/src/shared/types.ts
+++ b/src/shared/types.ts
@@ -139,6 +139,8 @@ export interface FsApi {
list(dirPath: string): Promise<DirEntry[]>
/** Read a file's text contents (empty string on error). */
read(filePath: string): Promise<string>
+ /** Read a file as base64 (for images and other binary previews; '' on error). */
+ readBinary(filePath: string): Promise<string>
/** Write text to a file; resolves true on success. */
write(filePath: string, content: string): Promise<boolean>
}