Package jline

Examples of jline.Terminal


    @Option(name = "--lines", description = "stop after N lines")
    int lines;

    @Override
    protected Object doExecute() throws Exception {
        Terminal term = (Terminal) session.get(".jline.terminal");
        if (term == null || !isTty(System.out)) {
            BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
            String line;
            while ((line = reader.readLine()) != null) {
                System.out.println(line);
            }
            return null;
        } else {
            boolean echo = term.isEchoEnabled();
            term.setEchoEnabled(false);
            try {
                if (lines == 0) {
                    lines = term.getHeight();
                }
                LineSplitter reader = new LineSplitter(new BufferedReader(new InputStreamReader(System.in)), term.getWidth());
                int count = 0;
                int c;
                do {
                    do {
                        String line;
                        if ((line = reader.readLine()) == null) {
                            return null;
                        }
                        System.out.println(line);
                    } while (++count < lines - 2);
                    c = -1;
                    while (c == -1) {
                        System.out.flush();
                        System.out.print("--More--");
                        System.out.flush();
                        c = session.getKeyboard().read();
                        switch (c) {
                            case 'q':
                            case -1:
                                c = 'q';
                                break;
                            case '\r':
                            case '\n':
                            case 14: // Down arrow
                                count--;
                                System.out.print("\r          \r");
                                break;
                            case ' ':
                                count = 0;
                                System.out.print("\r          \r");
                                break;
                            case 16: // Up arrow
                                // fall through
                            default:
                                c = -1;
                                System.out.print("\r          \r");
                                break;
                        }
                        if (c == 'q') {
                            break;
                        }
                    }
                } while (c != 'q');
                return null;
            } finally {
                term.setEchoEnabled(echo);
            }
        }
    }
View Full Code Here


        public void start(final Environment env) throws IOException {
            try {
                final Subject subject = ShellImpl.this.session != null ? ShellImpl.this.session
                        .getAttribute(KarafJaasAuthenticator.SUBJECT_ATTRIBUTE_KEY) : null;
                final Terminal terminal = new SshTerminal(env);
                Runnable destroyCallback = new Runnable() {
                    public void run() {
                        destroy();
                    }
                };
View Full Code Here

        return null;
    }

    private int getTermWidth() {
        Terminal term = (Terminal) session.get(".jline.terminal");
        return term != null ? term.getWidth() : 80;
    }
View Full Code Here

            }
        } else {
            // We are going into full blown interactive shell mode.

            final TerminalFactory terminalFactory = new TerminalFactory();
            final Terminal terminal = terminalFactory.getTerminal();
            ConsoleImpl console = createConsole(commandProcessor, in, out, err, terminal);
            CommandSession session = console.getSession();
            session.put("USER", user);
            session.put("APPLICATION", application);
            session.put(NameScoping.MULTI_SCOPE_MODE_KEY, Boolean.toString(isMultiScopeMode()));
            session.put("#LINES", new Function() {
                public Object execute(CommandSession session, List<Object> arguments) throws Exception {
                    return Integer.toString(terminal.getHeight());
                }
            });
            session.put("#COLUMNS", new Function() {
                public Object execute(CommandSession session, List<Object> arguments) throws Exception {
                    return Integer.toString(terminal.getWidth());
                }
            });
            session.put(".jline.terminal", terminal);

            console.run();
View Full Code Here

                .a(": ")
                .toString() : "";
        for (Iterator<Object> it = params.iterator(); it.hasNext(); ) {
            Object param = it.next();
            if (HelpOption.HELP.name().equals(param)) {
                Terminal term = session != null ? (Terminal) session.get(".jline.terminal") : null;
                int termWidth = term != null ? term.getWidth() : 80;
                boolean globalScope = NameScoping.isGlobalScope(session, actionMetaData.getCommand().scope());
                actionMetaData.printUsage(action, System.out, globalScope, termWidth);
                return false;
            }
        }
View Full Code Here

            return;
        }
        final Subject subject = new Subject();
        subject.getPrincipals().add(new UserPrincipal("karaf"));

        final Terminal terminal = terminalFactory.getTerminal();
        Runnable callback = new Runnable() {
            public void run() {
                try {
                    bundleContext.getBundle(0).stop();
                } catch (Exception e) {
View Full Code Here

        session.getConsole().println(getMessage());
        // This makes the Groovy shell lavender. Not sure I'm a huge fan of that, but I like it being a different color.
        // Perhaps a light gray?
        session.getConsole().println("\u001B[36m");
        Terminal terminal = (Terminal) session.get(".jline.terminal");
        try {
            groovy.run(terminal, "");
        } catch (Exception e) {
            e.printStackTrace();
        } finally {
View Full Code Here

        }
        return commands;
    }

    protected void printMethodList(CommandSession session, PrintStream out, SortedMap<String, String> commands) {
        Terminal term = (Terminal) session.get(".jline.terminal");
        int termWidth = term != null ? term.getWidth() : 80;
        out.println(Ansi.ansi().a(Ansi.Attribute.INTENSITY_BOLD).a("COMMANDS").a(Ansi.Attribute.RESET));
        ShellTable table = new ShellTable().noHeaders().separator(" ").size(termWidth);
        table.column(new Col("Command").maxSize(35));
        table.column(new Col("Description"));
        for (Map.Entry<String,String> entry : commands.entrySet()) {
View Full Code Here

        }
        return null;
    }

    private void printSubShellHelp(CommandSession session, Bundle bundle, SubShell subShell, PrintStream out) {
        Terminal term = session != null ? (Terminal) session.get(".jline.terminal") : null;
        out.println(Ansi.ansi().bold().a("SUBSHELL").boldOff());
        out.print("        ");
        if (subShell.getName() != null) {
            out.println(Ansi.ansi().bold().a(subShell.getName()).boldOff());
            out.println();
        }
        out.print("\t");
        out.println(subShell.getDescription());
        out.println();
        if (subShell.getDetailedDescription() != null) {
            out.println(Ansi.ansi().bold().a("DETAILS").boldOff());
            String desc = loadDescription(bundle, subShell.getDetailedDescription());
            while (desc.endsWith("\n")) {
                desc = desc.substring(0, desc.length()  -1);
            }
            IndentFormatter.printFormatted("        ", desc, term != null ? term.getWidth() : 80, out);
        }
        out.println();
        out.println("${command-list|" + subShell.getName() + ":}");
    }
View Full Code Here

      try
      {
         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

TOP

Related Classes of jline.Terminal

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.