code: public static String formatDisplayListTerminalString(List<TerminalString> displayList, int termHeight, int termWidth) {
          if (displayList == null || displayList.size() < 1)
              return "";
          // make sure that termWidth is > 0
          if (termWidth < 1)
              termWidth = 80; // setting it to default
  
          int maxLength = 0;
          for (TerminalString completion : displayList)
              if (completion.getCharacters().length() > maxLength)
                  maxLength = completion.getCharacters().length();
  
          maxLength = maxLength + 2; // adding two spaces for better readability
          int numColumns = termWidth / maxLength;
          if (numColumns > displayList.size()) // we dont need more columns than items
              numColumns = displayList.size();
          if (numColumns < 1)
              numColumns = 1;
          int numRows = displayList.size() / numColumns;
  
          // add a row if we cant display all the items
          if (numRows * numColumns < displayList.size())
              numRows++;
  
          StringBuilder completionOutput = new StringBuilder();
          if (numRows > 1) {
              // create the completion listing
              for (int i = 0; i < numRows; i++) {
                  for (int c = 0; c < numColumns; c++) {
                      int fetch = i + (c * numRows);
                      if (fetch < displayList.size()) {
                          if (c == numColumns - 1) {  // No need to pad the right most column
                              completionOutput.append(displayList.get(i + (c * numRows)).toString());
                          } else {
                              completionOutput.append(padRight(maxLength
                                      + displayList.get(i + (c * numRows)).getANSILength(),
                                      displayList.get(i + (c * numRows)).toString()));
                          }
                      } else {
                          break;
                      }
                  }
                  completionOutput.append(Config.getLineSeparator());
              }
          }
          else {
              for (TerminalString ts : displayList) {
                  completionOutput.append(ts.toString()).append("  ");
              }
              completionOutput.append(Config.getLineSeparator());
          }
  
          return completionOutput.toString();
      }
docs: Format completions so that they look similar to GNU Readline
  
  @param displayList to format
  @param termHeight max height
  @param termWidth max width
  @return formatted string to be outputted