forked from tools/josh
1
0
Fork 0

Make error stream output red

Fixes #130.
This commit is contained in:
Florine W. Dekker 2020-06-30 19:27:06 +02:00
parent aa8b641f53
commit 3305197c65
Signed by: FWDekker
GPG Key ID: B1B567AF58D6EE0F
4 changed files with 24 additions and 4 deletions

View File

@ -1,6 +1,6 @@
{
"name": "fwdekker.com",
"version": "0.36.0",
"version": "0.37.0",
"description": "The source code of [my personal website](https://fwdekker.com/).",
"author": "Felix W. Dekker",
"browser": "dist/bundle.js",

View File

@ -105,5 +105,5 @@ body {
.errorMessage {
color: red;
color: #FF3333;
}

View File

@ -60,6 +60,27 @@ export class Terminal {
* The standard output stream.
*/
private readonly standardOutput = new Buffer();
/**
* The standard error stream, actually just a wrapper around the standard output stream.
*/
private readonly standardError = new class extends Buffer {
private wrappedBuffer: Buffer;
constructor(wrappedBuffer: Buffer) {
super();
this.wrappedBuffer = wrappedBuffer;
}
read(count: number | undefined = undefined): string {
return this.wrappedBuffer.read(count);
}
write(string: string) {
this.wrappedBuffer.write(`<span class="errorMessage">${string}</span>`);
}
}(this.standardOutput);
/**
@ -234,7 +255,7 @@ export class Terminal {
this.outputText += `${this.prefixText}${this.isInputHidden ? "" : escapeHtml(input)}\n`;
this.standardInput.writeLine(input);
this.shell.execute(new StreamSet(this.standardInput, this.standardOutput, this.standardOutput));
this.shell.execute(new StreamSet(this.standardInput, this.standardOutput, this.standardError));
let buffer = "";
while (this.standardOutput.has(1)) {

View File

@ -159,7 +159,6 @@ describe("commands", () => {
it("executes the command if the previous command exited successfully", () => {
environment.set("status", "" + ExitCode.OK);
// TODO (#129) Run `false` to check that the exit code changes
expect(execute("and echo 'message'")).to.equal(ExitCode.OK);
expect(readOut()).to.equal("message\n");
});