org.fusesource.jansi.Ansi.cursor()方法的使用及代码示例

x33g5p2x  于2022-01-15 转载在 其他  
字(10.0k)|赞(0)|评价(0)|浏览(123)

本文整理了Java中org.fusesource.jansi.Ansi.cursor()方法的一些代码示例,展示了Ansi.cursor()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Ansi.cursor()方法的具体详情如下:
包路径:org.fusesource.jansi.Ansi
类名称:Ansi
方法名:cursor

Ansi.cursor介绍

[英]Moves the cursor to row n, column m. The values are 1-based, and default to 1 (top left corner) if omitted. A sequence such as CSI ;5H is a synonym for CSI 1;5H as well as CSI 17;H is the same as CSI 17H and CSI 17;1H
[中]将光标移动到第n行、第m列。这些值基于1,如果省略,则默认为1(左上角)。序列,例如CSI;5H是CSI 1的同义词;5H以及CSI 17;H与CSI 17H和CSI 17相同;1H

代码示例

代码示例来源:origin: org.apache.pig/pig

@Override
protected void printClear() {
  AnsiConsole.systemInstall();
  Ansi ansi = Ansi.ansi();
  System.out.println( ansi.eraseScreen() );
  System.out.println( ansi.cursor(0, 0) );
  AnsiConsole.systemUninstall();
}

代码示例来源:origin: aliyun/aliyun-odps-console

/**
  * NOTE: Use this method only if isUnixTerminal is true.
  * Clear the screen, and the repositions the cursor to top left
  */
 public static void clearScreen(PrintStream out) {
  out.print(ansi().eraseScreen(Ansi.Erase.ALL).toString());
  out.print(ansi().cursor(1, 1).toString());
  out.flush();
 }
}

代码示例来源:origin: aliyun/aliyun-odps-console

/**
 * NOTE: Use this method only if isUnixTerminal is true.
 * Repositions the cursor to top left, and clear screen
 */
public static void resetScreen(PrintStream out) {
 out.print(ansi().cursor(1, 1).toString());
 out.print(ansi().eraseScreen(Ansi.Erase.FORWARD).toString());
 out.flush();
}

代码示例来源:origin: org.springframework.shell/spring-shell

@CliCommand(value = { "cls", "clear" }, help = "Clears the console")
public void clear() {
  AnsiConsole.out().print(ansi().eraseScreen().cursor(0, 0));
}

代码示例来源:origin: org.jboss.forge/forge-shell

@Override
public void clear()
{
 print(new Ansi().cursor(0, 0).eraseScreen().toString());
}

代码示例来源:origin: org.jledit/core

/**
 * Hides the editor screen and restore the {@link Terminal}.
 */
public void hide() {
  console.out().print("\33[" + 1 + ";" + terminal.getHeight() + ";r");
  //Erase screen doesn't behave well on windows.
  for (int l = 1; l <= terminal.getHeight(); l++) {
    console.out().print(ansi().cursor(l, 1));
    console.out().print(ansi().eraseLine(Erase.FORWARD));
  }
  console.out().print(ansi().cursor(1, 1));
  flush();
  try {
    terminal.restore();
  } catch (Exception e) {
    //noop
  }
}

代码示例来源:origin: org.jledit/core

@Override
public void restoreCursorPosition() {
  Coordinates coordinates = cursorPositions.pop();
  if (coordinates != null) {
    console.out().print(ansi().cursor(coordinates.getLine() + getHeaderSize(), coordinates.getColumn()));
  }
}

代码示例来源:origin: org.jledit/core

/**
 * Moves cursor to the end of the current line.
 */
public void moveToStartOfLine() {
  String currentLine = getContent(getLine());
  LinkedList<String> toDisplayLines = toDisplayLines(currentLine);
  int remainingLines = toDisplayLines.size() - getColumn() / terminal.getWidth();
  for (int r = 0; r < remainingLines; r++) {
    toDisplayLines.removeLast();
  }
  frameColumn = 1;
  delegate.moveToStartOfLine();
  for (int l = toDisplayLines.size() - 1; l >= 0; l--) {
    frameLine--;
    if (frameLine <= 0) {
      frameLine = 1;
      scrollDown(1);
      console.out().print(ansi().cursor(frameLine + getHeaderSize(), 1));
      displayText(toDisplayLines.get(l));
      console.out().print(ansi().cursor(frameLine + getHeaderSize(), getColumn()));
    }
  }
  console.out().print(ansi().cursor(frameLine + getHeaderSize(), frameColumn));
}

代码示例来源:origin: org.jledit/core

