Package jline.console

Examples of jline.console.ConsoleReader


      {
         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


   
    return reservations;
  }
 
  public static void main(String[] args) throws Exception {
    final ConsoleReader reader = new ConsoleReader();
    ARS ars = null;
   
    while (true) {
      String line = reader.readLine(">");
      if (line == null)
        break;
     
      final String[] tokens = line.split("\\s+");
     
      if (tokens[0].equals("reserve") && tokens.length >= 4 && ars != null) {
        // start up multiple threads all trying to reserve the same resource, no more than one should succeed
       
        final ARS fars = ars;
        ArrayList<Thread> threads = new ArrayList<Thread>();
        for (int i = 3; i < tokens.length; i++) {
          final int whoIndex = i;
          Runnable reservationTask = new Runnable() {
            @Override
            public void run() {
              try {
                reader.println("  " + String.format("%20s", tokens[whoIndex]) + " : " + fars.reserve(tokens[1], tokens[2], tokens[whoIndex]));
              } catch (Exception e) {
                e.printStackTrace();
              }
            }
          };
         
          threads.add(new Thread(reservationTask));
        }
       
        for (Thread thread : threads)
          thread.start();
       
        for (Thread thread : threads)
          thread.join();
       
      } else if (tokens[0].equals("cancel") && tokens.length == 4 && ars != null) {
        ars.cancel(tokens[1], tokens[2], tokens[3]);
      } else if (tokens[0].equals("list") && tokens.length == 3 && ars != null) {
        List<String> reservations = ars.list(tokens[1], tokens[2]);
        if (reservations.size() > 0) {
          reader.println("  Reservation holder : " + reservations.get(0));
          if (reservations.size() > 1)
            reader.println("  Wait list : " + reservations.subList(1, reservations.size()));
        }
      } else if (tokens[0].equals("quit") && tokens.length == 1) {
        break;
      } else if (tokens[0].equals("connect") && tokens.length == 6 && ars == null) {
        ZooKeeperInstance zki = new ZooKeeperInstance(new ClientConfiguration().withInstance(tokens[1]).withZkHosts(tokens[2]));
        Connector conn = zki.getConnector(tokens[3], new PasswordToken(tokens[4]));
        if (conn.tableOperations().exists(tokens[5])) {
          ars = new ARS(conn, tokens[5]);
          reader.println("  connected");
        } else
          reader.println("  No Such Table");
      } else {
        System.out.println("  Commands : ");
        if (ars == null) {
          reader.println("    connect <instance> <zookeepers> <user> <pass> <table>");
        } else {
          reader.println("    reserve <what> <when> <who> {who}");
          reader.println("    cancel <what> <when> <who>");
          reader.println("    list <what> <when>");
        }
      }
    }
  }
View Full Code Here

  private boolean logErrorsToConsole = false;
  private PrintWriter writer = null;
  private boolean masking = false;

  public Shell() throws IOException {
    this(new ConsoleReader(), new PrintWriter(
        new OutputStreamWriter(System.out,
        System.getProperty("jline.WindowsTerminal.output.encoding", System.getProperty("file.encoding")))));
  }
View Full Code Here

 
  private static ConsoleReader reader = null;
 
  private static ConsoleReader getConsoleReader() throws IOException {
    if (reader == null)
      reader = new ConsoleReader();
    return reader;
  }
View Full Code Here

   
    out = System.out;
    output = new TestOutputStream();
    System.setOut(new PrintStream(output));

    shell = new Shell(new ConsoleReader(new FileInputStream(FileDescriptor.in), output), new PrintWriter(output));
    shell.setLogErrorsToConsole();
  }
View Full Code Here

    TimeZone.setDefault(TimeZone.getTimeZone("UTC"));
    Shell.log.setLevel(Level.OFF);
    output = new TestOutputStream();
    input = new StringInputStream();
    PrintWriter pw = new PrintWriter(new OutputStreamWriter(output));
    shell = new Shell(new ConsoleReader(input, output), pw);
    shell.setLogErrorsToConsole();
    shell.config("--fake", "-u", "test", "-p", "secret");
  }
View Full Code Here

  @Before
  public void setup() throws IOException {
    Shell.log.setLevel(Level.OFF);
    output = new TestOutputStream();
    shell = new Shell(new ConsoleReader(new FileInputStream(FileDescriptor.in), output), new PrintWriter(output));
    shell.setLogErrorsToConsole();
  }
View Full Code Here

    exceptionWriter.addMutation(anyObject(Mutation.class));
    expectLastCall().andThrow(mre);

    shellState = createNiceMock(Shell.class);

    reader = new ConsoleReader(input, baos, new UnsupportedTerminal());
    expect(shellState.getReader()).andReturn(reader).anyTimes();

    replay(writer, exceptionWriter, shellState);

    data = new TreeMap<Key,Value>();
View Full Code Here

    history.add("bar");

    baos = new ByteArrayOutputStream();

    String input = String.format("!1%n"); // Construct a platform dependent new-line
    reader = new ConsoleReader(new ByteArrayInputStream(input.getBytes()), baos);
    reader.setHistory(history);

    shell = new Shell(reader, null);
  }
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

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.