Package jline.console

Examples of jline.console.ConsoleReader


        this.consoleInput = new ConsoleInputStream();
        this.session = processor.createSession(this.consoleInput, this.out, this.err);
        this.session.put("SCOPE", "shell:osgi:*");
        this.closeCallback = closeCallback;

        reader = new ConsoleReader(this.consoleInput,
                                   new PrintWriter(this.out),
                                   getClass().getResourceAsStream("keybinding.properties"),
                                   this.terminal);

        final File file = getHistoryFile();
View Full Code Here


    cConf.reloadConfiguration();
    Configuration hConf = HBaseConfiguration.create();

    Injector injector = Guice.createInjector(createModules(cConf, hConf));
    flowOperations = injector.getInstance(FlowOperations.class);
    consoleReader = new ConsoleReader();
  }
View Full Code Here

        this.consoleInput = new ConsoleInputStream();
        this.session = processor.createSession(this.consoleInput, this.out, this.err);
        this.session.put("SCOPE", "shell:osgi:*");
        this.closeCallback = closeCallback;

        reader = new ConsoleReader(this.consoleInput,
                                   new PrintWriter(this.out),
                                   getClass().getResourceAsStream("keybinding.properties"),
                                   this.terminal);

        final File file = getHistoryFile();
View Full Code Here

        this.consoleInput = new ConsoleInputStream();
        this.session = processor.createSession(this.consoleInput, this.out, this.err);
        this.session.put("SCOPE", "shell:osgi:*");
        this.closeCallback = closeCallback;

        reader = new ConsoleReader(null,
                                   this.consoleInput,
                                   this.out,
                                   this.terminal,
                                   encoding);

View Full Code Here

      {
         outputStream = System.out;
      }
      if (Boolean.getBoolean("forge.compatibility.IDE"))
      {
         this.reader = new ConsoleReader(inputStream, new OutputStreamWriter(outputStream), null, new IdeTerminal());
      }
      else if (OSUtils.isWindows())
      {
         this.reader = setupReaderForWindows(inputStream, outputStream);
      }
      else
         this.reader = new ConsoleReader(inputStream, new OutputStreamWriter(outputStream));
      this.reader.setHistoryEnabled(true);
      this.reader.setBellEnabled(false);
   }
View Full Code Here

      {
         final OutputStream ansiOut = AnsiConsole.wrapOutputStream(outputStream);

         TerminalFactory.configure(Type.WINDOWS);
         Terminal terminal = TerminalFactory.get();
         ConsoleReader consoleReader = new ConsoleReader(inputStream, new PrintWriter(
                             new OutputStreamWriter(ansiOut, System.getProperty(
                                      "jline.WindowsTerminal.output.encoding", System.getProperty("file.encoding")))),
                    null, terminal);
         return consoleReader;
      }
View Full Code Here

        this.consoleInput = new ConsoleInputStream();
        this.session = processor.createSession(this.consoleInput, this.out, this.err);
        this.session.put("SCOPE", "shell:osgi:*");
        this.closeCallback = closeCallback;

        reader = new ConsoleReader(this.consoleInput,
                                   new PrintWriter(this.out),
                                   getClass().getResourceAsStream("keybinding.properties"),
                                   this.terminal);

        final File file = getHistoryFile();
View Full Code Here

      {
         outputStream = System.out;
      }
      if (Boolean.getBoolean("forge.compatibility.IDE"))
      {
         this.reader = new ConsoleReader(inputStream, new OutputStreamWriter(outputStream), null, new IdeTerminal());
      }
      else if (OSUtils.isWindows())
      {
         this.reader = setupReaderForWindows(inputStream, outputStream);
      }
      else
         this.reader = new ConsoleReader(inputStream, new OutputStreamWriter(outputStream));
      this.reader.setHistoryEnabled(true);
      this.reader.setBellEnabled(false);
      for (TriggeredAction action : triggeredActions) {
         this.reader.addTriggeredAction(action.getTrigger(), action.getListener());
      }
View Full Code Here

      {
         final OutputStream ansiOut = AnsiConsole.wrapOutputStream(outputStream);

         TerminalFactory.configure(Type.WINDOWS);
         Terminal terminal = TerminalFactory.get();
         ConsoleReader consoleReader = new ConsoleReader(inputStream, new PrintWriter(
                  new OutputStreamWriter(ansiOut, System.getProperty(
                           "jline.WindowsTerminal.output.encoding", System.getProperty("file.encoding")))),
                  null, terminal);
         return consoleReader;
      }
