Exemplo n.º 1
0
  /**
   * Calling this method will put the underlying terminal in private mode, clear the screen, move
   * the cursor and refresh.
   *
   * @throws LanternaException
   */
  public void startScreen() {
    if (hasBeenActivated) return;

    hasBeenActivated = true;
    terminal.enterPrivateMode();
    terminal.clearScreen();
    terminal.moveCursor(cursorPosition.getColumn(), cursorPosition.getRow());
    refresh();
  }
Exemplo n.º 2
0
  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();
  }
Exemplo n.º 3
0
  /**
   * Call this method to make changes done through {@code putCharacter(...)}, {@code putString(...)}
   * visible on the terminal. The screen will calculate the changes that are required and send the
   * necessary characters and control sequences to make it so.
   */
  public void refresh() {
    if (!hasBeenActivated) return;

    synchronized (mutex) {
      // If any resize operations are in the queue, execute them
      resizeScreenIfNeeded();

      Map<TerminalPosition, ScreenCharacter> updateMap =
          new TreeMap<TerminalPosition, ScreenCharacter>(new ScreenPointComparator());

      for (int y = 0; y < terminalSize.getRows(); y++) {
        for (int x = 0; x < terminalSize.getColumns(); x++) {
          ScreenCharacter c = backbuffer[y][x];
          if (!c.equals(visibleScreen[y][x]) || wholeScreenInvalid) {
            visibleScreen[y][x] =
                c; // Remember, ScreenCharacter is immutable, we don't need to worry about it being
            // modified
            updateMap.put(new TerminalPosition(x, y), c);
          }
        }
      }

      Writer terminalWriter = new Writer();
      terminalWriter.reset();
      TerminalPosition previousPoint = null;
      for (TerminalPosition nextUpdate : updateMap.keySet()) {
        if (previousPoint == null
            || previousPoint.getRow() != nextUpdate.getRow()
            || previousPoint.getColumn() + 1 != nextUpdate.getColumn()) {
          terminalWriter.setCursorPosition(nextUpdate.getColumn(), nextUpdate.getRow());
        }
        terminalWriter.writeCharacter(updateMap.get(nextUpdate));
        previousPoint = nextUpdate;
      }
      terminalWriter.setCursorPosition(
          getCursorPosition().getColumn(), getCursorPosition().getRow());
      wholeScreenInvalid = false;
    }
    terminal.flush();
  }
Exemplo n.º 4
0
  public static void main(String[] args) throws InterruptedException {
    Terminal terminal = TerminalFacade.createSwingTerminal();
    terminal.enterPrivateMode();
    terminal.clearScreen();
    terminal.moveCursor(10, 5);
    terminal.putCharacter('H');
    terminal.putCharacter('e');
    terminal.putCharacter('l');
    terminal.putCharacter('l');
    terminal.putCharacter('o');
    terminal.putCharacter('!');
    terminal.putCharacter(' ');
    terminal.putCharacter(ACS.HEART);
    terminal.putCharacter(ACS.SPADES);
    terminal.putCharacter(ACS.CLUB);
    terminal.putCharacter(ACS.DIAMOND);
    terminal.putCharacter(ACS.DOUBLE_LINE_CROSS);
    terminal.putCharacter(ACS.SINGLE_LINE_CROSS);
    terminal.putCharacter(ACS.DOUBLE_LINE_T_DOWN);
    terminal.putCharacter(ACS.SINGLE_LINE_VERTICAL);
    terminal.putCharacter(ACS.SINGLE_LINE_HORIZONTAL);
    terminal.moveCursor(10, 7);
    terminal.applySGR(Terminal.SGR.ENTER_BOLD);
    terminal.putCharacter('H');
    terminal.putCharacter('e');
    terminal.putCharacter('l');
    terminal.putCharacter('l');
    terminal.putCharacter('o');
    terminal.putCharacter('!');
    terminal.putCharacter(' ');
    terminal.putCharacter(ACS.HEART);
    terminal.putCharacter(ACS.SPADES);
    terminal.putCharacter(ACS.CLUB);
    terminal.putCharacter(ACS.DIAMOND);
    terminal.putCharacter(ACS.DOUBLE_LINE_CROSS);
    terminal.putCharacter(ACS.SINGLE_LINE_CROSS);
    terminal.putCharacter(ACS.DOUBLE_LINE_T_DOWN);
    terminal.putCharacter(ACS.SINGLE_LINE_VERTICAL);
    terminal.putCharacter(ACS.SINGLE_LINE_HORIZONTAL);
    terminal.moveCursor(10, 9);
    terminal.applySGR(Terminal.SGR.ENTER_UNDERLINE);
    terminal.putCharacter('H');
    terminal.putCharacter('e');
    terminal.applySGR(Terminal.SGR.EXIT_BOLD);
    terminal.putCharacter('l');
    terminal.applySGR(Terminal.SGR.EXIT_UNDERLINE);
    terminal.putCharacter('l');
    terminal.putCharacter('o');
    terminal.applySGR(Terminal.SGR.ENTER_UNDERLINE);
    terminal.putCharacter('!');
    terminal.putCharacter(' ');
    terminal.putCharacter(ACS.HEART);
    terminal.putCharacter(ACS.SPADES);
    terminal.putCharacter(ACS.CLUB);
    terminal.putCharacter(ACS.DIAMOND);
    terminal.putCharacter(ACS.DOUBLE_LINE_CROSS);
    terminal.putCharacter(ACS.SINGLE_LINE_CROSS);
    terminal.putCharacter(ACS.DOUBLE_LINE_T_DOWN);
    terminal.putCharacter(ACS.SINGLE_LINE_VERTICAL);
    terminal.putCharacter(ACS.SINGLE_LINE_HORIZONTAL);
    terminal.applySGR(Terminal.SGR.RESET_ALL);
    terminal.moveCursor(0, 0);

    Thread.sleep(5000);
    terminal.exitPrivateMode();
  }
