Пример #1
0
  public void addLine(String line) {
    StringBuilder bob = new StringBuilder();
    for (int i = 0; i < line.length(); i++) {
      char c = line.charAt(i);
      if (c == '\n' && style == Style.MULTI_LINE) {
        String string = bob.toString();
        int lineWidth = CJKUtils.getTrueWidth(string);
        lines.add(string);
        if (longestRow < lineWidth + 1) {
          longestRow = lineWidth + 1;
        }
        addLine(line.substring(i + 1));
        return;
      } else if (Character.isISOControl(c)) {
        continue;
      }

      bob.append(c);
    }
    String string = bob.toString();
    if (!validated(string)) {
      throw new IllegalStateException(
          "TextBox validation pattern " + validationPattern + " does not match the supplied text");
    }
    int lineWidth = CJKUtils.getTrueWidth(string);
    lines.add(string);
    if (longestRow < lineWidth + 1) {
      longestRow = lineWidth + 1;
    }
  }
Пример #2
0
  @Override
  public TextGraphics putString(int column, int row, String string) {
    if (string.contains("\n")) {
      string = string.substring(0, string.indexOf("\n"));
    }
    if (string.contains("\r")) {
      string = string.substring(0, string.indexOf("\r"));
    }
    string = tabBehaviour.replaceTabs(string, column);
    int offset = 0;
    for (int i = 0; i < string.length(); i++) {
      char character = string.charAt(i);
      setCharacter(
          column + offset,
          row,
          new TextCharacter(character, foregroundColor, backgroundColor, activeModifiers.clone()));

      if (CJKUtils.isCharCJK(character)) {
        // CJK characters are twice the normal characters in width, so next character position is
        // two columns forward
        offset += 2;
      } else {
        // For "normal" characters we advance to the next column
        offset += 1;
      }
    }
    return this;
  }
Пример #3
0
 @Override
 public TerminalSize getPreferredSize(final ComboBox<V> comboBox) {
   TerminalSize size =
       TerminalSize.ONE.withColumns(
           (comboBox.getItemCount() == 0 ? CJKUtils.getColumnWidth(comboBox.getText()) : 0) + 2);
   synchronized (comboBox) {
     for (int i = 0; i < comboBox.getItemCount(); i++) {
       V item = comboBox.getItem(i);
       size =
           size.max(
               new TerminalSize(
                   CJKUtils.getColumnWidth(item.toString()) + 2 + 1,
                   1)); // +1 to add a single column of space
     }
   }
   return size;
 }
Пример #4
0
 public TextBox setMask(Character mask) {
   if (mask != null && CJKUtils.isCharCJK(mask)) {
     throw new IllegalArgumentException("Cannot use a CJK character as a mask");
   }
   this.mask = mask;
   invalidate();
   return this;
 }
Пример #5
0
 @Override
 public TerminalPosition getCursorLocation(ComboBox<V> comboBox) {
   if (comboBox.isDropDownFocused()) {
     return new TerminalPosition(comboBox.getSize().getColumns() - 1, 0);
   } else {
     int textInputPosition = comboBox.getTextInputPosition();
     int textInputColumn =
         CJKUtils.getColumnWidth(comboBox.getText().substring(0, textInputPosition));
     return new TerminalPosition(textInputColumn - textVisibleLeftPosition, 0);
   }
 }
Пример #6
0
 @Override
 public void drawComponent(TextGUIGraphics graphics) {
   TerminalSize area = graphics.getSize();
   String absolutePath = directory.getAbsolutePath();
   int absolutePathLengthInColumns = CJKUtils.getColumnWidth(absolutePath);
   if (area.getColumns() < absolutePathLengthInColumns) {
     absolutePath = absolutePath.substring(absolutePathLengthInColumns - area.getColumns());
     absolutePath = "..." + absolutePath.substring(Math.min(absolutePathLengthInColumns, 3));
   }
   setText(absolutePath);
   super.drawComponent(graphics);
 }
Пример #7
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);
    }