@@ -4,6 +4,7 @@ import * as helpers from "./utils/helpers.js";
44import { themes } from "./utils/themes.js" ;
55import AIResponseHandler from "./services/AiService.js" ;
66import SelectionCore from "./core/selectionCore.js" ;
7+ import Icons from "./utils/icons" ;
78import {
89 ALLOW_TRANSPRANCY ,
910 CURSOR_BLINK ,
@@ -172,35 +173,35 @@ export default class AcodeX {
172173 className : "action-button new-session" ,
173174 ariaLabel : "New Session" ,
174175 } ) ;
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 ;
176177 this . $searchBtn = tag ( "button" , {
177178 className : "action-button search-btn" ,
178179 ariaLabel : "Search" ,
179180 } ) ;
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 ;
181182 this . $cdBtn = tag ( "button" , {
182183 className : "action-button folder-icon" ,
183184 ariaLabel : "Navigate to Folder" ,
184185 } ) ;
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 ;
186187 this . $minimizeBtn = tag ( "button" , {
187188 className : "action-button minimize" ,
188189 ariaLabel : "Minimize" ,
189190 } ) ;
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 ;
191192 this . $closeTermBtn = tag ( "button" , {
192193 className : "action-button close" ,
193194 ariaLabel : "Close Terminal" ,
194195 } ) ;
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 ;
196197 this . $searchInputContainer = tag ( "div" , {
197198 className : "search-input-container" ,
198199 } ) ;
199200 this . $searchInputContainer . append (
200201 tag ( "button" , {
201202 className : "action-button find-previous" ,
202203 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 ,
204205 onclick : this . _findPreviousMatchofSearch . bind ( this ) ,
205206 } ) ,
206207 tag ( "input" , {
@@ -214,7 +215,7 @@ export default class AcodeX {
214215 tag ( "button" , {
215216 className : "action-button find-next" ,
216217 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 ,
218219 onclick : this . _findNextMatchofSearch . bind ( this ) ,
219220 } ) ,
220221 ) ;
@@ -244,7 +245,7 @@ export default class AcodeX {
244245 // show terminal button
245246 this . $showTermBtn = tag ( "button" , {
246247 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 ,
248249 } ) ;
249250 // append Terminal panel to app main
250251 if ( app . get ( "main" ) ) {
@@ -427,6 +428,11 @@ export default class AcodeX {
427428
428429 // acodex terminal api
429430 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+ */
430436 execute : ( cmd , withEnter = true ) => {
431437 try {
432438 if ( ! this . isTerminalOpened ) return ;
@@ -435,17 +441,36 @@ export default class AcodeX {
435441 throw Error ( error ) ;
436442 }
437443 } ,
444+ /**
445+ * Checks if the terminal is minimized.
446+ * @returns {boolean } - True if the terminal is minimized, false otherwise.
447+ */
438448 isMinimized : ( ) => {
439449 return this . isTerminalMinimized ;
440450 } ,
451+
452+ /**
453+ * Checks if the terminal is opened.
454+ * @returns {boolean } - True if the terminal is opened, false otherwise.
455+ */
441456 isTerminalOpened : ( ) => {
442457 return this . isTerminalOpened ;
443458 } ,
459+
460+ /**
461+ * Maximizes the terminal if it is opened and minimized.
462+ */
444463 maximiseTerminal : ( ) => {
445464 if ( this . isTerminalOpened && this . isTerminalMinimized ) {
446465 this . maxmise ( ) ;
447466 }
448467 } ,
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+ */
449474 openTerminal : async (
450475 termContainerHeight = 270 ,
451476 port = this . settings . port ,
@@ -456,6 +481,10 @@ export default class AcodeX {
456481 port ,
457482 ) ;
458483 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+ */
459488 onmessage : ( cb ) => {
460489 if ( socket ) {
461490 socket . onmessage = ( event ) =>
@@ -466,17 +495,30 @@ export default class AcodeX {
466495 ) ;
467496 }
468497 } ,
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+ */
469503 write : ( cmd , withEnter = true ) => {
470504 const command = withEnter ? `${ cmd } \r` : cmd ;
471505 socket . send ( command ) ;
472506 } ,
473507 } ;
474508 }
475509 } ,
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+ */
476514 createSession : async ( ) => {
477515 if ( this . isTerminalOpened ) {
478516 const socket = await this . createSession ( ) ;
479517 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+ */
480522 onmessage : ( cb ) => {
481523 if ( socket ) {
482524 socket . onmessage = ( event ) =>
@@ -487,17 +529,31 @@ export default class AcodeX {
487529 ) ;
488530 }
489531 } ,
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+ */
490537 write : ( cmd , withEnter = true ) => {
491538 const command = withEnter ? `${ cmd } \r` : cmd ;
492539 socket . send ( command ) ;
493540 } ,
494541 } ;
495542 }
496543 } ,
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+ */
497549 changeSession : async ( sessionName ) => {
498550 if ( this . isTerminalOpened ) {
499551 const socket = await this . changeSession ( sessionName ) ;
500552 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+ */
501557 onmessage : ( cb ) => {
502558 if ( socket ) {
503559 socket . onmessage = ( event ) =>
@@ -508,25 +564,50 @@ export default class AcodeX {
508564 ) ;
509565 }
510566 } ,
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+ */
511572 write : ( cmd , withEnter = true ) => {
512573 const command = withEnter ? `${ cmd } \r` : cmd ;
513574 socket . send ( command ) ;
514575 } ,
515576 } ;
516577 }
517578 } ,
579+ /**
580+ * Closes the terminal if it is currently opened.
581+ */
518582 closeTerminal : ( ) => {
519583 if ( this . isTerminalOpened ) {
520584 this . closeTerminal ( ) ;
521585 }
522586 } ,
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+ */
523593 convertAcodeUriToTermReadable : ( path ) => {
524594 return helpers . convertPath ( path ) ;
525595 } ,
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+ */
526602 addTheme : ( themeNme , colorSchema ) => {
527603 THEME_LIST . push ( themeNme ) ;
528604 themes [ themeNme ] = colorSchema ;
529605 } ,
606+
607+ /**
608+ * Applies a specified theme to the terminal.
609+ * @param {string } themeNme - The name of the theme to apply.
610+ */
530611 applyTheme : ( themeNme ) => {
531612 this . settings . theme = themeNme ;
532613 appSettings . update ( ) ;
@@ -542,7 +623,7 @@ export default class AcodeX {
542623 className : "action-button gui-viewer" ,
543624 ariaLabel : "Open GUI Viewer" ,
544625 } ) ;
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 ;
546627 viewerBtn . onclick = this . openViewerPage . bind ( this ) ;
547628 return viewerBtn ;
548629 }
0 commit comments