Exemplo n.º 5
0
 private static void putString(Terminal rawTerminal, String string) {
   for (int i = 0; i < string.length(); i++) rawTerminal.putCharacter(string.charAt(i));
 }
Exemplo n.º 6
0
 // TODO add checkIntersection method,
 public void draw(Terminal terminal) {
   terminal.moveCursor(this.x, this.y);
   terminal.putCharacter(this.symbol);
   terminal.moveCursor(0, 0);
 }
Exemplo n.º 7
0
  // test de methode d'affichage avec google.lanterna
  public void affichageGraphique(Terminal terminal) {

    terminal.enterPrivateMode(); // mode d'edition du terminal
    terminal.clearScreen(); // on efface l'ecran

    for (Integer i = 1; i <= 8; i++) {
      // affichage des coordonnees au bord de l'ecran
      terminal.applyBackgroundColor(Terminal.Color.DEFAULT);
      terminal.applyForegroundColor(Terminal.Color.DEFAULT);
      terminal.moveCursor(i, 10);
      terminal.putCharacter(i.toString().charAt(0));
      terminal.moveCursor(10, i);
      terminal.putCharacter(i.toString().charAt(0));

      // changement de la couleur de fond de maniere alternative
      for (int j = 1; j <= 8; j++) {
        terminal.moveCursor(i, j);
        terminal.applyBackgroundColor(Terminal.Color.BLUE);
        if ((i + j) % 2 == 0) terminal.applyBackgroundColor(Terminal.Color.YELLOW);

        terminal.putCharacter(' ');
      }
    }
    Iterator<Piece> it = this.get_pieces().iterator();

    // affichage de chacune des pieces
    while (it.hasNext()) {
      Piece p = it.next();
      if (!p
          .get_estMange()) { // on n'affiche que les pièces qui ne sont pas mangées (i.e encore sur
                             // le plateau)
        terminal.moveCursor(p.get_coordonnees().get_x(), p.get_coordonnees().get_y());

        terminal.applyBackgroundColor(Terminal.Color.BLUE);
        if ((p.get_coordonnees().get_x() + p.get_coordonnees().get_y()) % 2 == 0)
          terminal.applyBackgroundColor(Terminal.Color.YELLOW);

        terminal.applyForegroundColor(Terminal.Color.BLACK);
        if (p.get_couleur().get_couleur() == "blanc")
          terminal.applyForegroundColor(Terminal.Color.WHITE);

        terminal.putCharacter(p.get_symbole().charAt(0));
      }
    }

    terminal.moveCursor(0, 0);
  }
Exemplo n.º 8
0
 /**
  * Creates a new Screen on top of a supplied terminal, will query the terminal for its size. The
  * screen is initially blank.
  *
  * @param terminal
  * @throws LanternaException
  */
 public Screen(Terminal terminal) {
   this(terminal, terminal.queryTerminalSize());
 }
Exemplo n.º 9
0
  /**
   * Calling this method will make the underlying terminal leave private mode, effectively going
   * back to whatever state the terminal was in before calling {@code startScreen()}
   *
   * @throws LanternaException
   */
  public void stopScreen() {
    if (!hasBeenActivated) return;

    terminal.exitPrivateMode();
    hasBeenActivated = false;
  }
Exemplo n.º 10
0
 /**
  * Reads the next {@code Key} from the input queue, or returns null if there is nothing on the
  * queue.
  */
 public Key readInput() {
   return terminal.readInput();
 }