Examples of Console


Examples of org.apache.qpid.qmf2.console.Console

                        tx.sendResponse(HTTP_OK, "application/json", connection.toString());
                    }
                    else
                    { // In this block we are dealing with resources associated with a specified connectionName.
                      // path describes the resources specifically related to "/qpid/connection/<connectionName>"
                        Console console = connection.getConsole();

                        if (path.startsWith("console/objects/"))
                        { // Get information about specified objects.
                            path = path.substring(16);
                            sendGetObjectsResponse(tx, console, path);
                        }
                        else if (path.startsWith("console/objects") && path.length() == 15)
                        {  // If objects is unspecified treat as a synonym for classes.
                            tx.sendResponse(HTTP_OK, "application/json", JSON.fromObject(console.getClasses()));
                        }
                        else if (path.startsWith("console/address/"))
                        { // Get the Console AMQP Address
                            tx.sendResponse(HTTP_OK, "application/json", JSON.fromObject(console.getAddress()));
                        }
                        else if (path.startsWith("console/address") && path.length() == 15)
                        { // Get the Console AMQP Address
                            tx.sendResponse(HTTP_OK, "application/json", JSON.fromObject(console.getAddress()));
                        }
                        else if (path.startsWith("console/workItemCount/"))
                        { // Returns the count of pending WorkItems that can be retrieved.
                            tx.sendResponse(HTTP_OK, "text/plain", "" + console.getWorkitemCount());
                        }
                        else if (path.startsWith("console/workItemCount") && path.length() == 21)
                        { // Returns the count of pending WorkItems that can be retrieved.
                            tx.sendResponse(HTTP_OK, "text/plain", "" + console.getWorkitemCount());
                        }
                        else if (path.startsWith("console/nextWorkItem/"))
                        { // Obtains the next pending work item, or null if none available.
                            tx.sendResponse(HTTP_OK, "application/json", JSON.fromObject(console.getNextWorkitem()));
                        }
                        else if (path.startsWith("console/nextWorkItem") && path.length() == 20)
                        { // Obtains the next pending work item, or null if none available.
                            tx.sendResponse(HTTP_OK, "application/json", JSON.fromObject(console.getNextWorkitem()));
                        }
                        else if (path.startsWith("console/agents") && path.length() == 14)
                        { // Get information about all available Agents.
                            tx.sendResponse(HTTP_OK, "application/json", JSON.fromObject(console.getAgents()));
                        }
                        else if (path.startsWith("console/agent/"))
                        { // Get information about a specified Agent.
                            Agent agent = console.getAgent(path.substring(14));
                            if (agent == null)
                            {
                                tx.sendResponse(HTTP_NOT_FOUND, "text/plain", "404 Not Found.");
                            }
                            else
                            {
                                tx.sendResponse(HTTP_OK, "application/json", JSON.fromObject(agent));
                            }
                        }
                        else if (path.startsWith("console/agent") && path.length() == 13)
                        { // If agent is unspecified treat as a synonym for agents.
                            tx.sendResponse(HTTP_OK, "application/json", JSON.fromObject(console.getAgents()));
                        }
                        else if (path.startsWith("console/classes/"))
                        { // Get information about the classes for a specified Agent
                            path = path.substring(16); // Get Agent name

                            // TODO handle getClasses() for specified Agent
                            tx.sendResponse(HTTP_NOT_IMPLEMENTED, "text/plain", "501 getClasses() for specified Agent not yet implemented.");
                        }
                        else if (path.startsWith("console/classes") && path.length() == 15)
                        { // Get information about all the classes for all Agents
                            tx.sendResponse(HTTP_OK, "application/json", JSON.fromObject(console.getClasses()));
                        }
                        else if (path.startsWith("console/packages/"))
                        { // Get information about the packages for a specified Agent
                            path = path.substring(17); // Get Agent name

                            // TODO handle getPackages() for specified Agent.
                            tx.sendResponse(HTTP_NOT_IMPLEMENTED, "text/plain", "501 getPackages() for specified Agent not yet implemented.");
                        }
                        else if (path.startsWith("object/"))
                        {
                            /**
                             * This is the REST implementation of getObjects(oid) it is also the equivalent of
                             * the QmfConsoleData refresh() method where an object can update its state.
                             * N.B. that the ManagementAgent on the broker appears not to set the timestamp properties
                             * in the response to this call, which means that they get set to current time in the
                             * QmfConsoleData, this is OK for _update_ts but not for _create_ts and _delete_ts
                             * users of this call should be aware of that in their own code.
                             */
                            path = path.substring(7);

                            // The ObjectId has been passed in the URI, create a real ObjectId
                            ObjectId oid = new ObjectId(path);

                            List<QmfConsoleData> objects = console.getObjects(oid);
                            if (objects.size() == 0)
                            {
                                tx.sendResponse(HTTP_NOT_FOUND, "text/plain", "404 Not Found.");
                            }
                            else
                            {
                                // Not that in a departure from the QMF2 API this returns the QmfConsoleData object
                                // rather than a list of size one. Perhaps the APIs should be completely consistent
                                // but this response seems more convenient.
                                tx.sendResponse(HTTP_OK, "application/json", JSON.fromObject(objects.get(0)));
                            }
                        }
                        else if (path.startsWith("console/packages") && path.length() == 16)
                        { // Get information about all the packages for all Agents
                            tx.sendResponse(HTTP_OK, "application/json", JSON.fromObject(console.getPackages()));
                        }
                        else
                        {
                            tx.sendResponse(HTTP_NOT_FOUND, "text/plain", "404 Not Found.");
                        }
View Full Code Here

Examples of org.apache.qpid.qmf2.console.Console

                {
                    tx.sendResponse(HTTP_INTERNAL_ERROR, "text/plain", "500 Broker Disconnected.");
                }
                else
                { // If we get this far we should have found a Qpid Connection so retrieve the QMF2 Console Object.
                    Console console = connection.getConsole();

                    if (path.startsWith("object/"))
                    {
                        path = path.substring(7);

                        // The ObjectId has been passed in the URI create an ObjectId and retrieve the Agent Name.
                        ObjectId oid = new ObjectId(path);
                        String agentName = oid.getAgentName();

                        // The qpidd ManagementAgent doesn't populate AgentName, if it's empty assume it's the broker.
                        agentName = agentName.equals("") ? "broker" : agentName;

                        Agent agent = console.getAgent(agentName); // Find the Agent we got the QmfData from.
                        if (agent == null)
                        {
                            _log.info("QpidServer.doPost path: {} Agent: {} not found.", tx.getRequestURI(), agentName);
                            tx.sendResponse(HTTP_NOT_FOUND, "text/plain", "404 Not Found.");
                        }
View Full Code Here

Examples of org.crsh.console.Console

      final ConsoleReader reader,
      PrintStream out,
      String lineSeparator) {

    //
    this.console = new Console(shell, this);
    this.writer = out;
    this.useAlternate = false;
    this.terminal = reader.getTerminal();
    this.reader = reader;
    this.lineSeparator = lineSeparator;
View Full Code Here

Examples of org.gradle.logging.internal.Console

        } else {
            if (Boolean.TRUE.equals(operationParameters.isColorOutput())) {
                PrintStream outStr = new PrintStream(operationParameters.getStandardOutput());
                DefaultColorMap colourMap = new DefaultColorMap();
                colourMap.setUseColor(true);
                Console console = new AnsiConsole(outStr, outStr, colourMap, true);
                loggingServices = this.loggingServices.newColoredLogging(console);
            } else {
                loggingServices = this.loggingServices.newToolingApiLogging();
            }
            loggingServices.get(OutputEventRenderer.class).configure(operationParameters.getBuildLogLevel());
View Full Code Here

Examples of org.h2.tools.Console

        s1.stop();
    }

    private void testConsole() throws Exception {
        String old = System.getProperty(SysProperties.H2_BROWSER);
        Console c = new Console();
        c.setOut(new PrintStream(new ByteArrayOutputStream()));
        try {

            // start including browser
            lastUrl = "-";
            System.setProperty(SysProperties.H2_BROWSER, "call:" + TestTools.class.getName() + ".openBrowser");
            c.runTool("-web", "-webPort", "9002", "-tool", "-browser", "-tcp", "-tcpPort", "9003", "-pg", "-pgPort", "9004");
            assertContains(lastUrl, ":9002");
            c.shutdown();

            // check if starting the browser works
            c.runTool("-web", "-webPort", "9002", "-tool");
            lastUrl = "-";
            c.actionPerformed(new ActionEvent(this, 0, "console"));
            assertContains(lastUrl, ":9002");
            lastUrl = "-";
            // double-click prevention is 100 ms
            Thread.sleep(200);
            MouseEvent me = new MouseEvent(new Button(), 0, 0, 0, 0, 0, 0, false, MouseEvent.BUTTON1);
            c.mouseClicked(me);
            assertContains(lastUrl, ":9002");
            lastUrl = "-";
            // no delay - ignore because it looks like a double click
            c.mouseClicked(me);
            assertEquals("-", lastUrl);
            // open the window
            c.actionPerformed(new ActionEvent(this, 0, "status"));
            c.actionPerformed(new ActionEvent(this, 0, "exit"));

            // check if the service was stopped
            c.runTool("-webPort", "9002");
            c.shutdown();

            // trying to use the same port for two services should fail,
            // but also stop the first service
            createClassProxy(c.getClass());
            assertThrows(ErrorCode.EXCEPTION_OPENING_PORT_2, c).
                    runTool("-web", "-webPort", "9002", "-tcp", "-tcpPort", "9002");
            c.runTool("-web", "-webPort", "9002");
            c.shutdown();

        } finally {
            if (old != null) {
                System.setProperty(SysProperties.H2_BROWSER, old);
            } else {
View Full Code Here

Examples of org.javatari.atari.console.Console

    }
  }

  protected Console buildAndPlugStandaloneConsole() {
    if (standaloneConsole != null) throw new IllegalStateException();
    standaloneConsole = new Console();
    plugConsole(standaloneConsole);
    return standaloneConsole;
  }
View Full Code Here

Examples of org.jboss.aesh.console.Console

                console.getShell().out().println("^C");
                console.clearBufferAndDisplayPrompt();
            }
        });

        final Console exampleConsole = new Console(builder.create());

        Completion completer = new Completion() {
            @Override
            public void complete(CompleteOperation co) {
                // very simple completor
                List<String> commands = new ArrayList<String>();
                if(co.getBuffer().equals("fo") || co.getBuffer().equals("foo")) {
                    commands.add("foo");
                    commands.add("foobaa");
                    commands.add("foobar");
                    commands.add("foobaxxxxxx");
                    commands.add("foobbx");
                    commands.add("foobcx");
                    commands.add("foobdx");
                }
                if(co.getBuffer().equals("p")) {
                    commands.add("profile=foo");
                    co.setOffset(0);
                }
                /*
                if(co.getBuffer().equals("p")) {
                    commands.add("profile=bar");
                    co.setOffset(0);
                }
                */
                if(co.getBuffer().equals("profile="))
                    commands.add("profile=foo");
                if(co.getBuffer().equals("profile="))
                    commands.add("profile=bar");
                if(co.getBuffer().equals("--")) {
                    commands.add("--help-");
                }
                if("--help-me".startsWith(co.getBuffer())) {
                    commands.add("--help-me");
                }
                if(co.getBuffer().equals("fooba")) {
                    commands.add("foobaa");
                    commands.add("foobar");
                    commands.add("foobaxxxxxx");
                }
                if(co.getBuffer().equals("foobar")) {
                    commands.add("foobar");
                }
                if(co.getBuffer().equals("bar")) {
                    commands.add("bar/");
                }
                if(co.getBuffer().equals("h")) {
                    commands.add("help.history");
                    commands.add("help");
                    co.setOffset(0);
                }
                if(co.getBuffer().equals("help")) {
                    commands.add("help.history");
                    commands.add("help");
                }
                if(co.getBuffer().equals("help.")) {
                    commands.add("help.history");
                }
                if(co.getBuffer().equals("deploy")) {
                    commands.add("deploy /home/blabla/foo/bar/alkdfe/en/to/tre");
                }
                if(co.getBuffer().equals("testing")) {
                    commands.add("testing YAY");
                }
                if(co.getBuffer().equals("val") ||
                        co.getBuffer().equals("value ")) {
                    commands.add("value 1");
                    commands.add("value 2");
                    commands.add("value 10");
                    commands.add("value 20");
                }
                if(co.getBuffer().equals("valu"))
                    commands.add("value 10");

                co.setCompletionCandidates(commands);
            }
        };

        exampleConsole.addCompletion(completer);

        final ConsoleCallback consoleCallback = new ConsoleCallback() {
            @Override
            public int readConsoleOutput(ConsoleOperation output) {
                try {
                //To change body of implemented methods use File | Settings | File Templates.
                exampleConsole.getShell().out().print("======>\"" + output.getBuffer() + "\"\n");
                if(masking) {
                    exampleConsole.getShell().out().print("got password: " + output.getBuffer() + ", stopping masking");
                    masking = false;
                    exampleConsole.setPrompt(prompt);
                }
                else if (output.getBuffer().equalsIgnoreCase("quit") || output.getBuffer().equalsIgnoreCase("exit") ||
                        output.getBuffer().equalsIgnoreCase("reset")) {
                    exampleConsole.stop();
                }
                else if(output.getBuffer().equalsIgnoreCase("password")) {
                    masking = true;
                    exampleConsole.setPrompt(new Prompt("password: ", (char) 0));
                }
                else if(output.getBuffer().startsWith("blah")) {
                    exampleConsole.getShell().err().print("blah. command not found.\n");
                    exampleConsole.getShell().out().print("BAH" + Config.getLineSeparator());
                }
                else if(output.getBuffer().equals("clear"))
                    exampleConsole.clear();
                else if(output.getBuffer().startsWith("man")) {
                    //exampleConsole.attachProcess(test);
                    ConsoleCommand test =
                            new ExampleConsoleCommand(exampleConsole, output);
                    exampleConsole.attachProcess(test);
                }
                else if(output.getBuffer().startsWith("login")) {
                    exampleConsole.setConsoleCallback(passwordCallback);
                    exampleConsole.setPrompt(new Prompt("Username: "));
                }
                 return 0;
                }
                catch (IOException ioe) {
                    exampleConsole.getShell().out().println("Exception: "+ioe.getMessage());
                    return -1;
                }
            }
        };
        exampleConsole.setConsoleCallback(consoleCallback);
        exampleConsole.start();
        exampleConsole.setPrompt(prompt);

        passwordCallback = new ConsoleCallback() {
            private boolean hasUsername = false;

            @Override
            public int readConsoleOutput(ConsoleOperation output) {
                if(hasUsername) {
                    password = output.getBuffer();
                    hasPassword = true;
                    exampleConsole.getShell().out().print("Username: " + username + ", password: " + password + Config.getLineSeparator());
                    exampleConsole.setPrompt(prompt);
                    exampleConsole.setConsoleCallback(consoleCallback);
                }
                else {
                    username = output.getBuffer();
                    exampleConsole.setPrompt( new Prompt("Password: ", (char) 0));
                    hasUsername = true;
                }
                return 0;
            }
        };

        //show how we can change the prompt async
        try {
            Thread.sleep(4000);
            exampleConsole.setPrompt(new Prompt(
                    new TerminalString("[FOO]» ", new TerminalColor( Color.RED, Color.DEFAULT), new TerminalTextStyle(CharacterType.BOLD))));
        } catch (InterruptedException e) {
            e.printStackTrace();
        }

