11package io .nodelink .server ;
22
3+ import io .nodelink .server .command .CommandDispatcher ;
4+ import io .nodelink .server .command .CommandLogics ;
5+ import io .nodelink .server .command .CommandRegistry ;
6+ import io .nodelink .server .command .TabCompleter ;
7+ import io .nodelink .server .enums .CommandsEnum ;
38import io .nodelink .server .update .Version ;
4- import org . jline . reader . EndOfFileException ;
5- import org .jline .reader .UserInterruptException ;
9+
10+ import org .jline .reader .* ;
611import org .jline .terminal .Terminal ;
712import org .jline .terminal .TerminalBuilder ;
8- import org .jline .reader .LineReader ;
9- import org .jline .reader .LineReaderBuilder ;
1013import org .jline .utils .InfoCmp .Capability ;
14+
1115import java .nio .file .Paths ;
1216
17+ import java .util .List ;
18+
1319public class NodeLinkHelper {
1420
1521 private static final NodeLinkHelper INSTANCE = new NodeLinkHelper ();
@@ -21,9 +27,24 @@ public class NodeLinkHelper {
2127 private static final String WHITE = "\u001B [37m" ;
2228 private static final String YELLOW = "\u001B [33m" ;
2329
24- private static String STATUS = "Main" ;
30+
2531 private static String PRODUCT = "Post Production" ;
2632
33+ private Terminal terminal ;
34+
35+ private String STATUS = "OFFLINE" ;
36+
37+ public synchronized void updateStatus (String newStatus ) {
38+ this .STATUS = (newStatus == null ) ? "" : newStatus ;
39+ if (this .terminal != null ) {
40+ fullClearAndRefresh (this .terminal );
41+ }
42+ }
43+
44+ public synchronized String getStatus () {
45+ return this .STATUS ;
46+ }
47+
2748 private static final int RESERVED_ROWS = 36 ;
2849
2950 public static NodeLinkHelper getHelper () {
@@ -36,13 +57,29 @@ public void INITIALIZE() {
3657
3758 private void initTerminal () {
3859 try {
39- Terminal terminal = TerminalBuilder .builder ()
60+ terminal = TerminalBuilder .builder ()
4061 .name ("NodeLink Server" )
4162 .system (true )
4263 .build ();
4364
65+ CommandRegistry registry = new CommandRegistry ();
66+ registry .registerParentEnum (CommandsEnum .class );
67+
68+ TabCompleter appCompleter = new TabCompleter (registry );
69+
70+ CommandDispatcher dispatcher = new CommandDispatcher (registry );
71+
72+ CommandLogics logics = new CommandLogics (dispatcher , terminal );
73+
4474 LineReader reader = LineReaderBuilder .builder ()
4575 .terminal (terminal )
76+ .completer ((lineReader , parsedLine , candidates ) -> {
77+ String buffer = parsedLine .line ();
78+ List <String > suggestions = appCompleter .complete (buffer );
79+ for (String s : suggestions ) {
80+ candidates .add (new Candidate (s ));
81+ }
82+ })
4683 .variable (LineReader .HISTORY_FILE , Paths .get ("bin/history.txt" ))
4784 .option (LineReader .Option .AUTO_FRESH_LINE , true )
4885 .build ();
@@ -55,26 +92,28 @@ private void initTerminal() {
5592 try {
5693 String command = reader .readLine (prompt );
5794
58- if (command == null || command .equalsIgnoreCase ("exit" )) System .exit (1 );
95+ if (command == null || command .equalsIgnoreCase ("exit" ) || command .equalsIgnoreCase ("quit" )) {
96+ System .exit (1 );
97+ }
5998
6099 if (command .equalsIgnoreCase ("clear" )) {
61100 fullClearAndRefresh (terminal );
62101 continue ;
63102 }
64103
65- if ( command . equalsIgnoreCase ( "wow" )) {
66- STATUS = "Wow Mode" ;
67- fullClearAndRefresh ( terminal );
68- continue ;
104+ boolean handled = dispatcher . dispatch ( command );
105+ if (! handled ) {
106+ terminal . writer (). println ( "Commande inconnue : " + command );
107+ terminal . flush () ;
69108 }
70109
71- terminal .writer ().println ("Exécution de : " + command );
72-
73110 } catch (UserInterruptException | EndOfFileException e ) {
74- break ;
111+ System . exit ( 1 ) ;
75112 }
76113 }
77- } catch (Exception e ) {}
114+ } catch (Exception e ) {
115+ e .printStackTrace ();
116+ }
78117 }
79118
80119 private void fullClearAndRefresh (Terminal terminal ) {
@@ -164,12 +203,12 @@ private String LOGO() {
164203
165204 private String HEADER () {
166205 return """
167- __ __ __ ____ __ ______ ____ __ __ ______ \s
168- /\\ \\ /\\ \\ /\\ \\ /\\ _`\\ /\\ \\ /\\ __ _\\ /\\ _` \\ /\\ \\ / \\ \\ /\\ __ _\\ \s
169- \\ \\ `\\ \\ \\ \\ \\ \\ \\ \\ \\ / \\ _\\ \\ \\ \\ \\ /_/ \\ \\ / \\ \\ \\ L \\ _ \\ \\ \\ ` \\ \\ \\ \\ /_/ \\ \\ / \s
170- \\ \\ , ` \\ \\ \\ \\ __ _______ \\ \\ \\ /_/_ \\ \\ \\ __ \\ \\ \\ \\ \\ _ \\ L \\ \\ , ` \\ \\ \\ \\ \s
171- \\ \\ \\ `\\ \\ \\ \\ \\ L\\ \\ /\\ ______\\ \\ \\ \\ L\\ \\ \\ \\ \\ L\\ \\ \\ _ \\ \\ __ \\ \\ \\ L \\ \\ \\ \\ \\ ` \\ \\ \\ \\ \\ \s
172- \\ \\ _\\ \\ _\\ \\ \\ ____/ \\ /______/ \\ \\ ____/ \\ \\ ____/ / \\ _____ \\ \\ \\ ____ / \\ \\ _ \\ \\ _ \\ \\ \\ _\\
173- \\ /_/\\ /_/ \\ /___/ \\ /___ / \\ /___/ \\ /_____/ \\ /___ / \\ /_/ \\ /_/ \\ /_/""" ;
206+ __ __ __ ____ ____ ____ __ __ ____ ____ \s
207+ /\\ \\ /\\ \\ /\\ \\ /\\ _`\\ /\\ _` \\ /\\ _` \\ /\\ \\ / \\ \\ /\\ _` \\ /\\ _` \\ \s
208+ \\ \\ `\\ \\ \\ \\ \\ \\ \\ \\ , \\ L \\ _\\ \\ \\ \\ L \\ _ \\ \\ \\ \\ L \\ \\ \\ \\ \\ \\ \\ \\ \\ \\ L \\ _ \\ \\ \\ \\ L \\ \\ \s
209+ \\ \\ , ` \\ \\ \\ \\ __ _______ \\ /_ \\ __ \\ \\ \\ _ \\ L \\ \\ , / \\ \\ \\ \\ \\ \\ \\ _ \\ L \\ \\ , / \s
210+ \\ \\ \\ `\\ \\ \\ \\ \\ L\\ \\ /\\ ______\\ / \\ \\ L\\ \\ \\ \\ \\ L\\ \\ \\ \\ \\ \\ \\ \\ \\ \\ _/ \\ \\ \\ \\ L \\ \\ \\ \\ \\ \\ \\ \s
211+ \\ \\ _\\ \\ _\\ \\ \\ ____/ \\ /______/ \\ ` \\ ____\\ \\ \\ ____/ \\ \\ _ \\ \\ _ \\ \\ ` \\ ___ / \\ \\ ____/ \\ \\ _ \\ \\ _\\
212+ \\ /_/\\ /_/ \\ /___/ \\ /_____ / \\ /___/ \\ /_/ \\ / / ` \\ /__ / \\ /___/ \\ /_/ \\ / /""" ;
174213 }
175214}
0 commit comments