View Full Code Here

    public static void main(String[] args) throws IOException, DeploymentException, InterruptedException {

        final ClientManager clientManager = new ClientManager();

        try {
            final ConsoleReader console = new ConsoleReader(
                    NAME,
                    new FileInputStream(FileDescriptor.in), System.out, null);

            console.addCompleter(new StringsCompleter("open", "close", "send", "ping", "exit", "quit", "help"));
            console.setPrompt(getPrompt());

            if (args.length > 0) {

                int i = 0;
                String arg;

                while (i < args.length && args[i].startsWith("--")) {
                    arg = args[i++];

                    if (arg.equals("--proxy")) {
                        if (i < args.length) {
                            final String proxyUrl = args[i++];
                            clientManager.getProperties().put(ClientManager.PROXY_URI, proxyUrl);
                        } else {
                            ClientCli.print(console, null, String.format("--proxy requires an argument (url)"), false);
                        }
                    }

                    if (arg.equals("--help")) {

                        String help = "\n"
                                + "\nUsage: cmd [--proxy proxyUrl] [ws uri]"
                                + "\n"
                                + "\nruntime commands:"
                                + "\n\topen uri : open a connection to the web socket uri"
                                + "\n\tclose : close a currently open web socket session"
                                + "\n\tsend message : send a text message"
                                + "\n\tsend : send a multiline text message teminated with a ."
                                + "\n\tping : send a ping message"
                                + "\n\tquit | exit : exit this tool"
                                + "\n\thelp : display this message";

                        ClientCli.print(console, null, help, false);
                        return;
                    }
                }

                if (i == (args.length - 1)) {
                    connectToURI(console, args[i], clientManager);
                    console.getHistory().add("open " + args[i]);
                    console.setPrompt(getPrompt());
                    i++;
                }

                if (i != args.length) {
                    ClientCli.print(console, null, String.format("Invalid argument count, usage cmd [--proxy proxyUrl] [ws uri]"), false);
                    return;
                }
            }

            String line;
            mainLoop:
            while ((line = console.readLine()) != null) {

                try {
                    // Get rid of extranious white space
                    line = line.trim();

                    if (line.length() == 0) {
                        // Do nothing
                    } else if (line.startsWith("open ")) {
                        final String uri = line.substring(5).trim();
                        connectToURI(console, uri, clientManager);
                    } else if (line.startsWith("close")) {
                        if (session != null) {
                            session.close();
                        }
                        session = null;

                        ClientCli.print(console, null, String.format("Session closed"), false);
                    } else if (line.startsWith("send ")) {
                        final String message = line.substring(5);

                        if (session != null) {
                            session.getBasicRemote().sendText(message);
                        }
                        // Multiline send, complets on the full stop
                    } else if (line.startsWith("send")) {

                        ClientCli.print(console, null, String.format("End multiline message with . on own line"), false);

                        String temporaryPrompt = "send...> ";
                        console.setPrompt(temporaryPrompt);

                        StringBuilder sb = new StringBuilder();
                        String subLine;
                        while (!".".equals((subLine = console.readLine()))) {
                            sb.append(subLine);
                            sb.append('\n');
                        }

                        // Send message
                        if (session != null) {
                            session.getBasicRemote().sendText(sb.toString());
                        }

                    } else if (line.startsWith("ping")) {
                        if (session != null) {
                            session.getBasicRemote().sendPing(ByteBuffer.wrap("tyrus-client-ping".getBytes("UTF-8")));
                        }
                    } else if (line.startsWith("exit") || line.startsWith("quit")) {
                        break mainLoop;
                    } else if (line.startsWith("help")) {

                        String help = ""
                                + "\n\topen uri : open a connection to the web socket uri"
                                + "\n\tclose : close a currently open web socket session"
                                + "\n\tsend message : send a text message"
                                + "\n\tsend : send a multiline text message teminated with a ."
                                + "\n\tping : send a ping message"
                                + "\n\tquit | exit : exit this tool"
                                + "\n\thelp : display this message"
                                + "\n\t";

                        ClientCli.print(console, null, help, false);

                    } else {
                        ClientCli.print(console, null, "Unable to parse given command.", false);
                    }

                } catch (IOException e) {
                    ClientCli.print(console, null, String.format("IOException: %s", e.getMessage()), false);
                }

                // Restore prompt
                console.setPrompt(getPrompt());
            }

        } finally {
            try {
                TerminalFactory.get().restore();
View Full Code Here

TOP

Related Classes of jline.console.ConsoleReader

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.