Skip to content

Commit cdd8422

Browse files
author
Kane Hsieh
committed
copy
1 parent a2f1459 commit cdd8422

File tree

1 file changed

+45
-31
lines changed

1 file changed

+45
-31
lines changed

js/terminal-ext.js

Lines changed: 45 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -10,30 +10,33 @@ extend = (term) => {
1010
term.history = [];
1111
term.historyCursor = -1;
1212
term.pos = () => term._core.buffer.x - term._promptRawText().length - 1;
13-
term._promptRawText = () => `${term.user}${term.sep}${term.host} ${term.cwd} $`;
13+
term._promptRawText = () =>
14+
`${term.user}${term.sep}${term.host} ${term.cwd} $`;
1415
term.deepLink = window.location.hash.replace("#", "").split("-").join(" ");
1516

1617
term.promptText = () => {
17-
var text = term._promptRawText().replace(term.user, colorText(term.user, "user"))
18+
var text = term
19+
._promptRawText()
20+
.replace(term.user, colorText(term.user, "user"))
1821
.replace(term.sep, colorText(term.sep, ""))
1922
.replace(term.host, colorText(term.host, ""))
2023
.replace(term.cwd, colorText(term.cwd, "hyperlink"))
2124
.replace(term._promptChar, colorText(term._promptChar, "prompt"));
2225
return text;
23-
}
26+
};
2427

25-
term.timer = ms => new Promise(res => setTimeout(res, ms));
28+
term.timer = (ms) => new Promise((res) => setTimeout(res, ms));
2629

2730
term.dottedPrint = async (phrase, n, newline = true) => {
2831
term.write(phrase);
2932

3033
for (let i = 0; i < n; i++) {
31-
await term.delayPrint('.', 1000);
34+
await term.delayPrint(".", 1000);
3235
}
3336
if (newline) {
3437
term.write("\r\n");
3538
}
36-
}
39+
};
3740

3841
term.progressBar = async (t, msg) => {
3942
var r;
@@ -44,29 +47,29 @@ extend = (term) => {
4447
term.write("\r\n[");
4548

4649
for (let i = 0; i < term.cols / 2; i = i + 1) {
47-
r = Math.round(Math.random() * t / 20);
50+
r = Math.round((Math.random() * t) / 20);
4851
t = t - r;
49-
await term.delayPrint('█', r);
52+
await term.delayPrint("█", r);
5053
}
5154
term.write("]\r\n");
52-
}
55+
};
5356

5457
term.delayPrint = async (str, t) => {
5558
await term.timer(t);
5659
term.write(str);
57-
}
60+
};
5861

5962
term.delayStylePrint = async (str, t, wrap) => {
6063
await term.timer(t);
6164
term.stylePrint(str, wrap);
62-
}
65+
};
6366

6467
term.prompt = (prefix = "\r\n", suffix = " ") => {
6568
term.write(`${prefix}${term.promptText()}${suffix}`);
6669
};
6770

6871
term.clearCurrentLine = (goToEndofHistory = false) => {
69-
term.write('\x1b[2K\r');
72+
term.write("\x1b[2K\r");
7073
term.prompt("", " ");
7174
term.currentLine = "";
7275
if (goToEndofHistory) {
@@ -81,13 +84,14 @@ extend = (term) => {
8184
term.currentLine = newLine;
8285
term.write(newLine);
8386
if (preserveCursor) {
84-
term.write('\x1b[D'.repeat(length - term.pos()));
87+
term.write("\x1b[D".repeat(length - term.pos()));
8588
}
86-
}
89+
};
8790

8891
term.stylePrint = (text, wrap = true) => {
8992
// Hyperlinks
90-
const urlRegex = /https?:\/\/(www\.)?[-a-zA-Z0-9@:%._\+~#=]{1,256}\.[a-zA-Z0-9()]{1,6}\b([-a-zA-Z0-9()@:%_\+.~#?&//=]*)/g;
93+
const urlRegex =
94+
/https?:\/\/(www\.)?[-a-zA-Z0-9@:%._\+~#=]{1,256}\.[a-zA-Z0-9()]{1,6}\b([-a-zA-Z0-9()@:%_\+.~#?&//=]*)/g;
9195
const urlMatches = text.matchAll(urlRegex);
9296
let allowWrapping = true;
9397
for (match of urlMatches) {
@@ -116,11 +120,11 @@ extend = (term) => {
116120
if (term.cols >= 40) {
117121
term.writeln(`\r\n${getArt(id)}\r\n`);
118122
}
119-
}
123+
};
120124

121125
term.printLogoType = () => {
122126
term.writeln(term.cols >= 40 ? LOGO_TYPE : "[Root Ventures]\r\n");
123-
}
127+
};
124128

125129
term.openURL = (url, newWindow = true) => {
126130
term.stylePrint(`Opening ${url}`);
@@ -132,23 +136,23 @@ extend = (term) => {
132136
window.location.href = url;
133137
}
134138
}
135-
}
139+
};
136140

137141
term.displayURL = (url) => {
138142
term.stylePrint(colorText(url, "hyperlink"));
139-
}
143+
};
140144

