Package jline

Examples of jline.ConsoleReader


                try {
                    if(con == null) {
                        con = new ServerConnection(parser, out, in, kernel, deploymentFactory);
                    }
                    try {
                        dc.execute(new ConsoleReader(in, out), con, commandArgs);
                    } catch (DeploymentSyntaxException e) {
                        processException(out, e);
                    } catch (DeploymentException e) {
                        processException(out, e);
                    } catch (IOException e) {
View Full Code Here


    private void loadScript(String script, boolean batch, boolean loadOnly,
                            List<String> params, List<String> files)
        throws IOException, ParseException {
       
        Reader inputReader;
        ConsoleReader reader;
        boolean interactive;
        
        try {
            String cmds = runPreprocessor(script, params, files);

            if (mInteractive && !batch) { // Write prompt and echo commands
                // Console reader treats tabs in a special way
                cmds = cmds.replaceAll("\t","    ");

                reader = new ConsoleReader(new ByteArrayInputStream(cmds.getBytes()),
                                           new OutputStreamWriter(System.out));
                reader.setHistory(mConsoleReader.getHistory());
                InputStream in = new ConsoleReaderInputStream(reader);
                inputReader = new BufferedReader(new InputStreamReader(in));
                interactive = true;
            } else { // Quietly parse the statements
                inputReader = new StringReader(cmds);
View Full Code Here

        // run grunt interactive.
        String remainders[] = opts.getRemainingArgs();
        if (remainders == null) {
            // Interactive
            mode = ExecMode.SHELL;
            ConsoleReader reader = new ConsoleReader(System.in, new OutputStreamWriter(System.out));
            reader.setDefaultPrompt("grunt> ");
            final String HISTORYFILE = ".pig_history";
            String historyFile = System.getProperty("user.home") + File.separator  + HISTORYFILE;
            reader.setHistory(new History(new File(historyFile)));
            ConsoleReaderInputStream inputStream = new ConsoleReaderInputStream(reader);
            grunt = new Grunt(new BufferedReader(new InputStreamReader(inputStream)), pigContext);
            grunt.setConsoleReader(reader);
            gruntCalled = true;
            grunt.run();
View Full Code Here

     * @throws Exception
     *         if an Exception occurs
     */
    public void runInteractive() throws Exception {
        // built jline console reader with history + tab completion
        ConsoleReader reader = new ConsoleReader();
        reader.setHistory(new History());
        reader.setUseHistory(true);
       
        // get all available commands for command tab completion
        Collection<CommandLine> commands =
            CommandLineFactory.getInstance().getCommandLines();
        List<String> commandNames = new ArrayList<String>();
        for (CommandLine c : commands) {
            commandNames.add(c.getName());
            for (Object alias : c.getAlias()) {
                commandNames.add((String) alias);
            }
        }
        commandNames.add("exit");
        commandNames.add("quit");
       
        // first part is the command, then all arguments will get children tab completion
        reader.addCompletor(new ArgumentCompletor( new Completor[] {
                new SimpleCompletor(commandNames.toArray(new String[] {} )),
                new JcrChildrenCompletor()
        }));
       
        while (!exit) {
            try {
                String input = reader.readLine("[" + this.getPrompt() + "] > ");
               
                log.debug("running: " + input);
                if (input.trim().equals("exit") || input.trim().equals("quit")) { // exit?
                    exit = true;
                    System.out.println("Good bye...");
View Full Code Here

    private void loadScript(String script, boolean batch, boolean loadOnly,
                            List<String> params, List<String> files)
        throws IOException, ParseException {
       
        Reader inputReader;
        ConsoleReader reader;
        boolean interactive;
        
        try {
            FetchFileRet fetchFile = FileLocalizer.fetchFile(mConf, script);
            String cmds = runPreprocessor(fetchFile.file.getAbsolutePath(), params, files);

            if (mInteractive && !batch) { // Write prompt and echo commands
                // Console reader treats tabs in a special way
                cmds = cmds.replaceAll("\t","    ");

                reader = new ConsoleReader(new ByteArrayInputStream(cmds.getBytes()),
                                           new OutputStreamWriter(System.out));
                reader.setHistory(mConsoleReader.getHistory());
                InputStream in = new ConsoleReaderInputStream(reader);
                inputReader = new BufferedReader(new InputStreamReader(in));
                interactive = true;
            } else { // Quietly parse the statements
                inputReader = new StringReader(cmds);
View Full Code Here

                        "when executing pig with a pig script file)");
                return ReturnCode.ILLEGAL_ARGS;
            }
            // Interactive
            mode = ExecMode.SHELL;
            ConsoleReader reader = new ConsoleReader(System.in, new OutputStreamWriter(System.out));
            reader.setDefaultPrompt("grunt> ");
            final String HISTORYFILE = ".pig_history";
            String historyFile = System.getProperty("user.home") + File.separator  + HISTORYFILE;
            reader.setHistory(new History(new File(historyFile)));
            ConsoleReaderInputStream inputStream = new ConsoleReaderInputStream(reader);
            grunt = new Grunt(new BufferedReader(new InputStreamReader(inputStream)), pigContext);
            grunt.setConsoleReader(reader);
            gruntCalled = true;
            grunt.run();
View Full Code Here

            return null;
        }
    }

    private ConsoleReader prepareReader() throws IOException {
        ConsoleReader reader = new ConsoleReader();
        reader.setUseHistory(true);
        Map<String, String> env = System.getenv();
        String fileHistory = String.format("%s/.%s.history", env.containsKey("HOME") ? env.get("HOME"): "/tmp", commandPrompt);
        reader.setHistory(new History(new File(fileHistory)));
        return reader;
    }
View Full Code Here

    public void receiveCommand() {
        IdleMonitor idleMonitor = new IdleMonitor();
        idleMonitor.start();
        try {
            ConsoleReader reader = prepareReader();
            // allows caller to customize completor
            if(completor != null)
                reader.addCompletor(completor);
            do {
                idleMonitor.setIdle();
                String line = reader.readLine(commandPrompt + "> ").trim();
                // does not dispatch commands for caller, notify caller for processing commands
                if(cmdListener != null) {
                    idleMonitor.setBusy();
                    logCommand(line);
                    cmdListener.processCommand(line);
View Full Code Here

    }

    public void launch() {
        IdleMonitor idleMonitor = new IdleMonitor();
        try {
            ConsoleReader reader = prepareReader();
            // automatically extract completor from commandTable
            completor = extractCompletor(commandTable);
            reader.addCompletor(completor);

            idleMonitor.start();
            do {
                idleMonitor.setIdle();
                String line = reader.readLine(commandPrompt + "> ").trim();
                StringTokenizer tok = new StringTokenizer(line);
                if(tok.hasMoreElements()) {
                    String cmd = tok.nextToken();
                    // dispatches commands based on commandTable
                    if(commandTable.containsKey(cmd)) {
View Full Code Here

      this.done = false;
      this.cmd = null;
      this.cmdIndex = 0;
      this.readWait = false;
      this.output = new StringBuilderOutputStream();
      ConsoleReader reader = new ConsoleReader(this, new OutputStreamWriter(output, Constants.UTF8));
      this.shell = new Shell(reader, new PrintWriter(new OutputStreamWriter(output, Constants.UTF8)));
      shell.setLogErrorsToConsole();
      if (mock != null) {
        if (shell.config("--fake", "-u", username, "-p", password))
          throw new IOException("mock shell config error");
View Full Code Here

TOP

Related Classes of jline.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.