@Override
public void mergeLine() {
  String currentLine = getContent(getLine());
  frameColumn = currentLine.length() % terminal.getWidth() + 1;
  if (frameColumn == terminal.getWidth()) {
    frameColumn = 1;
    frameLine++;
  }
  delegate.mergeLine();
  redrawRestOfScreen();
  console.out().print(ansi().cursor(frameLine + getHeaderSize(), frameColumn));
}

代码示例来源:origin: org.jledit/core

/**
 * Repaints the whole screen.
 */
void repaintScreen() {
  int repaintLine = 1;
  console.out().print(ansi().eraseScreen(Erase.ALL));
  console.out().print(ansi().cursor(1, 1));
  console.out().print("\33[" + (getHeaderSize() + 1) + ";" + (terminal.getHeight() - getFooterSize()) + ";r");
  redrawHeader();
  redrawFooter();
  LinkedList<String> linesToDisplay = new LinkedList<String>();
  int l = 1;
  while (linesToDisplay.size() < terminal.getHeight() - getFooterSize()) {
    String currentLine = getContent(l++);
    linesToDisplay.addAll(toDisplayLines(currentLine));
  }
  for (int i = 0; i < terminal.getHeight() - getHeaderSize() - getFooterSize(); i++) {
    console.out().print(ansi().cursor(repaintLine + getHeaderSize(), 1));
    displayText(linesToDisplay.get(i));
    repaintLine++;
  }
  console.out().print(ansi().cursor(2, 1));
}

代码示例来源:origin: org.jledit/core

/**
 * Redraws the rest of the multi line.
 */
void redrawRestOfLine() {
  //The number of lines to reach the end of the frame.
  int maxLinesToRepaint = terminal.getHeight() - getFooterSize() - frameLine;
  LinkedList<String> toRepaintLines = new LinkedList<String>();
  String currentLine = getContent(getLine());
  toRepaintLines.addAll(toDisplayLines(currentLine));
  //Remove already shown lines
  int remainingLines = (getColumn() - 1) / terminal.getWidth();
  for (int r = 0; r < remainingLines; r++) {
    toRepaintLines.removeFirst();
  }
  saveCursorPosition();
  for (int l = 0; l < Math.min(maxLinesToRepaint, toRepaintLines.size()); l++) {
    console.out().print(ansi().cursor(frameLine + getHeaderSize() + l, 1));
    console.out().print(ansi().eraseLine(Erase.FORWARD));
    displayText(toRepaintLines.get(l));
  }
  restoreCursorPosition();
}

代码示例来源:origin: org.jledit/core

frameLine = 1;
  scrollDown(1);
  console.out().print(ansi().cursor(frameLine + getHeaderSize(), 1));
  displayText(toDisplayLines.get(l));
  console.out().print(ansi().cursor(frameLine + getHeaderSize(), getColumn()));
console.out().print(ansi().cursor(frameLine + getHeaderSize(), frameColumn));

代码示例来源:origin: org.jledit/core

/**
 * Moves cursor to the end of the current line.
 */
public void moveToEndOfLine() {
  String currentLine = getContent(getLine());
  LinkedList<String> toDisplayLines = toDisplayLines(currentLine);
  int remainingLines = getColumn() / terminal.getWidth() + 1;
  for (int r = 0; r < remainingLines; r++) {
    toDisplayLines.removeFirst();
  }
  frameColumn = currentLine.length();
  delegate.moveToEndOfLine();
  for (int l = 0; l < toDisplayLines.size(); l++) {
    frameLine++;
    frameColumn -= terminal.getWidth();
    if (frameLine >= terminal.getHeight() - getFooterSize()) {
      frameLine = terminal.getHeight() - getHeaderSize() - getFooterSize();
      scrollUp(1);
      console.out().print(ansi().cursor(frameLine + getHeaderSize(), 1));
      displayText(toDisplayLines.get(l));
      console.out().print(ansi().cursor(frameLine + getHeaderSize(), getColumn()));
    }
  }
  console.out().print(ansi().cursor(frameLine + getHeaderSize(), frameColumn));
}

代码示例来源:origin: org.jledit/core

frameLine = terminal.getHeight() - getHeaderSize() - getFooterSize();
  scrollUp(1);
  console.out().print(ansi().cursor(frameLine + getHeaderSize(), 1));
  displayText(toDisplayLines.get(l));
  console.out().print(ansi().cursor(frameLine + getHeaderSize(), getColumn()));
console.out().print(ansi().cursor(frameLine + getHeaderSize(), frameColumn));