View Full Code Here

Examples of org.jboss.aesh.console.Console

                console.getShell().out().println("^C");
                console.clearBufferAndDisplayPrompt();
            }
        });

        final Console exampleConsole = new Console(builder.create());

        Completion completer = new Completion() {
            @Override
            public void complete(CompleteOperation co) {
                // very simple completor
                List<String> commands = new ArrayList<String>();
                if(co.getBuffer().equals("fo") || co.getBuffer().equals("foo")) {
                    commands.add("foo");
                    commands.add("foobaa");
                    commands.add("foobar");
                    commands.add("foobaxxxxxx");
                    commands.add("foobbx");
                    commands.add("foobcx");
                    commands.add("foobdx");
                }
                if(co.getBuffer().equals("p")) {
                    commands.add("profile=foo");
                    co.setOffset(0);
                }
                /*
                if(co.getBuffer().equals("p")) {
                    commands.add("profile=bar");
                    co.setOffset(0);
                }
                */
                if(co.getBuffer().equals("profile="))
                    commands.add("profile=foo");
                if(co.getBuffer().equals("profile="))
                    commands.add("profile=bar");
                if(co.getBuffer().equals("--")) {
                    commands.add("--help-");
                }
                if("--help-me".startsWith(co.getBuffer())) {
                    commands.add("--help-me");
                }
                if(co.getBuffer().equals("fooba")) {
                    commands.add("foobaa");
                    commands.add("foobar");
                    commands.add("foobaxxxxxx");
                }
                if(co.getBuffer().equals("foobar")) {
                    commands.add("foobar");
                }
                if(co.getBuffer().equals("bar")) {
                    commands.add("bar/");
                }
                if(co.getBuffer().equals("h")) {
                    commands.add("help.history");
                    commands.add("help");
                    co.setOffset(0);
                }
                if(co.getBuffer().equals("help")) {
                    commands.add("help.history");
                    commands.add("help");
                }
                if(co.getBuffer().equals("help.")) {
                    commands.add("help.history");
                }
                if(co.getBuffer().equals("deploy")) {
                    commands.add("deploy /home/blabla/foo/bar/alkdfe/en/to/tre");
                }
                if(co.getBuffer().equals("testing")) {
                    commands.add("testing YAY");
                }
                if(co.getBuffer().equals("val") ||
                        co.getBuffer().equals("value ")) {
                    commands.add("value 1");
                    commands.add("value 2");
                    commands.add("value 10");
                    commands.add("value 20");
                }
                if(co.getBuffer().equals("valu"))
                    commands.add("value 10");

                co.setCompletionCandidates(commands);
            }
        };

        exampleConsole.addCompletion(completer);

        final ConsoleCallback consoleCallback = new AeshConsoleCallback() {
            @Override
            public int execute(ConsoleOperation output) {
                try {
                //To change body of implemented methods use File | Settings | File Templates.
                exampleConsole.getShell().out().print("======>\"" + output.getBuffer() + "\"\n");
                if(masking) {
                    exampleConsole.getShell().out().print("got password: " + output.getBuffer() + ", stopping masking");
                    masking = false;
                    exampleConsole.setPrompt(prompt);
                }
                else if (output.getBuffer().equalsIgnoreCase("quit") || output.getBuffer().equalsIgnoreCase("exit") ||
                        output.getBuffer().equalsIgnoreCase("reset")) {
                    exampleConsole.stop();
                }
                else if(output.getBuffer().equalsIgnoreCase("password")) {
                    masking = true;
                    exampleConsole.setPrompt(new Prompt("password: ", (char) 0));
                }
                else if(output.getBuffer().startsWith("blah")) {
                    exampleConsole.getShell().err().print("blah. command not found.\n");
                    exampleConsole.getShell().out().print("BAH" + Config.getLineSeparator());
                }
                else if(output.getBuffer().equals("clear"))
                    exampleConsole.clear();
                else if(output.getBuffer().startsWith("man")) {
                    //exampleConsole.attachProcess(test);
                    //man = new ExampleConsoleCommand(exampleConsole, output);
                    exampleConsole.getShell().out().println("trying to wait for input");
                    CommandOperation co = null;
                    try {
                        co = getInput();
                    }
                    catch (InterruptedException e) {
                        e.printStackTrace();
                        return -1;
                    }
                    exampleConsole.getShell().out().println("got: " + co.toString());
                    //exampleConsole.attachProcess(test);
                }
                else if(output.getBuffer().startsWith("login")) {
                    exampleConsole.setConsoleCallback(passwordCallback);
                    exampleConsole.setPrompt(new Prompt("Username: "));
                }
                 return 0;
                }
                catch (IOException ioe) {
                    exampleConsole.getShell().out().println("Exception: "+ioe.getMessage());
                    return -1;
                }
            }
        };

        exampleConsole.setConsoleCallback(consoleCallback);
        exampleConsole.start();
        exampleConsole.setPrompt(prompt);

        passwordCallback = new AeshConsoleCallback() {
            private boolean hasUsername = false;

            @Override
            public int execute(ConsoleOperation output) {
                if(hasUsername) {
                    password = output.getBuffer();
                    hasPassword = true;
                    exampleConsole.getShell().out().print("Username: " + username + ", password: " + password + Config.getLineSeparator());
                    exampleConsole.setPrompt(prompt);
                    exampleConsole.setConsoleCallback(consoleCallback);
                }
                else {
                    username = output.getBuffer();
                    exampleConsole.setPrompt( new Prompt("Password: ", (char) 0));
                    hasUsername = true;
                }
                return 0;
            }
        };

        //show how we can change the prompt async
        try {
            Thread.sleep(4000);
            exampleConsole.setPrompt(new Prompt(
                    new TerminalString("[FOO]» ", new TerminalColor( Color.RED, Color.DEFAULT), new TerminalTextStyle(CharacterType.BOLD))));
        } catch (InterruptedException e) {
            e.printStackTrace();
        }

