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


   * Create a new {@link Shell} instance.
   * @throws IOException
   */
  public Shell(List<Command> commands) throws IOException {
    attachSignalHandler();
    this.consoleReader = new ConsoleReader();
    this.commandRunner = createCommandRunner(commands);
    initializeConsoleReader();
  }
View Full Code Here

public class Main {

  private static int counter;

  public static void main(String[] args) throws Exception {
    ConsoleReader reader = new ConsoleReader();
    reader.setPrompt("> ");

    PrintWriter out = new PrintWriter(reader.getOutput());
    out.println(banner());

    Environment env = new Environment();

    while (!env.isHalted()) {
      String line = reader.readLine();
      if (line == null)
        break;

      String output = eval(env, line);
View Full Code Here

  public static void shell() throws Exception {
    System.out.println("loOp (http://looplang.org)");
    System.out.println("     by Dhanji R. Prasanna\n");

    ConsoleReader reader = new ConsoleReader();
    try {
      reader.setExpandEvents(false);
      reader.addCompleter(new MetaCommandCompleter());

      Unit shellScope = new Unit(null, ModuleDecl.SHELL);
      FunctionDecl main = new FunctionDecl("main", null);
      shellScope.declare(main);
      shellContext = new HashMap<String, Object>();

      boolean inFunction = false;

      // Used to build up multiline statement blocks (like functions)
      StringBuilder block = null;
      //noinspection InfiniteLoopStatement
      do {
        String prompt = (block != null) ? "|    " : ">> ";
        String rawLine = reader.readLine(prompt);

        if (inFunction) {
          if (rawLine == null || rawLine.trim().isEmpty()) {
            inFunction = false;

            // Eval the function to verify it.
            printResult(Loop.evalClassOrFunction(block.toString(), shellScope));
            block = null;
            continue;
          }

          block.append(rawLine).append('\n');
          continue;
        }

        if (rawLine == null) {
          quit(reader);
        }

        //noinspection ConstantConditions
        String line = rawLine.trim();
        if (line.isEmpty())
          continue;

        // Add a require import.
        if (line.startsWith("require ")) {
          shellScope.declare(new LexprParser(new Tokenizer(line + '\n').tokenize()).require());
          shellScope.loadDeps("<shell>");
          continue;
        }

        if (line.startsWith(":q") || line.startsWith(":quit")) {
          quit(reader);
        }

        if (line.startsWith(":h") || line.startsWith(":help")) {
          printHelp();
        }

        if (line.startsWith(":run")) {
          String[] split = line.split("[ ]+", 2);
          if (split.length < 2 || !split[1].endsWith(".loop"))
            System.out.println("You must specify a .loop file to run.");
          Loop.run(split[1]);
          continue;
        }

        if (line.startsWith(":r") || line.startsWith(":reset")) {
          System.out.println("Context reset.");
          shellScope = new Unit(null, ModuleDecl.SHELL);
          main = new FunctionDecl("main", null);
          shellScope.declare(main);
          shellContext = new HashMap<String, Object>();
          continue;
        }
        if (line.startsWith(":i") || line.startsWith(":imports")) {
          for (RequireDecl requireDecl : shellScope.imports()) {
            System.out.println(requireDecl.toSymbol());
          }
          System.out.println();
          continue;
        }
        if (line.startsWith(":f") || line.startsWith(":functions")) {
          for (FunctionDecl functionDecl : shellScope.functions()) {
            StringBuilder args = new StringBuilder();
            List<Node> children = functionDecl.arguments().children();
            for (int i = 0, childrenSize = children.size(); i < childrenSize; i++) {
              Node arg = children.get(i);
              args.append(arg.toSymbol());

              if (i < childrenSize - 1)
                args.append(", ");
            }

            System.out.println(functionDecl.name()
                + ": (" + args.toString() + ")"
                + (functionDecl.patternMatching ? " #pattern-matching" : "")
            );
          }
          System.out.println();
          continue;
        }
        if (line.startsWith(":t") || line.startsWith(":type")) {
          String[] split = line.split("[ ]+", 2);
          if (split.length <= 1) {
            System.out.println("Give me an expression to determine the type for.\n");
            continue;
          }

          Object result = evalInFunction(split[1], main, shellScope, false);
          printTypeOf(result);
          continue;
        }

        if (line.startsWith(":javatype")) {
          String[] split = line.split("[ ]+", 2);
          if (split.length <= 1) {
            System.out.println("Give me an expression to determine the type for.\n");
            continue;
          }

          Object result = evalInFunction(split[1], main, shellScope, false);
          if (result instanceof LoopError)
            System.out.println(result.toString());
          else
            System.out.println(result == null ? "null" : result.getClass().getName());
          continue;
        }

        // Function definitions can be multiline.
        if (line.endsWith("->") || line.endsWith("=>")) {
          inFunction = true;
          block = new StringBuilder(line).append('\n');
          continue;
        } else if (isDangling(line)) {
          if (block == null)
            block = new StringBuilder();

          block.append(line).append('\n');
          continue;
        }

        if (block != null) {
          rawLine = block.append(line).toString();
          block = null;
        }

        // First determine what kind of expression this is.
        main.children().clear();

        // OK execute expression.
        try {
          printResult(evalInFunction(rawLine, main, shellScope, true));
        } catch (ClassCastException e) {
          StackTraceSanitizer.cleanForShell(e);
          System.out.println("#error: " + e.getMessage());
          System.out.println();
        } catch (RuntimeException e) {
          StackTraceSanitizer.cleanForShell(e);
          e.printStackTrace();
          System.out.println();
        }

      } while (true);
    } catch (IOException e) {
      System.err.println("Something went wrong =(");
      reader.getTerminal().reset();
      System.exit(1);
    }
  }
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

  }

  public TajoCli(TajoConf c, String [] args, InputStream in, OutputStream out) throws Exception {
    this.conf = new TajoConf(c);
    this.sin = in;
    this.reader = new ConsoleReader(sin, out);
    this.reader.setExpandEvents(false);
    this.sout = new PrintWriter(reader.getOutput());

    CommandLineParser parser = new PosixParser();
    CommandLine cmd = parser.parse(options, args);
View Full Code Here

    evaluate(session, new ByteArrayInputStream(expression.getBytes()));
  }

  private static void evaluate(Session session, InputStream in) throws Exception {
    UnsupportedTerminal term = new UnsupportedTerminal();
    ConsoleReader consoleReader = new ConsoleReader(in, System.out, term);
    JlineRepl repl = new JlineRepl(session, consoleReader);
    repl.setEcho(true);
    repl.setStopOnError(true);

    try {
View Full Code Here

  public JlineRepl(Session session) throws Exception {
   
    if(Strings.nullToEmpty(System.getProperty("os.name")).startsWith("Windows")) {
      // AnsiWindowsTerminal does not work properly in WIndows 7
      // so disabling across the board for now
      reader = new ConsoleReader(System.in, System.out, new UnsupportedTerminal());
    } else {
      reader = new ConsoleReader();
    }

    // disable events triggered by ! (this is valid R !!)
    reader.setExpandEvents(false);
View Full Code Here

      loadLibrary(session, namespaceUnderTest);
    }
   
    UnsupportedTerminal term = new UnsupportedTerminal();
    InputStream in = new ByteArrayInputStream(sourceText.getBytes(Charsets.UTF_8));
    ConsoleReader consoleReader = new ConsoleReader(in, reporter.getStdOut(), term);
    JlineRepl repl = new JlineRepl(session, consoleReader);
    repl.setEcho(true);
    repl.setStopOnError(true);

    try {
View Full Code Here

    this.environment = environment;
  }
 
  public void start() throws IOException {
    if(System.console() == null) {
      reader = new ConsoleReader(System.in, System.out, new UnsupportedTerminal());
    } else {
      reader = new ConsoleReader();
    }
    do {
      String line = reader.readLine(environment.getPrompt());
      execute(line);
    } while(true);
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.