public static void main(String[] args) throws InterruptedException {
    final Terminal rawTerminal = new TestTerminalFactory(args).createTerminal();
    rawTerminal.enterPrivateMode();

    int currentRow = 0;
    rawTerminal.moveCursor(0, 0);
    while (true) {
      Key key = rawTerminal.readInput();
      if (key == null) {
        Thread.sleep(1);
        continue;
      }

      if (key.getKind() == Key.Kind.Escape) break;

      if (currentRow == 0) rawTerminal.clearScreen();

      rawTerminal.moveCursor(0, currentRow++);
      putString(rawTerminal, key.toString());

      if (currentRow >= rawTerminal.getTerminalSize().getRows()) currentRow = 0;
    }

    rawTerminal.exitPrivateMode();
  }
Beispiel #2
0
 @Override
 public boolean onInput(final Key k, final GUIScreen gui) {
   switch (k.getKind()) {
     case NormalKey:
       switch (k.getCharacter()) {
         case 'q':
           return this.navigation.backOneLevel();
         default:
       }
     default:
       return false;
   }
 }
 @Override
 protected Result unhandledKeyboardEvent(Key key) {
   if (key.getKind() == Key.Kind.Enter) {
     ((Item) getSelectedItem()).doAction();
     return Result.EVENT_HANDLED;
   }
   return Result.EVENT_NOT_HANDLED;
 }
  @Override
  public Key readInput() {
    synchronized (readMutex) {
      if (!keyQueue.isEmpty()) return keyQueue.poll();

      Key key = inputDecoder.getNextCharacter();
      if (key != null && key.getKind() == Key.Kind.CursorLocation) {
        TerminalPosition reportedTerminalPosition = inputDecoder.getLastReportedTerminalPosition();
        if (reportedTerminalPosition != null)
          onResized(reportedTerminalPosition.getColumn(), reportedTerminalPosition.getRow());

        return readInput();
      } else {
        return key;
      }
    }
  }
Beispiel #5
0
 public static void main(String[] argv) {
   //		Terminal terminal = TerminalFacade.createTerminal();
   //		terminal.enterPrivateMode();
   //
   //		terminal.exitPrivateMode();
   Screen screen = TerminalFacade.createScreen();
   screen.startScreen();
   screen.putString(
       10, 5, "Press \u2191 q to exit...", Terminal.Color.WHITE, Terminal.Color.BLACK);
   screen.refresh();
   boolean done = false;
   try {
     while (!done) {
       Key key = screen.readInput();
       if (key != null) {
         if (key.getCharacter() == 'q') {
           screen.putString(
               10, 6, "That is q!!!           ", Terminal.Color.GREEN, Terminal.Color.BLACK);
           screen.refresh();
           done = true;
           Thread.sleep(2000);
         } else {
           screen.putString(
               10,
               6,
               "That is " + key.getCharacter() + ", not q",
               Terminal.Color.RED,
               Terminal.Color.BLACK);
           screen.refresh();
         }
       } else {
         Thread.sleep(20);
       }
     }
   } catch (InterruptedException e) {
     // TODO Auto-generated catch block
     e.printStackTrace();
   }
   screen.stopScreen();
 }
Beispiel #6
0
 @Override
 public Result keyboardInteraction(final Key key) {
   switch (key.getKind()) {
     case ArrowLeft:
       seekPlayerRelative(this.player, 0 - getSelectedHop().getSeconds());
       return Result.EVENT_HANDLED;
     case ArrowRight:
       seekPlayerRelative(this.player, getSelectedHop().getSeconds());
       return Result.EVENT_HANDLED;
     default:
       return super.keyboardInteraction(key);
   }
 }
  protected TerminalSize waitForTerminalSizeReport(int timeoutMs) {
    long startTime = System.currentTimeMillis();
    synchronized (readMutex) {
      while (System.currentTimeMillis() - startTime < timeoutMs) {
        Key key = inputDecoder.getNextCharacter();
        if (key == null) {
          try {
            Thread.sleep(1);
          } catch (InterruptedException e) {
          }
          continue;
        }

        if (key.getKind() != Key.Kind.CursorLocation) {
          keyQueue.add(key);
        } else {
          TerminalPosition reportedTerminalPosition =
              inputDecoder.getLastReportedTerminalPosition();
          if (reportedTerminalPosition != null)
            onResized(reportedTerminalPosition.getColumn(), reportedTerminalPosition.getRow());
          else
            throw new LanternaException(
                new IOException(
                    "Unexpected: inputDecoder.getLastReportedTerminalPosition() "
                        + "returned null after position was reported"));
          return new TerminalSize(
              reportedTerminalPosition.getColumn(), reportedTerminalPosition.getRow());
        }
      }
    }
    throw new LanternaException(
        new IOException(
            "Timeout while waiting for terminal size report! "
                + "Maybe your terminal doesn't support cursor position report, please "
                + "consider using a custom size querier"));
  }