141145
term.command = (line) => {
142146
const parts = line.split(/\s+/);
143147
const cmd = parts[0].toLowerCase();
144-
const args = parts.slice(1, parts.length)
148+
const args = parts.slice(1, parts.length);
145149
const fn = commands[cmd];
146-
if (typeof (fn) === "undefined") {
150+
if (typeof fn === "undefined") {
147151
term.stylePrint(`Command not found: ${cmd}. Try 'help' to get started.`);
148152
} else {
149153
return fn(args);
150154
}
151-
}
155+
};
152156

153157
term.resizeListener = () => {
154158
term._initialized = false;
@@ -169,9 +173,17 @@ extend = (term) => {
169173
preloadFiles();
170174
term.reset();
171175
term.printLogoType();
172-
term.stylePrint('Welcome to the Root Ventures terminal. Seeding bold engineers!');
173-
term.stylePrint(`Type ${colorText("help", "command")} to get started. Or type ${colorText("exit", "command")} for web version.`, false);
174-
term.stylePrint(`\r\nOpen jobs detected. Type ${colorText("jobs", "command")} for more info.`, false);
176+
term.stylePrint(
177+
"Welcome to the Root Ventures terminal. We are investing in technical founders.",
178+
);
179+
term.stylePrint(
180+
`Type ${colorText("help", "command")} to get started. Or type ${colorText("exit", "command")} for web version.`,
181+
false,
182+
);
183+
term.stylePrint(
184+
`\r\nOpen jobs detected. Type ${colorText("jobs", "command")} for more info.`,
185+
false,
186+
);
175187

176188
term.user = user;
177189
if (!preserveHistory) {
@@ -184,27 +196,29 @@ extend = (term) => {
184196
if (term.deepLink != "") {
185197
term.command(term.deepLink);
186198
}
187-
}
188-
}
199+
};
200+
};
189201

190202
// https://stackoverflow.com/questions/14484787/wrap-text-in-javascript
191203
// TODO: This doesn't work well at detecting newline
192204
function _wordWrap(str, maxWidth) {
193-
var newLineStr = "\r\n"; done = false; res = '';
205+
var newLineStr = "\r\n";
206+
done = false;
207+
res = "";
194208
while (str.length > maxWidth) {
195209
found = false;
196210
// Inserts new line at first whitespace of the line
197211
for (i = maxWidth - 1; i >= 0; i--) {
198212
if (_testWhite(str.charAt(i))) {
199-
res = res + [str.slice(0, i), newLineStr].join('');
213+
res = res + [str.slice(0, i), newLineStr].join("");
200214
str = str.slice(i + 1);
201215
found = true;
202216
break;
203217
}
204218
}
205219
// Inserts new line at maxWidth position, the word is too long to wrap
206220
if (!found) {
207-
res += [str.slice(0, maxWidth), newLineStr].join('');
221+
res += [str.slice(0, maxWidth), newLineStr].join("");
208222
str = str.slice(maxWidth);
209223
}
210224
}
@@ -214,4 +228,4 @@ function _wordWrap(str, maxWidth) {
214228
function _testWhite(x) {
215229
var white = new RegExp(/^\s$/);
216230
return white.test(x.charAt(0));
217-
};
231+
}

0 commit comments

Comments
 (0)