1010import org .jline .reader .*;
1111import org .jline .terminal .Terminal ;
1212import org .jline .terminal .TerminalBuilder ;
13+ import org .jline .utils .InfoCmp ;
1314import org .jline .utils .InfoCmp .Capability ;
1415
15- import java .nio .file .Paths ;
16-
1716import java .util .List ;
1817
1918public class NodeLinkHelper {
@@ -28,7 +27,11 @@ public class NodeLinkHelper {
2827 private static final String YELLOW = "\u001B [33m" ;
2928
3029
31- private static String PRODUCT = "Post Production" ;
30+ private final String PRODUCT = "Post Production" ;
31+
32+ public synchronized String getPRODUCT () {
33+ return this .PRODUCT ;
34+ }
3235
3336 private Terminal terminal ;
3437
@@ -69,8 +72,6 @@ private void initTerminal() {
6972
7073 CommandDispatcher dispatcher = new CommandDispatcher (registry );
7174
72- CommandLogics logics = new CommandLogics (dispatcher , terminal );
73-
7475 LineReader reader = LineReaderBuilder .builder ()
7576 .terminal (terminal )
7677 .completer ((lineReader , parsedLine , candidates ) -> {
@@ -80,43 +81,62 @@ private void initTerminal() {
8081 candidates .add (new Candidate (s ));
8182 }
8283 })
83- .variable (LineReader .HISTORY_FILE , Paths .get ("bin/history.txt" ))
8484 .option (LineReader .Option .AUTO_FRESH_LINE , true )
8585 .build ();
8686
87+ CommandLogics logics = new CommandLogics (dispatcher , reader , terminal );
88+
8789 fullClearAndRefresh (terminal );
8890
8991 while (true ) {
90- String prompt = GREEN + "Server" + RESET + "@" + YELLOW + "NodeLink" + RESET + "-(" + RED + STATUS + RESET + ")~" + WHITE + "$ " + RESET ;
92+ String prompt = GREEN + "Server" + RESET + "@" + YELLOW + "NodeLink" + RESET + "-(" + RED + NodeLink . getHelper (). getStatus () + RESET + ")~" + WHITE + "$ " + RESET ;
9193
9294 try {
9395 String command = reader .readLine (prompt );
9496
95- if (command == null || command .equalsIgnoreCase ( "exit" ) || command . equalsIgnoreCase ( "quit" )) {
96- System . exit ( 1 ) ;
97+ if (command == null || command .trim (). isEmpty ( )) {
98+ continue ;
9799 }
98100
99- if (command .equalsIgnoreCase ("clear" )) {
100- fullClearAndRefresh (terminal );
101- continue ;
101+ try {
102+ boolean handled = dispatcher .dispatch (command );
103+
104+ if (!handled ) {
105+ terminal .writer ().println ("Commande inconnue : " + command );
106+ terminal .writer ().println ("\n " );
107+ }
108+ } catch (Exception e ) {
109+ terminal .writer ().println ("Erreur : La commande '" + command + "' n'est pas reconnue." );
110+ terminal .writer ().println ("\n " );
102111 }
103112
104- boolean handled = dispatcher .dispatch (command );
105- if (!handled ) {
106- terminal .writer ().println ("Commande inconnue : " + command );
113+ terminal .writer ().flush ();
114+
115+ if (command .equalsIgnoreCase ("exit" ) || command .equalsIgnoreCase ("quit" )) {
116+ terminal .writer ().print ("\u001B [r" );
117+ terminal .writer ().print ("\u001B [2J\u001B [3J" );
118+ terminal .puts (InfoCmp .Capability .cursor_address , 0 , 0 );
107119 terminal .flush ();
120+ System .exit (0 );
108121 }
109122
110123 } catch (UserInterruptException | EndOfFileException e ) {
111- System .exit (1 );
124+ terminal .writer ().print ("\u001B [r" );
125+ terminal .writer ().print ("\u001B [2J\u001B [3J" );
126+ terminal .puts (InfoCmp .Capability .cursor_address , 0 , 0 );
127+ terminal .flush ();
128+ System .exit (0 );
129+ } catch (Exception e ) {
130+ terminal .writer ().println ("Une erreur système est survenue : " + e .getMessage ());
131+ terminal .writer ().flush ();
112132 }
113133 }
114134 } catch (Exception e ) {
115135 e .printStackTrace ();
116136 }
117137 }
118138
119- private void fullClearAndRefresh (Terminal terminal ) {
139+ public void fullClearAndRefresh (Terminal terminal ) {
120140 terminal .writer ().print ("\u001B [r" );
121141 terminal .writer ().print ("\u001B [2J\u001B [3J" );
122142 terminal .puts (Capability .cursor_address , 0 , 0 );
@@ -167,6 +187,10 @@ private int getPlainTextLength(String s) {
167187 return s .replaceAll ("\u001B \\ [[;\\ d]*m" , "" ).length ();
168188 }
169189
190+ public void displayHelpPage () {
191+
192+ }
193+
170194 private String LOGO () {
171195 return """
172196 ░ \s
0 commit comments