代码示例来源:origin: org.jledit/core

@Override
public void newLine() {
  delegate.newLine();
  console.out().print(ansi().eraseLine(Erase.FORWARD));
  frameColumn = 1;
  frameLine++;
  if (frameLine > terminal.getHeight() - getHeaderSize() - getFooterSize()) {
    frameLine = terminal.getHeight() - getHeaderSize() - getFooterSize();
    scrollUp(1);
  }
  redrawRestOfScreen();
  console.out().print(ansi().cursor(frameLine + getHeaderSize(), frameColumn));
}

代码示例来源:origin: org.jledit/core

/**
 * Refreshes the footer that displays the current line and column.
 */
public void redrawFooter() {
  saveCursorPosition();
  Ansi style = ansi();
  if (getTheme().getFooterBackground() != null) {
    style.bg(getTheme().getFooterBackground());
  }
  if (getTheme().getFooterForeground() != null) {
    style.fg(getTheme().getFooterForeground());
  }
  getConsole().out().print(style);
  getConsole().out().print(ansi().cursor(getTerminal().getHeight() + 1 - getFooterSize(), 1).eraseLine(Ansi.Erase.FORWARD));
  for (int i = 1; i <= helpLines.size(); i++) {
    String helpLine = helpLines.get(i - 1);
    int startColumn = (getTerminal().getWidth() - helpLine.length()) / 2;
    getConsole().out().print(ansi().cursor(getTerminal().getHeight() + 1 - getFooterSize() + i, 1).eraseLine(Ansi.Erase.FORWARD));
    getConsole().out().print(ansi().cursor(getTerminal().getHeight() + 1 - getFooterSize() + i, startColumn));
    getConsole().out().print(helpLine);
  }
  getConsole().out().print(ansi().reset());
  restoreCursorPosition();
}

代码示例来源:origin: org.jledit/core

public void redrawHeader() {
  saveCursorPosition();
  getConsole().out().print(ansi().cursor(1, 1));
  Ansi style = ansi();
  if (getTheme().getHeaderBackground() != null) {
    style.bg(getTheme().getHeaderBackground());
  }
  if (getTheme().getHeaderForeground() != null) {
    style.fg(getTheme().getHeaderForeground());
  }
  String textCoords = "L:" + getLine() + " C:" + getColumn();
  int displayFileLength = getTerminal().getWidth() - getTitle().length() - textCoords.length() - 1;
  getConsole().out().print(style.a(getTitle()).a(":").a(Strings.tryToTrimToSize(getDisplayAs(), displayFileLength)).a(isDirty() ? DIRTY_SIGN : "").eraseLine(Ansi.Erase.FORWARD));
  getConsole().out().print(ansi().cursor(1, getTerminal().getWidth() - textCoords.length()));
  getConsole().out().print(ansi().a(textCoords).reset());
  getConsole().out().print(ansi().cursor(getTerminal().getHeight(), 1));
  restoreCursorPosition();
}

代码示例来源:origin: org.jledit/core

frameLine = terminal.getHeight() - getHeaderSize() - getFooterSize();
      scrollUp(1);
      console.out().print(ansi().cursor(frameLine + getHeaderSize(), 1));
      displayText(toDisplayLines.get(0));
      console.out().print(ansi().cursor(frameLine + getHeaderSize(), getColumn()));
console.out().print(ansi().cursor(frameLine + getHeaderSize(), frameColumn));

代码示例来源:origin: org.jledit/core

public String readLine(String message) throws IOException {
  String result = null;
  saveCursorPosition();
  Ansi style = ansi();
  if (getTheme().getPromptBackground() != null) {
    style.bg(getTheme().getPromptBackground());
  }
  if (getTheme().getPromptForeground() != null) {
    style.fg(getTheme().getPromptForeground());
  }
  for (int i = 1; i <= getFooterSize(); i++) {
    console.out().print(ansi().cursor(terminal.getHeight() - getFooterSize() + i, 1));
    console.out().print(style.eraseLine(Ansi.Erase.FORWARD));
  }
  console.out().print(ansi().cursor(terminal.getHeight(), 1));
  console.out().print(ansi().cursor(terminal.getHeight(), 1));
  console.out().print(style.a(message).bold().eraseLine(Ansi.Erase.FORWARD));
  flush();
  try {
    result = readLine();
  } finally {
    console.out().print(ansi().reset());
    restoreCursorPosition();
    redrawFooter();
  }
  return result;
}

代码示例来源:origin: org.jledit/core

console.out().print(ansi().cursor(frameLine + getHeaderSize(), frameColumn));

相关文章