@@ -21,10 +21,12 @@ public class CmdLineUI {
2121 public static final String CREATE_ASAP_CHANNEL = "newchannel" ;
2222 public static final String CREATE_ASAP_MESSAGE = "newmessage" ;
2323 public static final String RESET_ASAP_STORAGES = "resetstorage" ;
24- public static final String SET_SEND_RECEIVED_MESSAGES = "sendReceived " ;
24+ public static final String SET_SEND_RECEIVED_MESSAGES = "setSendReceived " ;
2525 public static final String PRINT_CHANNEL_INFORMATION = "printChannelInfo" ;
2626 public static final String PRINT_STORAGE_INFORMATION = "printStorageInfo" ;
2727 public static final String PRINT_ALL_INFORMATION = "printAll" ;
28+ public static final String SLEEP = "sleep" ;
29+ public static final String SHOW_LOG = "showlog" ;
2830
2931 private final PrintStream consoleOutput ;
3032 private final BufferedReader userInput ;
@@ -112,6 +114,12 @@ public void printUsage() {
112114 b .append (PRINT_CHANNEL_INFORMATION );
113115 b .append (".. print general information about a channel" );
114116 b .append ("\n " );
117+ b .append (SLEEP );
118+ b .append (".. sleep some milliseconds - helps writing batch programs" );
119+ b .append ("\n " );
120+ b .append (SHOW_LOG );
121+ b .append (".. print log of entered commands of this session" );
122+ b .append ("\n " );
115123 b .append (EXIT );
116124 b .append (".. exit" );
117125
@@ -194,18 +202,31 @@ public void printUsage(String cmdString, String comment) {
194202 case PRINT_ALL_INFORMATION :
195203 out .println (PRINT_ALL_INFORMATION );
196204 break ;
205+ case SLEEP :
206+ out .println (SLEEP + " milliseconds" );
207+ out .println ("example: " + SLEEP + " sleep 1000" );
208+ out .println ("process sleeps a second == 1000 ms" );
209+ break ;
210+ case SHOW_LOG :
211+ out .println (SHOW_LOG );
212+ break ;
197213 default :
198214 out .println ("unknown command: " + cmdString );
199215 }
200216 }
201217
218+ private List <String > cmds = new ArrayList <>();
219+
202220 public void runCommandLoop () {
203221 boolean again = true ;
222+
204223 while (again ) {
224+ boolean rememberCommand = true ;
225+ String cmdLineString = null ;
205226
206227 try {
207228 // read user input
208- String cmdLineString = userInput .readLine ();
229+ cmdLineString = userInput .readLine ();
209230
210231 // finish that loop if less than nothing came in
211232 if (cmdLineString == null ) break ;
@@ -252,6 +273,10 @@ public void runCommandLoop() {
252273 this .doPrintChannelInformation (parameterString ); break ;
253274 case PRINT_STORAGE_INFORMATION :
254275 this .doPrintStorageInformation (parameterString ); break ;
276+ case SLEEP :
277+ this .doSleep (parameterString ); break ;
278+ case SHOW_LOG :
279+ this .doShowLog (); rememberCommand = false ; break ;
255280 case PRINT_ALL_INFORMATION :
256281 this .doPrintAllInformation (); break ;
257282 case "q" : // convenience
@@ -262,12 +287,17 @@ public void runCommandLoop() {
262287 default : this .consoleOutput .println ("unknown command:" +
263288 cmdLineString );
264289 this .printUsage ();
290+ rememberCommand = false ;
265291 break ;
266292 }
267293 } catch (IOException ex ) {
268294 this .consoleOutput .println ("cannot read from input stream" );
269295 System .exit (0 );
270296 }
297+
298+ if (rememberCommand ) {
299+ this .cmds .add (cmdLineString );
300+ }
271301 }
272302 }
273303
@@ -615,6 +645,36 @@ public void doPrintStorageInformation(String parameterString) {
615645 }
616646 }
617647
648+ public void doSleep (String parameterString ) {
649+ StringTokenizer st = new StringTokenizer (parameterString );
650+
651+ try {
652+ Thread .sleep (Long .parseLong (parameterString ));
653+ }
654+ catch (InterruptedException e ) {
655+ this .consoleOutput .println ("sleep interrupted" );
656+ }
657+ catch (RuntimeException e ) {
658+ this .printUsage (PRINT_STORAGE_INFORMATION , e .getLocalizedMessage ());
659+ }
660+ }
661+
662+ private void doShowLog () {
663+ if (this .cmds .size () < 1 ) return ;
664+
665+ boolean first = true ;
666+ for (String c : this .cmds ) {
667+ if (!first ) {
668+ this .consoleOutput .println ("\\ n\" + " );
669+ } else {
670+ first = false ;
671+ }
672+ this .consoleOutput .print ("\" " );
673+ this .consoleOutput .print (c );
674+ }
675+ this .consoleOutput .println ("\" " );
676+ }
677+
618678 public void doPrintChannelInformation (String parameterString ) {
619679 // out.println("example: " + PRINT_CHANNEL_INFORMATION + " Alice chat sn2://abChat");
620680 StringTokenizer st = new StringTokenizer (parameterString );
0 commit comments