Exemplo n.º 1
0
 @Override
 public void drawComponent(TextGUIGraphics graphics) {
   TerminalSize area = graphics.getSize();
   String absolutePath = directory.getAbsolutePath();
   if (area.getColumns() < absolutePath.length()) {
     absolutePath = absolutePath.substring(absolutePath.length() - area.getColumns());
     absolutePath = "..." + absolutePath.substring(Math.min(absolutePath.length(), 3));
   }
   setText(absolutePath);
   super.drawComponent(graphics);
 }
Exemplo n.º 2
0
    @Override
    public void drawComponent(TextGUIGraphics graphics, ComboBox<V> comboBox) {
      graphics.setForegroundColor(TextColor.ANSI.WHITE);
      graphics.setBackgroundColor(TextColor.ANSI.BLUE);
      if (comboBox.isFocused()) {
        graphics.setForegroundColor(TextColor.ANSI.YELLOW);
        graphics.enableModifiers(SGR.BOLD);
      }
      graphics.fill(' ');
      int editableArea =
          graphics.getSize().getColumns() - 2; // This is exclusing the 'drop-down arrow'
      int textInputPosition = comboBox.getTextInputPosition();
      int columnsToInputPosition =
          CJKUtils.getColumnWidth(comboBox.getText().substring(0, textInputPosition));
      if (columnsToInputPosition < textVisibleLeftPosition) {
        textVisibleLeftPosition = columnsToInputPosition;
      }
      if (columnsToInputPosition - textVisibleLeftPosition >= editableArea) {
        textVisibleLeftPosition = columnsToInputPosition - editableArea + 1;
      }
      if (columnsToInputPosition - textVisibleLeftPosition + 1 == editableArea
          && comboBox.getText().length() > textInputPosition
          && CJKUtils.isCharCJK(comboBox.getText().charAt(textInputPosition))) {
        textVisibleLeftPosition++;
      }

      String textToDraw =
          CJKUtils.fitString(comboBox.getText(), textVisibleLeftPosition, editableArea);
      graphics.putString(0, 0, textToDraw);
      if (comboBox.isFocused()) {
        graphics.disableModifiers(SGR.BOLD);
      }
      graphics.setForegroundColor(TextColor.ANSI.BLACK);
      graphics.setBackgroundColor(TextColor.ANSI.WHITE);
      graphics.putString(editableArea, 0, "|" + Symbols.ARROW_DOWN);
    }
Exemplo n.º 3
0
    @Override
    public void drawComponent(TextGUIGraphics graphics, TextBox component) {
      if (viewTopLeft.getColumn() + graphics.getSize().getColumns() > component.longestRow) {
        viewTopLeft =
            viewTopLeft.withColumn(component.longestRow - graphics.getSize().getColumns());
        if (viewTopLeft.getColumn() < 0) {
          viewTopLeft = viewTopLeft.withColumn(0);
        }
      }
      if (viewTopLeft.getRow() + graphics.getSize().getRows() > component.getLineCount()) {
        viewTopLeft = viewTopLeft.withRow(component.getLineCount() - graphics.getSize().getRows());
        if (viewTopLeft.getRow() < 0) {
          viewTopLeft = viewTopLeft.withRow(0);
        }
      }
      if (component.isFocused()) {
        graphics.applyThemeStyle(graphics.getThemeDefinition(TextBox.class).getActive());
      } else {
        graphics.applyThemeStyle(graphics.getThemeDefinition(TextBox.class).getNormal());
      }
      graphics.fill(component.unusedSpaceCharacter);

      if (!component.isReadOnly()) {
        // Adjust the view if necessary
        if (component.caretPosition.getColumn() < viewTopLeft.getColumn()) {
          viewTopLeft = viewTopLeft.withColumn(component.caretPosition.getColumn());
        } else if (component.caretPosition.getColumn()
            >= graphics.getSize().getColumns() + viewTopLeft.getColumn()) {
          viewTopLeft =
              viewTopLeft.withColumn(
                  component.caretPosition.getColumn() - graphics.getSize().getColumns() + 1);
        }
        if (component.caretPosition.getRow() < viewTopLeft.getRow()) {
          viewTopLeft = viewTopLeft.withRow(component.getCaretPosition().getRow());
        } else if (component.caretPosition.getRow()
            >= graphics.getSize().getRows() + viewTopLeft.getRow()) {
          viewTopLeft =
              viewTopLeft.withRow(
                  component.caretPosition.getRow() - graphics.getSize().getRows() + 1);
        }
      }

      for (int row = 0; row < graphics.getSize().getRows(); row++) {
        int rowIndex = row + viewTopLeft.getRow();
        if (rowIndex >= component.lines.size()) {
          continue;
        }
        String line = component.lines.get(rowIndex);
        if (line.length() > viewTopLeft.getColumn()) {
          String string = line.substring(viewTopLeft.getColumn());
          if (component.mask != null) {
            string = new String(new char[string.length()]).replace('\0', component.mask);
          }
          graphics.putString(0, row, string);
        }
      }
    }