@@ -4,6 +4,7 @@ import * as helpers from "./utils/helpers.js";
4
4
import { themes } from "./utils/themes.js" ;
5
5
import AIResponseHandler from "./services/AiService.js" ;
6
6
import SelectionCore from "./core/selectionCore.js" ;
7
+ import Icons from "./utils/icons" ;
7
8
import {
8
9
ALLOW_TRANSPRANCY ,
9
10
CURSOR_BLINK ,
@@ -172,35 +173,35 @@ export default class AcodeX {
172
173
className : "action-button new-session" ,
173
174
ariaLabel : "New Session" ,
174
175
} ) ;
175
- newSessionBtn . innerHTML = `<svg viewBox="0 0 48 48" xmlns="http://www.w3.org/2000/svg" height="1.5em" width="1.5em"><path fill="currentColor" d="M24 38q-.65 0-1.075-.425-.425-.425-.425-1.075v-11h-11q-.65 0-1.075-.425Q10 24.65 10 24q0-.65.425-1.075.425-.425 1.075-.425h11v-11q0-.65.425-1.075Q23.35 10 24 10q.65 0 1.075.425.425.425.425 1.075v11h11q.65 0 1.075.425Q38 23.35 38 24q0 .65-.425 1.075-.425.425-1.075.425h-11v11q0 .65-.425 1.075Q24.65 38 24 38Z"/></svg>` ;
176
+ newSessionBtn . innerHTML = Icons . plus ;
176
177
this . $searchBtn = tag ( "button" , {
177
178
className : "action-button search-btn" ,
178
179
ariaLabel : "Search" ,
179
180
} ) ;
180
- this . $searchBtn . innerHTML = `<svg xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="lucide lucide- search-code"><path d="m13 13.5 2-2.5-2-2.5"/><path d="m21 21-4.3-4.3"/><path d="M9 8.5 7 11l2 2.5"/><circle cx="11" cy="11" r="8"/></svg>` ;
181
+ this . $searchBtn . innerHTML = Icons . search ;
181
182
this . $cdBtn = tag ( "button" , {
182
183
className : "action-button folder-icon" ,
183
184
ariaLabel : "Navigate to Folder" ,
184
185
} ) ;
185
- this . $cdBtn . innerHTML = `<svg xmlns="http://www.w3.org/2000/svg" width="16" height="16" fill="currentColor" class="bi bi-folder2-open" viewBox="0 0 16 16"><path d="M1 3.5A1.5 1.5 0 0 1 2.5 2h2.764c.958 0 1.76.56 2.311 1.184C7.985 3.648 8.48 4 9 4h4.5A1.5 1.5 0 0 1 15 5.5v.64c.57.265.94.876.856 1.546l-.64 5.124A2.5 2.5 0 0 1 12.733 15H3.266a2.5 2.5 0 0 1-2.481-2.19l-.64-5.124A1.5 1.5 0 0 1 1 6.14V3.5zM2 6h12v-.5a.5.5 0 0 0-.5-.5H9c-.964 0-1.71-.629-2.174-1.154C6.374 3.334 5.82 3 5.264 3H2.5a.5.5 0 0 0-.5.5V6zm-.367 1a.5.5 0 0 0-.496.562l.64 5.124A1.5 1.5 0 0 0 3.266 14h9.468a1.5 1.5 0 0 0 1.489-1.314l.64-5.124A.5.5 0 0 0 14.367 7H1.633z"/></svg>` ;
186
+ this . $cdBtn . innerHTML = Icons . folder ;
186
187
this . $minimizeBtn = tag ( "button" , {
187
188
className : "action-button minimize" ,
188
189
ariaLabel : "Minimize" ,
189
190
} ) ;
190
- this . $minimizeBtn . innerHTML = `<svg viewBox="0 0 48 48" xmlns="http://www.w3.org/2000/svg" height="1.5em" width="1.5em"><path fill="currentColor" d="M24 24.75q-.3 0-.55-.1-.25-.1-.5-.35l-9.9-9.9q-.45-.45-.45-1.05 0-.6.45-1.05.45-.45 1.05-.45.6 0 1.05.45L24 21.15l8.85-8.85q.45-.45 1.05-.45.6 0 1.05.45.45.45.45 1.05 0 .6-.45 1.05l-9.9 9.9q-.25.25-.5.35-.25.1-.55.1Zm0 12.65q-.3 0-.55-.1-.25-.1-.5-.35l-9.9-9.9q-.45-.45-.45-1.05 0-.6.45-1.05.45-.45 1.05-.45.6 0 1.05.45L24 33.8l8.85-8.85q.45-.45 1.05-.45.6 0 1.05.45.45.45.45 1.05 0 .6-.45 1.05l-9.9 9.9q-.25.25-.5.35-.25.1-.55.1Z"/></svg>` ;
191
+ this . $minimizeBtn . innerHTML = Icons . minimise ;
191
192
this . $closeTermBtn = tag ( "button" , {
192
193
className : "action-button close" ,
193
194
ariaLabel : "Close Terminal" ,
194
195
} ) ;
195
- this . $closeTermBtn . innerHTML = `<svg viewBox="0 0 48 48" xmlns="http://www.w3.org/2000/svg" height="1.5em" width="1.5em"><path fill="currentColor" d="M24 26.1 13.5 36.6q-.45.45-1.05.45-.6 0-1.05-.45-.45-.45-.45-1.05 0-.6.45-1.05L21.9 24 11.4 13.5q-.45-.45-.45-1.05 0-.6.45-1.05.45-.45 1.05-.45.6 0 1.05.45L24 21.9l10.5-10.5q.45-.45 1.05-.45.6 0 1.05.45.45.45.45 1.05 0 .6-.45 1.05L26.1 24l10.5 10.5q.45.45.45 1.05 0 .6-.45 1.05-.45.45-1.05.45-.6 0-1.05-.45Z"/></svg>` ;
196
+ this . $closeTermBtn . innerHTML = Icons . close ;
196
197
this . $searchInputContainer = tag ( "div" , {
197
198
className : "search-input-container" ,
198
199
} ) ;
199
200
this . $searchInputContainer . append (
200
201
tag ( "button" , {
201
202
className : "action-button find-previous" ,
202
203
ariaLabel : "Find Previous" ,
203
- innerHTML : `<svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><polyline points="15 18 9 12 15 6"></polyline></svg>` ,
204
+ innerHTML : Icons . findPrevious ,
204
205
onclick : this . _findPreviousMatchofSearch . bind ( this ) ,
205
206
} ) ,
206
207
tag ( "input" , {
@@ -214,7 +215,7 @@ export default class AcodeX {
214
215
tag ( "button" , {
215
216
className : "action-button find-next" ,
216
217
ariaLabel : "Find Next" ,
217
- innerHTML : `<svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><polyline points="9 18 15 12 9 6"></polyline></svg>` ,
218
+ innerHTML : Icons . findNext ,
218
219
onclick : this . _findNextMatchofSearch . bind ( this ) ,
219
220
} ) ,
220
221
) ;
@@ -244,7 +245,7 @@ export default class AcodeX {
244
245
// show terminal button
245
246
this . $showTermBtn = tag ( "button" , {
246
247
className : "show-terminal-btn" ,
247
- innerHTML : `<svg xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="lucide lucide- terminal"><polyline points="4 17 10 11 4 5"/><line x1="12" x2="20" y1="19" y2="19"/></svg>` ,
248
+ innerHTML : Icons . terminal ,
248
249
} ) ;
249
250
// append Terminal panel to app main
250
251
if ( app . get ( "main" ) ) {
@@ -427,6 +428,11 @@ export default class AcodeX {
427
428
428
429
// acodex terminal api
429
430
acode . define ( "acodex" , {
431
+ /**
432
+ * Executes a command in the terminal.
433
+ * @param {string } cmd - The command to execute.
434
+ * @param {boolean } [withEnter=true] - Whether to append a carriage return to the command.
435
+ */
430
436
execute : ( cmd , withEnter = true ) => {
431
437
try {
432
438
if ( ! this . isTerminalOpened ) return ;
@@ -435,17 +441,36 @@ export default class AcodeX {
435
441
throw Error ( error ) ;
436
442
}
437
443
} ,
444
+ /**
445
+ * Checks if the terminal is minimized.
446
+ * @returns {boolean } - True if the terminal is minimized, false otherwise.
447
+ */
438
448
isMinimized : ( ) => {
439
449
return this . isTerminalMinimized ;
440
450
} ,
451
+
452
+ /**
453
+ * Checks if the terminal is opened.
454
+ * @returns {boolean } - True if the terminal is opened, false otherwise.
455
+ */
441
456
isTerminalOpened : ( ) => {
442
457
return this . isTerminalOpened ;
443
458
} ,
459
+
460
+ /**
461
+ * Maximizes the terminal if it is opened and minimized.
462
+ */
444
463
maximiseTerminal : ( ) => {
445
464
if ( this . isTerminalOpened && this . isTerminalMinimized ) {
446
465
this . maxmise ( ) ;
447
466
}
448
467
} ,
468
+ /**
469
+ * Opens the terminal panel and returns an object to interact with the terminal.
470
+ * @param {number } [termContainerHeight=270] - The height of the terminal container.
471
+ * @param {number } [port=this.settings.port] - The port number to connect to.
472
+ * @returns {Promise<{onmessage: function, write: function}> } - An object with methods to interact with the terminal.
473
+ */
449
474
openTerminal : async (
450
475
termContainerHeight = 270 ,
451
476
port = this . settings . port ,
@@ -456,6 +481,10 @@ export default class AcodeX {
456
481
port ,
457
482
) ;
458
483
return {
484
+ /**
485
+ * Sets a callback function to handle incoming messages from the terminal.
486
+ * @param {function } cb - The callback function to handle incoming messages.
487
+ */
459
488
onmessage : ( cb ) => {
460
489
if ( socket ) {
461
490
socket . onmessage = ( event ) =>
@@ -466,17 +495,30 @@ export default class AcodeX {
466
495
) ;
467
496
}
468
497
} ,
498
+ /**
499
+ * Sends a command to the terminal session.
500
+ * @param {string } cmd - The command to send.
501
+ * @param {boolean } [withEnter=true] - Whether to append a carriage return to the command.
502
+ */
469
503
write : ( cmd , withEnter = true ) => {
470
504
const command = withEnter ? `${ cmd } \r` : cmd ;
471
505
socket . send ( command ) ;
472
506
} ,
473
507
} ;
474
508
}
475
509
} ,
510
+ /**
511
+ * Creates a new terminal session.
512
+ * @returns {Promise<{onmessage: function, write: function}> } - An object with methods to interact with the terminal session.
513
+ */
476
514
createSession : async ( ) => {
477
515
if ( this . isTerminalOpened ) {
478
516
const socket = await this . createSession ( ) ;
479
517
return {
518
+ /**
519
+ * Sets a callback function to handle incoming messages from the terminal.
520
+ * @param {function } cb - The callback function to handle incoming messages.
521
+ */
480
522
onmessage : ( cb ) => {
481
523
if ( socket ) {
482
524
socket . onmessage = ( event ) =>
@@ -487,17 +529,31 @@ export default class AcodeX {
487
529
) ;
488
530
}
489
531
} ,
532
+ /**
533
+ * Sends a command to the terminal session.
534
+ * @param {string } cmd - The command to send.
535
+ * @param {boolean } [withEnter=true] - Whether to append a carriage return to the command.
536
+ */
490
537
write : ( cmd , withEnter = true ) => {
491
538
const command = withEnter ? `${ cmd } \r` : cmd ;
492
539
socket . send ( command ) ;
493
540
} ,
494
541
} ;
495
542
}
496
543
} ,
544
+ /**
545
+ * Changes the current terminal session.
546
+ * @param {string } sessionName - The name of the session to switch to.
547
+ * @returns {Promise<{onmessage: function, write: function}> } - An object with methods to interact with the terminal.
548
+ */
497
549
changeSession : async ( sessionName ) => {
498
550
if ( this . isTerminalOpened ) {
499
551
const socket = await this . changeSession ( sessionName ) ;
500
552
return {
553
+ /**
554
+ * Sets a callback function to handle incoming messages from the terminal.
555
+ * @param {function } cb - The callback function to handle incoming messages.
556
+ */
501
557
onmessage : ( cb ) => {
502
558
if ( socket ) {
503
559
socket . onmessage = ( event ) =>
@@ -508,25 +564,50 @@ export default class AcodeX {
508
564
) ;
509
565
}
510
566
} ,
567
+ /**
568
+ * Sends a command to the terminal session.
569
+ * @param {string } cmd - The command to send.
570
+ * @param {boolean } [withEnter=true] - Whether to append a carriage return to the command.
571
+ */
511
572
write : ( cmd , withEnter = true ) => {
512
573
const command = withEnter ? `${ cmd } \r` : cmd ;
513
574
socket . send ( command ) ;
514
575
} ,
515
576
} ;
516
577
}
517
578
} ,
579
+ /**
580
+ * Closes the terminal if it is currently opened.
581
+ */
518
582
closeTerminal : ( ) => {
519
583
if ( this . isTerminalOpened ) {
520
584
this . closeTerminal ( ) ;
521
585
}
522
586
} ,
587
+
588
+ /**
589
+ * Converts an Acode URI to a terminal-readable path.
590
+ * @param {string } path - The Acode URI to convert.
591
+ * @returns {string } - The converted terminal-readable path.
592
+ */
523
593
convertAcodeUriToTermReadable : ( path ) => {
524
594
return helpers . convertPath ( path ) ;
525
595
} ,
596
+
597
+ /**
598
+ * Adds a new theme to the theme list.
599
+ * @param {string } themeNme - The name of the new theme.
600
+ * @param {object } colorSchema - The color schema of the new theme.
601
+ */
526
602
addTheme : ( themeNme , colorSchema ) => {
527
603
THEME_LIST . push ( themeNme ) ;
528
604
themes [ themeNme ] = colorSchema ;
529
605
} ,
606
+
607
+ /**
608
+ * Applies a specified theme to the terminal.
609
+ * @param {string } themeNme - The name of the theme to apply.
610
+ */
530
611
applyTheme : ( themeNme ) => {
531
612
this . settings . theme = themeNme ;
532
613
appSettings . update ( ) ;
@@ -542,7 +623,7 @@ export default class AcodeX {
542
623
className : "action-button gui-viewer" ,
543
624
ariaLabel : "Open GUI Viewer" ,
544
625
} ) ;
545
- viewerBtn . innerHTML = `<svg xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="lucide lucide-image-play"><path d="m11 16-5 5"/><path d="M11 21H5a2 2 0 0 1-2-2V5a2 2 0 0 1 2-2h14a2 2 0 0 1 2 2v6.5"/><path d="M15.765 22a.5.5 0 0 1-.765-.424V13.38a.5.5 0 0 1 .765-.424l5.878 3.674a1 1 0 0 1 0 1.696z"/><circle cx="9" cy="9" r="2"/></svg>` ;
626
+ viewerBtn . innerHTML = Icons . imagePlay ;
546
627
viewerBtn . onclick = this . openViewerPage . bind ( this ) ;
547
628
return viewerBtn ;
548
629
}
0 commit comments