-
Notifications
You must be signed in to change notification settings - Fork 76
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Prompt fix #22
Prompt fix #22
Changes from 2 commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Large diffs are not rendered by default.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,18 +1,10 @@ | ||
import { h, Component } from "preact"; | ||
|
||
import * as Comlink from "comlink"; | ||
|
||
import { Duplex, PassThrough } from "stream"; | ||
import parse_ from "shell-parse"; | ||
const parse = parse_; | ||
|
||
import { Terminal } from "xterm"; | ||
|
||
import parse from "shell-parse"; | ||
import { Terminal, IBufferLine } from "xterm"; | ||
import Process from "../process/process"; | ||
|
||
import { CommandOptions, Command } from "./command"; | ||
|
||
import { CommandOptions } from "./command"; | ||
import CommandFetcher from "./command-fetcher"; | ||
import LocalEchoController from "../local-echo/LocalEchoController"; | ||
|
||
let processWorkerBlobUrl: string | undefined = undefined; | ||
const getBlobUrlForProcessWorker = async (xterm: Terminal) => { | ||
|
@@ -112,6 +104,7 @@ export default class CommandRunner { | |
xterm: Terminal; | ||
commandString: string; | ||
stdoutOnCurrentLine: string; | ||
localEcho: LocalEchoController; | ||
|
||
commandEndCallback: Function; | ||
commandFetcherCallback: Function; | ||
|
@@ -132,6 +125,10 @@ export default class CommandRunner { | |
(window as any).SharedArrayBuffer && (window as any).Atomics; | ||
|
||
this.xterm = xterm; | ||
this.localEcho = new LocalEchoController(this.xterm, { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. So the suffix |
||
historySize: 0, | ||
maxAutocompleteEntries: 0 | ||
}); | ||
this.commandString = commandString; | ||
this.stdoutOnCurrentLine = ""; | ||
|
||
|
@@ -171,14 +168,6 @@ export default class CommandRunner { | |
await this.tryToSpawnProcess(0); | ||
} | ||
|
||
sendStdinLine(line: string) { | ||
// Remove our stdout prefix if we have one | ||
const stdin = line.replace(this.stdoutOnCurrentLine, ""); | ||
|
||
const data = new TextEncoder().encode(stdin); | ||
this.addStdinToSharedStdin(data, 0); | ||
} | ||
|
||
addStdinToSharedStdin(data: Uint8Array, processObjectIndex: number) { | ||
// Pass along the stdin to the shared object | ||
|
||
|
@@ -314,18 +303,21 @@ export default class CommandRunner { | |
this.pipedStdinDataForNextProcess = newPipedStdinData; | ||
} | ||
} else { | ||
// console.log("processDataCallback"); | ||
// Write the output to our terminal | ||
let dataString = new TextDecoder("utf-8").decode(data); | ||
// console.log("processDataCallback", dataString); | ||
this.xterm.write(dataString.replace(/\n/g, "\r\n")); | ||
|
||
this.stdoutOnCurrentLine = dataString; | ||
// Check if the data ended with 10 (New Line) | ||
// If it did, then clear the stdout we have on our line | ||
// Otherwise, record this that way we don't send it along our stdin | ||
if (data[data.length - 1] === 10) { | ||
this.stdoutOnCurrentLine = ""; | ||
} else { | ||
this.stdoutOnCurrentLine += dataString; | ||
} | ||
// if (data[data.length - 1] === 10) { | ||
// this.stdoutOnCurrentLine = ""; | ||
// } else { | ||
// // let lines = dataString.split("\n"); | ||
// this.stdoutOnCurrentLine = dataString; //lines[lines.length-1]; | ||
// } | ||
} | ||
} | ||
|
||
|
@@ -357,8 +349,21 @@ export default class CommandRunner { | |
this.commandEndCallback(); | ||
} | ||
|
||
// TODO: Maybe Remove this? May not need it? Wait until cleanup... | ||
processStdinReadCallback() {} | ||
processStdinReadCallback() { | ||
// When the stdin read begins | ||
console.log( | ||
`processStdinReadCallback y:${this.xterm.buffer.cursorY}, x: ${this.xterm.buffer.cursorX}, stdoutOnCurrentLine: ${this.stdoutOnCurrentLine}` | ||
); | ||
// let promptRead = (line as IBufferLine).translateToString(false, 0, this.xterm.buffer.cursorX); | ||
// console.log(promptRead); | ||
// this.xterm.write("\u001b[2K\r\u001b[2K"); | ||
// let lines = this.stdoutOnCurrentLine.split("\n"); | ||
this.localEcho.read("").then((stdin: string) => { | ||
this.stdoutOnCurrentLine = ""; | ||
const data = new TextEncoder().encode(stdin); | ||
this.addStdinToSharedStdin(data, 0); | ||
}); | ||
} | ||
|
||
kill() { | ||
if (!this.isRunning) { | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
/** | ||
* The history controller provides an ring-buffer | ||
*/ | ||
export class HistoryController { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Probably would like to rename this to CommandHistoryService. 😄 |
||
size: number; | ||
entries: Array<string>; | ||
cursor: number; | ||
|
||
constructor(size: number) { | ||
this.size = size; | ||
this.entries = []; | ||
this.cursor = 0; | ||
} | ||
|
||
/** | ||
* Push an entry and maintain ring buffer size | ||
*/ | ||
push(entry: string) { | ||
// Skip empty entries | ||
if (entry.trim() === "") return; | ||
// Skip duplicate entries | ||
const lastEntry = this.entries[this.entries.length - 1]; | ||
if (entry == lastEntry) return; | ||
// Keep track of entries | ||
this.entries.push(entry); | ||
if (this.entries.length > this.size) { | ||
this.entries.pop(); | ||
} | ||
this.cursor = this.entries.length; | ||
} | ||
|
||
/** | ||
* Rewind history cursor on the last entry | ||
*/ | ||
rewind() { | ||
this.cursor = this.entries.length; | ||
} | ||
|
||
/** | ||
* Returns the previous entry | ||
*/ | ||
getPrevious() { | ||
const idx = Math.max(0, this.cursor - 1); | ||
this.cursor = idx; | ||
return this.entries[idx]; | ||
} | ||
|
||
/** | ||
* Returns the next entry | ||
*/ | ||
getNext() { | ||
const idx = Math.min(this.entries.length, this.cursor + 1); | ||
this.cursor = idx; | ||
return this.entries[idx]; | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
All this imports were not used, so I removed them
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you! 😄