View Full Code Here

Examples of org.jboss.aesh.console.Console

   private void interactiveRun() throws IOException {
      config = new ConfigImpl(SystemUtils.getAppConfigFolder("InfinispanShell"));
      config.load();
      Settings settings = Settings.getInstance();
      settings.setAliasEnabled(false);
      console = new Console();
      context.setOutputAdapter(new ConsoleIOAdapter(console));
      console.addCompletion(new Completer(context));
      ScheduledExecutorService executor = Executors.newSingleThreadScheduledExecutor();
      sessionPingTask = executor.scheduleWithFixedDelay(new PingTask(), SESSION_PING_TIMEOUT, SESSION_PING_TIMEOUT, TimeUnit.SECONDS);
View Full Code Here

Examples of org.jboss.aesh.console.Console

                    e.printStackTrace();
                }
            }
        });

        final Console exampleConsole = new Console(builder.create());

        final ConsoleCommand test = new ConsoleCommand(exampleConsole) {

            @Override
            protected void afterAttach() throws IOException {
                if(!hasRedirectOut()) {
                    console.pushToStdOut(ANSI.getAlternateBufferScreen());
                }

                readFromFile();

                //detach after init if hasRedirectOut()
                if(hasRedirectOut()) {
                    detach();
                }
            }

            @Override
            protected void afterDetach() throws IOException {
                if(!hasRedirectOut())
                    console.pushToStdOut(ANSI.getMainBufferScreen());
            }

            private void readFromFile() throws IOException {
                if(getConsoleOutput().getStdOut() != null &&
                        getConsoleOutput().getStdOut().length() > 0) {
                    console.pushToStdOut("FROM STDOUT: "+getConsoleOutput().getStdOut());
                }
                else
                    console.pushToStdOut("here should we present some text... press 'q' to quit");
            }

            @Override
            public void processOperation(Operation operation) throws IOException {
                if(operation.getInput()[0] == 'q') {
                    detach();
                }
                else if(operation.getInput()[0] == 'a') {
                    readFromFile();
                }
                else {

                }
            }
        };

        Completion completer = new Completion() {
            @Override
            public void complete(CompleteOperation co) {
                // very simple completor
                List<String> commands = new ArrayList<String>();
                if(co.getBuffer().equals("fo") || co.getBuffer().equals("foo")) {
                    commands.add("foo");
                    commands.add("foobaa");
                    commands.add("foobar");
                    commands.add("foobaxxxxxx");
                    commands.add("foobbx");
                    commands.add("foobcx");
                    commands.add("foobdx");
                }
                if(co.getBuffer().equals("p")) {
                    commands.add("profile=foo");
                    co.setOffset(0);
                }
                /*
                if(co.getBuffer().equals("p")) {
                    commands.add("profile=bar");
                    co.setOffset(0);
                }
                */
                if(co.getBuffer().equals("profile="))
                    commands.add("profile=foo");
                if(co.getBuffer().equals("profile="))
                    commands.add("profile=bar");
                if(co.getBuffer().equals("--")) {
                    commands.add("--help-");
                }
                if("--help-me".startsWith(co.getBuffer())) {
                    commands.add("--help-me");
                }
                if(co.getBuffer().equals("fooba")) {
                    commands.add("foobaa");
                    commands.add("foobar");
                    commands.add("foobaxxxxxx");
                }
                if(co.getBuffer().equals("foobar")) {
                    commands.add("foobar");
                }
                if(co.getBuffer().equals("bar")) {
                    commands.add("bar/");
                }
                if(co.getBuffer().equals("h")) {
                    commands.add("help.history");
                    commands.add("help");
                    co.setOffset(0);
                }
                if(co.getBuffer().equals("help")) {
                    commands.add("help.history");
                    commands.add("help");
                }
                if(co.getBuffer().equals("help.")) {
                    commands.add("help.history");
                }
                if(co.getBuffer().equals("deploy")) {
                    commands.add("deploy /home/blabla/foo/bar/alkdfe/en/to/tre");
                }
                if(co.getBuffer().equals("testing")) {
                    commands.add("testing YAY");
                }
                co.setCompletionCandidates(commands);
            }
        };

        exampleConsole.addCompletion(completer);

        final ConsoleOutput line;
        final ConsoleCallback consoleCallback = new ConsoleCallback() {
            @Override
            public int readConsoleOutput(ConsoleOutput output) throws IOException{
                //To change body of implemented methods use File | Settings | File Templates.

                exampleConsole.pushToStdOut("======>\"" + output.getBuffer() + "\"\n");
                if(masking) {
                    exampleConsole.pushToStdOut("got password: "+output.getBuffer()+", stopping masking");
                    masking = false;
                    exampleConsole.setPrompt(prompt);
                }
                else if (output.getBuffer().equalsIgnoreCase("quit") || output.getBuffer().equalsIgnoreCase("exit") ||
                        output.getBuffer().equalsIgnoreCase("reset")) {
                    exampleConsole.stop();
                }
                else if(output.getBuffer().equalsIgnoreCase("password")) {
                    masking = true;
                    exampleConsole.setPrompt(new Prompt("password: ", (char) 0));
                }
                else if(output.getBuffer().startsWith("blah")) {
                    exampleConsole.pushToStdErr("blah. command not found.\n");
                    exampleConsole.pushToStdOut("BAH"+ Config.getLineSeparator());
                }
                else if(output.getBuffer().equals("clear"))
                    exampleConsole.clear();
                else if(output.getBuffer().startsWith("man")) {
                    //exampleConsole.attachProcess(test);
                    test.attach(output);
                }
                else if(output.getBuffer().startsWith("login")) {
                    exampleConsole.setConsoleCallback(passwordCallback);
                    exampleConsole.setPrompt(new Prompt("Username: "));
                }
                 return 0;
            }
        };
        exampleConsole.setConsoleCallback(consoleCallback);
        exampleConsole.start();
        exampleConsole.setPrompt(prompt);

        passwordCallback = new ConsoleCallback() {
            private boolean hasUsername = false;

            @Override
            public int readConsoleOutput(ConsoleOutput output) throws IOException {
                if(hasUsername) {
                    password = output.getBuffer();
                    hasPassword = true;
                    exampleConsole.pushToStdOut("Username: "+username+", password: "+password+Config.getLineSeparator());
                    exampleConsole.setPrompt(prompt);
                    exampleConsole.setConsoleCallback(consoleCallback);
                }
                else {
                    username = output.getBuffer();
                    exampleConsole.setPrompt( new Prompt("Password: ", (char) 0));
                    hasUsername = true;
                }
                return 0;
            }
        };

        //show how we can change the prompt async
        try {
            Thread.sleep(4000);
            exampleConsole.setPrompt(new Prompt(
                    new TerminalString("[FOO]» ", Color.DEFAULT_BG, Color.RED_TEXT, CharacterType.BOLD)));
            //exampleConsole.pushToStdOut(new TerminalString("PUSHING", Color.DEFAULT_BG, Color.BLUE_TEXT).getAsString());
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
View Full Code Here
TOP
Copyright © 2018 www.massapi.com. 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.