Java Code Examples for io.termd.core.readline.Readline#Interaction

The following examples show how to use io.termd.core.readline.Readline#Interaction . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: ReverseFunction.java    From termd with Apache License 2.0 6 votes vote down vote up
@Override
public void apply(Readline.Interaction interaction) {
  int[] points = interaction.buffer().toArray();

  // Reverse the buffer
  for (int i = 0; i < points.length / 2; i++) {
    int temp = points[i];
    points[i] = points[points.length - 1 - i];
    points[points.length - 1 - i] = temp;
  }

  // Refresh buffer
  interaction.refresh(new LineBuffer().insert(points));

  // Resume readline
  interaction.resume();
}
 
Example 2
Source File: PreviousHistory.java    From termd with Apache License 2.0 6 votes vote down vote up
@Override
public void apply(Readline.Interaction interaction) {
  List<int[]> history = interaction.history();
  if (history.size() > 0) {
    int curr = interaction.getHistoryIndex();
    int next = curr + 1;
    if (next < history.size()) {
      if (curr == -1) {
        int[] tmp = interaction.buffer().toArray();
        interaction.data().put("abc", tmp);
      }
      int[] line = history.get(next);
      interaction.refresh(new LineBuffer().insert(line));
      interaction.setHistoryIndex(next);
    }
  }
  interaction.resume();
}
 
Example 3
Source File: NextHistory.java    From termd with Apache License 2.0 6 votes vote down vote up
@Override
public void apply(Readline.Interaction interaction) {
  List<int[]> history = interaction.history();
  int curr = interaction.getHistoryIndex();
  if (curr >= 0) {
    int next = curr - 1;
    int[] line;
    if (next == -1) {
      line = (int[]) interaction.data().get("abc");
    } else {
      line = history.get(next);
    }
    interaction.refresh(new LineBuffer().insert(line));
    interaction.setHistoryIndex(next);
  }
  interaction.resume();
}
 
Example 4
Source File: ReverseFunction.java    From termd with Apache License 2.0 6 votes vote down vote up
@Override
public void apply(Readline.Interaction interaction) {
  int[] points = interaction.buffer().toArray();

  // Reverse the buffer
  for (int i = 0; i < points.length / 2; i++) {
    int temp = points[i];
    points[i] = points[points.length - 1 - i];
    points[points.length - 1 - i] = temp;
  }

  // Refresh buffer
  interaction.refresh(new LineBuffer().insert(points));

  // Resume readline
  interaction.resume();
}
 
Example 5
Source File: BackwardKillLine.java    From termd with Apache License 2.0 5 votes vote down vote up
@Override
public void apply(Readline.Interaction interaction) {
    LineBuffer buf = interaction.buffer().copy();
    buf.delete(-buf.getCursor());
    interaction.refresh(buf);
    interaction.resume();
}
 
Example 6
Source File: KillLine.java    From termd with Apache License 2.0 5 votes vote down vote up
@Override
public void apply(Readline.Interaction interaction) {
  LineBuffer buf = interaction.buffer().copy();
  buf.setSize(buf.getCursor());
  interaction.refresh(buf);
  interaction.resume();
}
 
Example 7
Source File: BackwardKillWord.java    From termd with Apache License 2.0 5 votes vote down vote up
@Override
public void apply(Readline.Interaction interaction) {
  LineBuffer buf = interaction.buffer().copy();
  int cursor = BackwardWord.findPos(buf);
  buf.delete(cursor - buf.getCursor());
  interaction.refresh(buf);
  interaction.resume();
}
 
Example 8
Source File: ForwardChar.java    From termd with Apache License 2.0 5 votes vote down vote up
@Override
public void apply(Readline.Interaction interaction) {
  LineBuffer buf = interaction.buffer().copy();
  buf.moveCursor(1);
  interaction.refresh(buf);
  interaction.resume();
}
 
Example 9
Source File: BackwardChar.java    From termd with Apache License 2.0 5 votes vote down vote up
@Override
public void apply(Readline.Interaction interaction) {
  LineBuffer buf = interaction.buffer().copy();
  buf.moveCursor(-1);
  interaction.refresh(buf);
  interaction.resume();
}
 
Example 10
Source File: DeleteChar.java    From termd with Apache License 2.0 5 votes vote down vote up
@Override
public void apply(Readline.Interaction interaction) {
  LineBuffer buf = interaction.buffer().copy();
  buf.delete(1);
  interaction.refresh(buf);
  interaction.resume();
}
 
Example 11
Source File: BackwardChar.java    From termd with Apache License 2.0 5 votes vote down vote up
@Override
public void apply(Readline.Interaction interaction) {
  LineBuffer buf = interaction.buffer().copy();
  buf.moveCursor(-1);
  interaction.refresh(buf);
  interaction.resume();
}
 
Example 12
Source File: BackwardDeleteChar.java    From termd with Apache License 2.0 5 votes vote down vote up
@Override
public void apply(Readline.Interaction interaction) {
  LineBuffer buf = interaction.buffer().copy();
  buf.delete(-1);
  interaction.refresh(buf);
  interaction.resume();
}
 
Example 13
Source File: EndOfLine.java    From termd with Apache License 2.0 5 votes vote down vote up
@Override
public void apply(Readline.Interaction interaction) {
  LineBuffer buf = interaction.buffer().copy();
  buf.setCursor(buf.getSize());
  interaction.refresh(buf);
  interaction.resume();
}
 
Example 14
Source File: ForwardChar.java    From termd with Apache License 2.0 5 votes vote down vote up
@Override
public void apply(Readline.Interaction interaction) {
  LineBuffer buf = interaction.buffer().copy();
  buf.moveCursor(1);
  interaction.refresh(buf);
  interaction.resume();
}
 
Example 15
Source File: BackwardDeleteChar.java    From termd with Apache License 2.0 5 votes vote down vote up
@Override
public void apply(Readline.Interaction interaction) {
  LineBuffer buf = interaction.buffer().copy();
  buf.delete(-1);
  interaction.refresh(buf);
  interaction.resume();
}
 
Example 16
Source File: DeleteChar.java    From termd with Apache License 2.0 5 votes vote down vote up
@Override
public void apply(Readline.Interaction interaction) {
  LineBuffer buf = interaction.buffer().copy();
  buf.delete(1);
  interaction.refresh(buf);
  interaction.resume();
}
 
Example 17
Source File: BackwardWord.java    From termd with Apache License 2.0 5 votes vote down vote up
@Override
public void apply(Readline.Interaction interaction) {
  LineBuffer buf = interaction.buffer().copy();
  buf.setCursor(findPos(buf));
  interaction.refresh(buf);
  interaction.resume();
}
 
Example 18
Source File: BackwardKillWord.java    From termd with Apache License 2.0 5 votes vote down vote up
@Override
public void apply(Readline.Interaction interaction) {
  LineBuffer buf = interaction.buffer().copy();
  int cursor = BackwardWord.findPos(buf);
  buf.delete(cursor - buf.getCursor());
  interaction.refresh(buf);
  interaction.resume();
}
 
Example 19
Source File: BeginningOfLine.java    From termd with Apache License 2.0 4 votes vote down vote up
@Override
public void apply(Readline.Interaction interaction) {
  interaction.refresh(interaction.buffer().copy().setCursor(0));
  interaction.resume();
}
 
Example 20
Source File: BeginningOfLine.java    From termd with Apache License 2.0 4 votes vote down vote up
@Override
public void apply(Readline.Interaction interaction) {
  interaction.refresh(interaction.buffer().copy().setCursor(0));
  interaction.resume();
}