opencode-miniterm 1.0.8 → 1.0.10

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (2) hide show
  1. package/package.json +1 -1
  2. package/src/index.ts +37 -28
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "opencode-miniterm",
3
- "version": "1.0.8",
3
+ "version": "1.0.10",
4
4
  "description": "A small front-end terminal UI for OpenCode",
5
5
  "main": "src/index.ts",
6
6
  "bin": {
package/src/index.ts CHANGED
@@ -182,48 +182,55 @@ let completionCycling = false;
182
182
  let lastSpaceTime = 0;
183
183
  let currentInputBuffer: string | null = null;
184
184
 
185
+ let count = 0;
185
186
  let oldWrappedRows = 0;
187
+ let oldCursorRow = 0;
186
188
  function renderLine(): void {
187
189
  const consoleWidth = process.stdout.columns || 80;
188
190
 
189
191
  readline.cursorTo(process.stdout, 0);
192
+
193
+ // Ensure the cursor is at the end of the old input
194
+ if (cursorPosition < inputBuffer.length) {
195
+ readline.moveCursor(process.stdout, 0, oldWrappedRows - oldCursorRow);
196
+ }
197
+
198
+ // Clear the old input
190
199
  if (oldWrappedRows > 0) {
191
200
  readline.moveCursor(process.stdout, 0, -oldWrappedRows);
192
201
  }
193
202
  readline.clearScreenDown(process.stdout);
203
+ readline.cursorTo(process.stdout, 2);
194
204
 
205
+ // Write the prompt
195
206
  writePrompt();
196
207
 
208
+ // Write the new input buffer
209
+ let renderExtent = Math.max(cursorPosition + 1, inputBuffer.length);
197
210
  let currentCol = 2;
198
- let row = 0;
199
- for (let i = 0; i < inputBuffer.length; i++) {
211
+ let newWrappedRows = 0;
212
+ for (let i = 0; i < renderExtent; i++) {
200
213
  if (currentCol >= consoleWidth) {
201
214
  process.stdout.write("\n");
202
215
  currentCol = 0;
203
- row++;
216
+ newWrappedRows++;
204
217
  }
205
- process.stdout.write(inputBuffer[i]!);
206
- currentCol++;
207
- }
208
- oldWrappedRows = row;
209
-
210
- let targetRow = 0;
211
- let targetCol = 0;
212
- let pos = 2;
213
- for (let i = 0; i < cursorPosition; i++) {
214
- if (pos >= consoleWidth) {
215
- targetRow++;
216
- pos = 0;
218
+ if (i < inputBuffer.length) {
219
+ process.stdout.write(inputBuffer[i]!);
217
220
  }
218
- pos++;
221
+ currentCol++;
219
222
  }
220
- targetCol = pos;
223
+
224
+ let absolutePos = 2 + cursorPosition;
225
+ let newCursorRow = Math.floor(absolutePos / consoleWidth);
226
+ let newCursorCol = absolutePos % consoleWidth;
221
227
 
222
228
  readline.cursorTo(process.stdout, 0);
223
- if (targetRow > 0) {
224
- process.stdout.write(`\x1b[${targetRow}B`);
225
- }
226
- readline.cursorTo(process.stdout, targetCol);
229
+ readline.moveCursor(process.stdout, 0, -1 * (newWrappedRows - newCursorRow));
230
+ readline.cursorTo(process.stdout, newCursorCol);
231
+
232
+ oldWrappedRows = newWrappedRows;
233
+ oldCursorRow = newCursorRow;
227
234
  }
228
235
 
229
236
  async function handleKeyPress(str: string, key: Key) {
@@ -805,7 +812,12 @@ async function processText(part: Part) {
805
812
  async function processToolUse(part: Part) {
806
813
  const toolPart = part as ToolPart;
807
814
  const toolName = toolPart.tool || "unknown";
808
- const toolInput = toolPart.state.input["description"] || toolPart.state.input["filePath"] || {};
815
+ const toolInput =
816
+ toolPart.state.input["description"] ||
817
+ toolPart.state.input["filePath"] ||
818
+ toolPart.state.input["path"] ||
819
+ // TODO: more state.input props...
820
+ "...";
809
821
  const toolText = `$ ${toolName}: ${ansi.BRIGHT_BLACK}${toolInput}${ansi.RESET}`;
810
822
 
811
823
  if (state.accumulatedResponse[state.accumulatedResponse.length - 1]?.title === "tool") {
@@ -835,14 +847,11 @@ async function processDiff(diff: FileDiff[]) {
835
847
  const newAfter = file.after ?? "";
836
848
  const oldAfter = state.lastFileAfter.get(file.file);
837
849
  if (newAfter !== oldAfter) {
838
- const status = !file.before ? "added" : !file.after ? "deleted" : "modified";
839
- const statusIcon = status === "added" ? "A" : status === "modified" ? "M" : "D";
840
- const statusLabel =
841
- status === "added" ? "added" : status === "modified" ? "modified" : "deleted";
850
+ const statusIcon = !file.before ? "A" : !file.after ? "D" : "M";
842
851
  const addStr = file.additions > 0 ? `${ansi.GREEN}+${file.additions}${ansi.RESET}` : "";
843
852
  const delStr = file.deletions > 0 ? `${ansi.RED}-${file.deletions}${ansi.RESET}` : "";
844
853
  const stats = [addStr, delStr].filter(Boolean).join(" ");
845
- const line = `${ansi.BLUE}${statusIcon}${ansi.RESET} ${file.file} (${statusLabel}) ${stats}`;
854
+ const line = `${ansi.BLUE}${statusIcon}${ansi.RESET} ${file.file} ${stats}`;
846
855
  parts.push(line);
847
856
 
848
857
  state.lastFileAfter.set(file.file, newAfter);
@@ -876,7 +885,7 @@ async function processTodos(todos: Todo[]) {
876
885
  state.accumulatedResponse.push({ key: "todo", title: "files", text: todoListText });
877
886
 
878
887
  const cleanTodoText = ansi.stripAnsiCodes(todoListText);
879
- await writeToLog(`${cleanTodoText}\n\n`);
888
+ await writeToLog(`${cleanTodoText}\n`);
880
889
 
881
890
  render(state);
882
891
  }