diff --git a/package.json b/package.json
index f1c7b7f..e265153 100644
--- a/package.json
+++ b/package.json
@@ -1,6 +1,6 @@
{
"name": "fwdekker.com",
- "version": "0.39.1",
+ "version": "0.39.2",
"description": "The source code of [my personal website](https://fwdekker.com/).",
"author": "Felix W. Dekker",
"browser": "dist/bundle.js",
diff --git a/src/main/js/Commands.ts b/src/main/js/Commands.ts
index 559d0cb..30d4c65 100644
--- a/src/main/js/Commands.ts
+++ b/src/main/js/Commands.ts
@@ -515,19 +515,22 @@ return new Command(
"echo": /* language=JavaScript */ `\
return new Command(
(input, streams) => {
- const message = input.args.join(" ").replace("hunter2", "*******");
-
- if (input.hasAnyOption("-n", "--newline"))
- streams.out.write(message);
- else
- streams.out.writeLine(message);
+ let message = input.args.join(" ").replace("hunter2", "*******");
+ if (input.hasAnyOption("-e", "--escapes"))
+ message = message.replace(/\\\\n/g, "\\n");
+ if (!input.hasAnyOption("-n", "--newline"))
+ message = message + "\\n";
+ streams.out.write(message);
return ExitCode.OK;
},
\`display text\`,
- \`echo [-n | --newline] [text ...]\`,
+ \`echo [-e | --escapes] [-n | --newline] [text ...]\`,
\`Displays each text separated by a single whitespace.
+ If the --escapes parameter is given, the newline escape sequence "\\\\n" is replaced by an actual newline
+ character.
+
Unless the --newline parameter is given, a newline is appended to the end.\`.trimMultiLines(),
new InputValidator()
)`,
@@ -538,8 +541,10 @@ return new Command(
return parseInt(input.args[0] || "0");
},
\`close session\`,
- \`exit\`,
- \`Closes the terminal session.\`,
+ \`exit [status]\`,
+ \`Closes the terminal session.
+
+ Returns status code status if it is defined, and returns 0 otherwise.\`,
new InputValidator({minArgs: 0, maxArgs: 1})
)`,
"false": /* language=JavaScript */ `\
diff --git a/src/test/Commands.spec.ts b/src/test/Commands.spec.ts
index dc79e2d..ea4deb5 100644
--- a/src/test/Commands.spec.ts
+++ b/src/test/Commands.spec.ts
@@ -345,14 +345,28 @@ describe("commands", () => {
beforeEach(() => loadCommand("echo"));
- it("adds a newline to the end by default", () => {
- expect(execute("echo a b c \n")).to.equal(ExitCode.OK);
- expect(readOut()).to.equal("a b c \n\n");
+ describe("--escapes", () => {
+ it("does not unescape newlines by default", () => {
+ expect(execute("echo 'a b \\n c'")).to.equal(ExitCode.OK);
+ expect(readOut()).to.equal("a b \\n c\n");
+ });
+
+ it("unescapes newlines if prompted to do so", () => {
+ expect(execute("echo -e 'a b \\n c'")).to.equal(ExitCode.OK);
+ expect(readOut()).to.equal("a b \n c\n");
+ });
});
- it("does not add a newline if prompted to do so", () => {
- expect(execute("echo -n a b c")).to.equal(ExitCode.OK);
- expect(readOut()).to.equal("a b c");
+ describe("--newline", () => {
+ it("adds a newline to the end by default, even if there is already a newline", () => {
+ expect(execute("echo a b c \n")).to.equal(ExitCode.OK);
+ expect(readOut()).to.equal("a b c \n\n");
+ });
+
+ it("does not add a newline if prompted to do so", () => {
+ expect(execute("echo -n a b c")).to.equal(ExitCode.OK);
+ expect(readOut()).to.equal("a b c");
+ });
});
});