forked from Acode-Foundation/Acode
-
Notifications
You must be signed in to change notification settings - Fork 6
Expand file tree
/
Copy pathterminalSettings.js
More file actions
385 lines (365 loc) · 9.66 KB
/
terminalSettings.js
File metadata and controls
385 lines (365 loc) · 9.66 KB
1
2
3
4
5
6
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
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
import fsOperation from "fileSystem";
import settingsPage from "components/settingsPage";
import {
DEFAULT_TERMINAL_SETTINGS,
TerminalThemeManager,
} from "components/terminal";
import toast from "components/toast";
import alert from "dialogs/alert";
import loader from "dialogs/loader";
import fonts from "lib/fonts";
import appSettings from "lib/settings";
import FileBrowser from "pages/fileBrowser";
import helpers from "utils/helpers";
export default function terminalSettings() {
const title = strings["terminal settings"];
const values = appSettings.value;
// Initialize terminal settings with defaults if not present
if (!values.terminalSettings) {
values.terminalSettings = {
...DEFAULT_TERMINAL_SETTINGS,
fontFamily:
DEFAULT_TERMINAL_SETTINGS.fontFamily || appSettings.value.fontFamily,
};
}
const terminalValues = values.terminalSettings;
const items = [
{
key: "all_file_access",
text: strings.allFileAccess.capitalize(),
info: "Enable access of /sdcard and /storage in terminal",
},
{
key: "fontSize",
text: strings["font size"],
value: terminalValues.fontSize,
prompt: strings["font size"],
promptType: "number",
promptOptions: {
test(value) {
value = Number.parseInt(value);
return value >= 8 && value <= 32;
},
},
info: "The font size used to render text.",
},
{
key: "fontFamily",
text: strings["terminal:font family"],
value: terminalValues.fontFamily,
get select() {
return fonts.getNames();
},
info: "The font family used to render text.",
},
{
key: "theme",
text: strings["theme"],
value: terminalValues.theme,
info: "The color theme of the terminal.",
get select() {
return TerminalThemeManager.getThemeNames().map((name) => [
name,
name.charAt(0).toUpperCase() + name.slice(1),
]);
},
valueText(value) {
const option = this.select.find(([v]) => v === value);
return option ? option[1] : value;
},
},
{
key: "cursorStyle",
text: strings["terminal:cursor style"],
value: terminalValues.cursorStyle,
select: ["block", "underline", "bar"],
info: "The style of the cursor when the terminal is focused.",
},
{
key: "cursorInactiveStyle",
text: strings["terminal:cursor inactive style"],
value: terminalValues.cursorInactiveStyle,
select: ["outline", "block", "bar", "underline", "none"],
info: "The style of the cursor when the terminal is not focused.",
},
{
key: "fontWeight",
text: strings["terminal:font weight"],
value: terminalValues.fontWeight,
select: [
"normal",
"bold",
"100",
"200",
"300",
"400",
"500",
"600",
"700",
"800",
"900",
],
info: "The font weight used to render non-bold text.",
},
{
key: "cursorBlink",
text: strings["terminal:cursor blink"],
checkbox: terminalValues.cursorBlink,
info: "Whether the cursor blinks.",
},
{
key: "scrollback",
text: strings["terminal:scrollback"],
value: terminalValues.scrollback,
prompt: strings["terminal:scrollback"],
promptType: "number",
promptOptions: {
test(value) {
value = Number.parseInt(value);
return value >= 100 && value <= 10000;
},
},
info: "The amount of scrollback in the terminal. Scrollback is the amount of rows that are retained when lines are scrolled beyond the initial viewport.",
},
{
key: "tabStopWidth",
text: strings["terminal:tab stop width"],
value: terminalValues.tabStopWidth,
prompt: strings["terminal:tab stop width"],
promptType: "number",
promptOptions: {
test(value) {
value = Number.parseInt(value);
return value >= 1 && value <= 8;
},
},
info: "The size of tab stops in the terminal.",
},
{
key: "letterSpacing",
text: strings["letter spacing"],
value: terminalValues.letterSpacing,
prompt: strings["letter spacing"],
promptType: "number",
info: "The spacing in whole pixels between characters.",
},
{
key: "convertEol",
text: strings["terminal:convert eol"],
checkbox: terminalValues.convertEol,
},
{
key: "imageSupport",
text: `${strings["image"]} Support`,
checkbox: terminalValues.imageSupport,
info: "Whether images are supported in the terminal.",
},
{
key: "fontLigatures",
text: strings["font ligatures"],
checkbox: terminalValues.fontLigatures,
info: "Whether font ligatures are enabled in the terminal.",
},
{
key: "backup",
text: strings.backup.capitalize(),
info: "Creates a backup of the terminal installation",
},
{
key: "restore",
text: strings.restore.capitalize(),
info: "Restores a backup of the terminal installation",
},
{
key: "uninstall",
text: strings.uninstall.capitalize(),
info: "Uninstalls the terminal installation",
},
];
return settingsPage(title, items, callback);
/**
* Callback for settings page when an item is clicked
* @param {string} key
* @param {string} value
*/
function callback(key, value) {
switch (key) {
case "all_file_access":
if (ANDROID_SDK_INT >= 30) {
system.isManageExternalStorageDeclared((boolStr) => {
if (boolStr === "true") {
system.requestStorageManager(console.log, console.error);
} else {
alert("This feature is not available.");
}
}, alert);
} else {
alert("This feature is not available.");
}
return;
case "backup":
terminalBackup();
return;
case "restore":
terminalRestore();
return;
case "uninstall":
loader.showTitleLoader();
Terminal.uninstall()
.then(() => {
loader.removeTitleLoader();
alert(
strings.success.toUpperCase(),
"Terminal uninstalled successfully.",
);
})
.catch((error) => {
loader.removeTitleLoader();
console.error("Terminal uninstall failed:", error);
helpers.error(error);
});
return;
default:
appSettings.update({
terminalSettings: {
...values.terminalSettings,
[key]: value,
},
});
// Update any active terminal instances
updateActiveTerminals(key, value);
break;
}
}
/**
* Creates a backup of the terminal installation
*/
async function terminalBackup() {
try {
// Ask user to select backup location
const { url } = await FileBrowser("folder", strings["select folder"]);
loader.showTitleLoader();
// Create backup
const backupPath = await Terminal.backup();
await system.copyToUri(
backupPath,
url,
"aterm_backup.tar",
console.log,
console.error,
);
loader.removeTitleLoader();
alert(strings.success.toUpperCase(), `${strings["backup successful"]}.`);
} catch (error) {
loader.removeTitleLoader();
console.error("Terminal backup failed:", error);
toast(error.toString());
}
}
/**
* Restores terminal installation
*/
async function terminalRestore() {
try {
sdcard.openDocumentFile(
async (data) => {
loader.showTitleLoader();
//this will create a file at $PREFIX/atem_backup.bin
await system.copyToUri(
data.uri,
cordova.file.dataDirectory,
"aterm_backup",
console.log,
console.error,
);
// Restore
await Terminal.restore();
// Clean up
const backupFilename = "aterm_backup.bin";
const tempBackupPath = cordova.file.dataDirectory + backupFilename;
const tempFS = fsOperation(tempBackupPath);
await tempFS.delete();
loader.removeTitleLoader();
alert(
strings.success.toUpperCase(),
"Terminal restored successfully",
);
},
toast,
"application/x-tar",
);
} catch (error) {
loader.removeTitleLoader();
console.error("Terminal restore failed:", error);
toast(error.toString());
}
}
}
/**
* Update active terminal instances with new settings
* @param {string} key
* @param {any} value
*/
async function updateActiveTerminals(key, value) {
// Find all terminal tabs and update their settings
const terminalTabs = editorManager.files.filter(
(file) => file.type === "terminal",
);
terminalTabs.forEach(async (tab) => {
if (tab.terminalComponent) {
const terminalOptions = {};
switch (key) {
case "fontSize":
tab.terminalComponent.terminal.options.fontSize = value;
break;
case "fontFamily":
// Load font if it's not already loaded
try {
await fonts.loadFont(value);
} catch (error) {
console.warn(`Failed to load font ${value}:`, error);
}
tab.terminalComponent.terminal.options.fontFamily = value;
tab.terminalComponent.terminal.refresh(
0,
tab.terminalComponent.terminal.rows - 1,
);
break;
case "fontWeight":
tab.terminalComponent.terminal.options.fontWeight = value;
break;
case "cursorBlink":
tab.terminalComponent.terminal.options.cursorBlink = value;
break;
case "cursorStyle":
tab.terminalComponent.terminal.options.cursorStyle = value;
break;
case "cursorInactiveStyle":
tab.terminalComponent.terminal.options.cursorInactiveStyle = value;
break;
case "scrollback":
tab.terminalComponent.terminal.options.scrollback = value;
break;
case "tabStopWidth":
tab.terminalComponent.terminal.options.tabStopWidth = value;
break;
case "convertEol":
tab.terminalComponent.terminal.options.convertEol = value;
break;
case "letterSpacing":
tab.terminalComponent.terminal.options.letterSpacing = value;
break;
case "theme":
tab.terminalComponent.terminal.options.theme =
TerminalThemeManager.getTheme(value);
break;
case "imageSupport":
tab.terminalComponent.updateImageSupport(value);
break;
case "fontLigatures":
tab.terminalComponent.updateFontLigatures(value);
break;
}
}
});
}