mirror of
https://github.com/getcompanion-ai/co-mono.git
synced 2026-04-15 06:04:40 +00:00
The Editor component now accepts TUI as the first constructor parameter, enabling it to query terminal dimensions. When content exceeds available height, the editor scrolls vertically keeping the cursor visible. Features: - Max editor height is 30% of terminal rows (minimum 5 lines) - Page Up/Down keys scroll by page size - Scroll indicators show lines above/below: ─── ↑ 5 more ─── Breaking change: Editor constructor signature changed from new Editor(theme) to new Editor(tui, theme) fixes #732
35 lines
997 B
TypeScript
35 lines
997 B
TypeScript
/**
|
|
* Load file into editor - for testing editor scrolling
|
|
*
|
|
* Usage: pi --extension ./examples/extensions/load-file.ts
|
|
*
|
|
* Commands:
|
|
* /load [path] - Load file into editor (defaults to README.md)
|
|
*/
|
|
|
|
import * as fs from "node:fs";
|
|
import * as path from "node:path";
|
|
import type { ExtensionAPI } from "@mariozechner/pi-coding-agent";
|
|
|
|
export default function (pi: ExtensionAPI) {
|
|
pi.registerCommand("load", {
|
|
description: "Load file into editor (defaults to README.md)",
|
|
handler: async (args, ctx) => {
|
|
const filePath = args.trim() || "README.md";
|
|
const fullPath = path.resolve(filePath);
|
|
|
|
if (!fs.existsSync(fullPath)) {
|
|
ctx.ui.notify(`File not found: ${fullPath}`, "error");
|
|
return;
|
|
}
|
|
|
|
try {
|
|
const content = fs.readFileSync(fullPath, "utf-8");
|
|
ctx.ui.setEditorText(content);
|
|
ctx.ui.notify(`Loaded ${filePath} (${content.split("\n").length} lines)`);
|
|
} catch (err) {
|
|
ctx.ui.notify(`Failed to read file: ${err}`, "error");
|
|
}
|
|
},
|
|
});
|
|
}
|