Launches the console mode, which reads and executes user input.
()
| 170 | * Launches the console mode, which reads and executes user input. |
| 171 | */ |
| 172 | private void console() { |
| 173 | Util.println(header() + NL + TRY_MORE_X); |
| 174 | verbose = true; |
| 175 | |
| 176 | // create console reader |
| 177 | try(ConsoleReader cr = ConsoleReader.get()) { |
| 178 | // loop until console is set to false (may happen in server mode) |
| 179 | while(console) { |
| 180 | // get next line |
| 181 | final String in = cr.readLine(PROMPT); |
| 182 | // end of input: break loop |
| 183 | if(in == null) break; |
| 184 | // skip empty lines |
| 185 | if(in.isEmpty()) continue; |
| 186 | |
| 187 | try { |
| 188 | if(!execute(CommandParser.get(in, context).pwReader(cr))) { |
| 189 | // show goodbye message if method returns false |
| 190 | Util.println(BYE[new Random().nextInt(4)]); |
| 191 | break; |
| 192 | } |
| 193 | } catch(final IOException ex) { |
| 194 | // output error messages |
| 195 | Util.errln(ex); |
| 196 | } |
| 197 | } |
| 198 | } |
| 199 | } |
| 200 | |
| 201 | /** |
| 202 | * Quits the console mode. |