Skip to content

Commit 90b5a6d

Browse files
feat: terminal frontend (#1415)
Co-authored-by: RohitKushvaha01 <oldisg131@gmail.com>
1 parent 3480319 commit 90b5a6d

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

63 files changed

+5905
-948
lines changed

package-lock.json

Lines changed: 84 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@
3636
},
3737
"cordova-plugin-websocket": {},
3838
"cordova-plugin-buildinfo": {},
39+
"com.foxdebug.acode.rk.exec.proot": {},
3940
"cordova-plugin-system": {},
4041
"com.foxdebug.acode.rk.exec.terminal": {}
4142
},
@@ -63,8 +64,9 @@
6364
"@types/url-parse": "^1.4.11",
6465
"autoprefixer": "^10.4.19",
6566
"babel-loader": "^9.1.3",
67+
"com.foxdebug.acode.rk.exec.proot": "file:src/plugins/proot",
6668
"com.foxdebug.acode.rk.exec.terminal": "file:src/plugins/terminal",
67-
"cordova-android": "13.0.0",
69+
"cordova-android": "^13.0.0",
6870
"cordova-clipboard": "^1.3.0",
6971
"cordova-plugin-advanced-http": "^3.3.1",
7072
"cordova-plugin-browser": "file:src/plugins/browser",
@@ -95,6 +97,14 @@
9597
"dependencies": {
9698
"@deadlyjack/ajax": "^1.2.6",
9799
"@ungap/custom-elements": "^1.3.0",
100+
"@xterm/addon-attach": "^0.11.0",
101+
"@xterm/addon-fit": "^0.10.0",
102+
"@xterm/addon-image": "^0.8.0",
103+
"@xterm/addon-search": "^0.15.0",
104+
"@xterm/addon-unicode11": "^0.8.0",
105+
"@xterm/addon-web-links": "^0.11.0",
106+
"@xterm/addon-webgl": "^0.18.0",
107+
"@xterm/xterm": "^5.5.0",
98108
"autosize": "^6.0.1",
99109
"cordova": "12.0.0",
100110
"core-js": "^3.37.1",

src/ace/commands.js

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -341,6 +341,14 @@ const commands = [
341341
},
342342
readOnly: true,
343343
},
344+
{
345+
name: "openTerminal",
346+
description: "Open Terminal",
347+
exec() {
348+
acode.exec("new-terminal");
349+
},
350+
readOnly: true,
351+
},
344352
];
345353

346354
export function setCommands(editor) {

src/components/terminal/index.js

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
/**
2+
* Terminal Components Export
3+
*/
4+
5+
import TerminalComponent from "./terminal";
6+
import { DEFAULT_TERMINAL_SETTINGS } from "./terminalDefaults";
7+
import TerminalManager from "./terminalManager";
8+
import TerminalThemeManager from "./terminalThemeManager";
9+
10+
export {
11+
TerminalComponent,
12+
TerminalManager,
13+
TerminalThemeManager,
14+
DEFAULT_TERMINAL_SETTINGS,
15+
};
16+
17+
export default {
18+
TerminalComponent,
19+
TerminalManager,
20+
TerminalThemeManager,
21+
DEFAULT_TERMINAL_SETTINGS,
22+
};
Lines changed: 102 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,102 @@
1+
// pretty basic ligature implementation for webview
2+
export default class LigaturesAddon {
3+
constructor(options = {}) {
4+
// fallback ligatures if a font does not support ligatures natively
5+
this._fallbackLigatures =
6+
options.fallbackLigatures ||
7+
[
8+
"<--",
9+
"<---",
10+
"<<-",
11+
"<-",
12+
"->",
13+
"->>",
14+
"-->",
15+
"--->",
16+
"<==",
17+
"<===",
18+
"<<=",
19+
"<=",
20+
"=>",
21+
"=>>",
22+
"==>",
23+
"===>",
24+
">=",
25+
">>=",
26+
"<->",
27+
"<-->",
28+
"<--->",
29+
"<---->",
30+
"<=>",
31+
"<==>",
32+
"<===>",
33+
"<====>",
34+
"<~~",
35+
"<~",
36+
"~>",
37+
"~~>",
38+
"::",
39+
":::",
40+
"==",
41+
"!=",
42+
"===",
43+
"!==",
44+
":=",
45+
":-",
46+
":+",
47+
"<*",
48+
"<*>",
49+
"*>",
50+
"<|",
51+
"<|>",
52+
"|>",
53+
"+:",
54+
"-:",
55+
"=:",
56+
":>",
57+
"++",
58+
"+++",
59+
"<!--",
60+
"<!---",
61+
"<***>",
62+
].sort((a, b) => b.length - a.length);
63+
this._characterJoinerId = undefined;
64+
this._terminal = undefined;
65+
}
66+
67+
activate(terminal) {
68+
this._terminal = terminal;
69+
this._characterJoinerId = terminal.registerCharacterJoiner(
70+
this._joinCharacters.bind(this),
71+
);
72+
terminal.element.style.fontFeatureSettings = `"liga" on, "calt" on`;
73+
}
74+
75+
dispose() {
76+
if (this._characterJoinerId !== undefined) {
77+
this._terminal?.deregisterCharacterJoiner(this._characterJoinerId);
78+
this._characterJoinerId = undefined;
79+
}
80+
if (this._terminal?.element) {
81+
this._terminal.element.style.fontFeatureSettings = "";
82+
}
83+
}
84+
85+
_joinCharacters(text) {
86+
return this._findLigatureRanges(text, this._fallbackLigatures);
87+
}
88+
89+
_findLigatureRanges(text, ligatures) {
90+
const ranges = [];
91+
for (let i = 0; i < text.length; i++) {
92+
for (const ligature of ligatures) {
93+
if (text.startsWith(ligature, i)) {
94+
ranges.push([i, i + ligature.length]);
95+
i += ligature.length - 1;
96+
break;
97+
}
98+
}
99+
}
100+
return ranges;
101+
}
102+
}

0 commit comments

Comments
 (0)