org.jline.keymap.KeyMap Java Examples

The following examples show how to use org.jline.keymap.KeyMap. 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: SqlLineOpts.java    From sqlline with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
public void setMode(String mode) {
  final LineReader reader = sqlLine.getLineReader();
  if (reader == null || reader.getKeyMaps() == null) {
    return;
  }
  final Map<String, KeyMap<Binding>> keyMaps = reader.getKeyMaps();
  switch (mode) {
  case LineReader.EMACS:
  case SqlLineProperty.DEFAULT:
    set(BuiltInProperty.MODE, LineReader.EMACS);
    keyMaps.put(LineReader.MAIN, keyMaps.get(LineReader.EMACS));
    break;
  case "vi":
    set(BuiltInProperty.MODE, mode);
    keyMaps.put(LineReader.MAIN, keyMaps.get(LineReader.VIINS));
    break;
  default:
    sqlLine.error(
        sqlLine.loc("unknown-value", MODE.propertyName(),
            mode, Arrays.asList(LineReader.EMACS, "vi")));
  }
}
 
Example #2
Source File: CliTableResultView.java    From Flink-CEPplus with Apache License 2.0 5 votes vote down vote up
@Override
protected KeyMap<ResultTableOperation> getKeys() {
	final KeyMap<ResultTableOperation> keys = new KeyMap<>();
	keys.setAmbiguousTimeout(200); // make ESC quicker
	keys.bind(ResultTableOperation.QUIT, "q", "Q", esc(), ctrl('c'));
	keys.bind(ResultTableOperation.REFRESH, "r", "R", key(client.getTerminal(), Capability.key_f5));
	keys.bind(ResultTableOperation.UP, "w", "W", key(client.getTerminal(), Capability.key_up));
	keys.bind(ResultTableOperation.DOWN, "s", "S", key(client.getTerminal(), Capability.key_down));
	keys.bind(ResultTableOperation.LEFT, "a", "A", key(client.getTerminal(), Capability.key_left));
	keys.bind(ResultTableOperation.RIGHT, "d", "D", key(client.getTerminal(), Capability.key_right));
	keys.bind(ResultTableOperation.OPEN, "o", "O", "\r");
	keys.bind(ResultTableOperation.GOTO, "g", "G");
	keys.bind(ResultTableOperation.NEXT, "n", "N");
	keys.bind(ResultTableOperation.PREV, "p", "P");
	keys.bind(ResultTableOperation.LAST, "l", "L", key(client.getTerminal(), Capability.key_end));
	keys.bind(ResultTableOperation.INC_REFRESH, "+");
	keys.bind(ResultTableOperation.DEC_REFRESH, "-");
	return keys;
}
 
Example #3
Source File: CliInputView.java    From Flink-CEPplus with Apache License 2.0 5 votes vote down vote up
@Override
protected KeyMap<InputOperation> getKeys() {
	final KeyMap<InputOperation> keys = new KeyMap<>();
	keys.setUnicode(INSERT);
	keys.setAmbiguousTimeout(200); // make ESC quicker
	for (char i = 32; i < 256; i++) {
		keys.bind(INSERT, Character.toString(i));
	}
	keys.bind(LEFT, key(client.getTerminal(), Capability.key_left));
	keys.bind(RIGHT, key(client.getTerminal(), Capability.key_right));
	keys.bind(BACKSPACE, del());

	if (client.isPlainTerminal()) {
		keys.bind(ENTER, "\r", "$");
		keys.bind(QUIT, key(client.getTerminal(), Capability.key_exit), "!");
	} else {
		keys.bind(ENTER, "\r");
		keys.bind(QUIT, esc());
	}
	return keys;
}
 
Example #4
Source File: SqshConsole.java    From jsqsh with Apache License 2.0 5 votes vote down vote up
/**
 * Sets the editing mode for the console reader.  Logically supported names are
 * 'vi' and 'emacs', however any valid keymap supported by JLine3 is supported.
 *
 * @param name The name of the editing mode.
 */
public void setEditingMode(String name) {

    Map<String, KeyMap<Binding>> keyMaps = reader.getKeyMaps();
    if ("vi".equals(name)) {

        keyMaps.put(LineReader.MAIN, keyMaps.get(LineReader.VIINS));
    }
    else if ("vi-move".equals(name)) {

        keyMaps.put(LineReader.MAIN, keyMaps.get(LineReader.VICMD));
    }
    else if ("vi-insert".equals(name)) {

        keyMaps.put(LineReader.MAIN, keyMaps.get(LineReader.VIINS));
    }
    else if ("emacs".equals(name)) {

        keyMaps.put(LineReader.MAIN, keyMaps.get(LineReader.EMACS));
    }
    else {

        if (keyMaps.containsKey(name)) {

            keyMaps.put(LineReader.MAIN, keyMaps.get(name));
        }
    }
}
 
Example #5
Source File: CliInputView.java    From flink with Apache License 2.0 5 votes vote down vote up
@Override
protected KeyMap<InputOperation> getKeys() {
	final KeyMap<InputOperation> keys = new KeyMap<>();
	keys.setUnicode(INSERT);
	keys.setAmbiguousTimeout(200); // make ESC quicker
	for (char i = 32; i < 256; i++) {
		keys.bind(INSERT, Character.toString(i));
	}
	keys.bind(LEFT, key(client.getTerminal(), Capability.key_left));
	keys.bind(RIGHT, key(client.getTerminal(), Capability.key_right));
	keys.bind(BACKSPACE, del());

	if (client.isPlainTerminal()) {
		keys.bind(ENTER, "\r", "$");
		keys.bind(QUIT, key(client.getTerminal(), Capability.key_exit), "!");
	} else {
		keys.bind(ENTER, "\r");
		keys.bind(QUIT, esc());
	}
	return keys;
}
 
Example #6
Source File: CliTableResultView.java    From flink with Apache License 2.0 5 votes vote down vote up
@Override
protected KeyMap<ResultTableOperation> getKeys() {
	final KeyMap<ResultTableOperation> keys = new KeyMap<>();
	keys.setAmbiguousTimeout(200); // make ESC quicker
	keys.bind(ResultTableOperation.QUIT, "q", "Q", esc(), ctrl('c'));
	keys.bind(ResultTableOperation.REFRESH, "r", "R", key(client.getTerminal(), Capability.key_f5));
	keys.bind(ResultTableOperation.UP, "w", "W", key(client.getTerminal(), Capability.key_up));
	keys.bind(ResultTableOperation.DOWN, "s", "S", key(client.getTerminal(), Capability.key_down));
	keys.bind(ResultTableOperation.LEFT, "a", "A", key(client.getTerminal(), Capability.key_left));
	keys.bind(ResultTableOperation.RIGHT, "d", "D", key(client.getTerminal(), Capability.key_right));
	keys.bind(ResultTableOperation.OPEN, "o", "O", "\r");
	keys.bind(ResultTableOperation.GOTO, "g", "G");
	keys.bind(ResultTableOperation.NEXT, "n", "N");
	keys.bind(ResultTableOperation.PREV, "p", "P");
	keys.bind(ResultTableOperation.LAST, "l", "L", key(client.getTerminal(), Capability.key_end));
	keys.bind(ResultTableOperation.INC_REFRESH, "+");
	keys.bind(ResultTableOperation.DEC_REFRESH, "-");
	return keys;
}
 
Example #7
Source File: CliRowView.java    From flink with Apache License 2.0 5 votes vote down vote up
@Override
protected KeyMap<RowOperation> getKeys() {
	final KeyMap<RowOperation> keys = new KeyMap<>();
	keys.setAmbiguousTimeout(200); // make ESC quicker
	keys.bind(RowOperation.QUIT, "q", "Q", esc());
	keys.bind(RowOperation.UP, "w", "W", key(client.getTerminal(), Capability.key_up));
	keys.bind(RowOperation.DOWN, "s", "S", key(client.getTerminal(), Capability.key_down));
	keys.bind(RowOperation.LEFT, "a", "A", key(client.getTerminal(), Capability.key_left));
	keys.bind(RowOperation.RIGHT, "d", "D", key(client.getTerminal(), Capability.key_right));
	return keys;
}
 
Example #8
Source File: CliInputView.java    From flink with Apache License 2.0 5 votes vote down vote up
@Override
protected KeyMap<InputOperation> getKeys() {
	final KeyMap<InputOperation> keys = new KeyMap<>();
	keys.setUnicode(INSERT);
	keys.setAmbiguousTimeout(200); // make ESC quicker
	for (char i = 32; i < 256; i++) {
		keys.bind(INSERT, Character.toString(i));
	}
	keys.bind(LEFT, key(client.getTerminal(), Capability.key_left));
	keys.bind(RIGHT, key(client.getTerminal(), Capability.key_right));
	keys.bind(BACKSPACE, del());

	if (client.isPlainTerminal()) {
		keys.bind(ENTER, "\r", "$");
		keys.bind(QUIT, key(client.getTerminal(), Capability.key_exit), "!");
	} else {
		keys.bind(ENTER, "\r");
		keys.bind(QUIT, esc());
	}
	return keys;
}
 
Example #9
Source File: CliTableResultView.java    From flink with Apache License 2.0 5 votes vote down vote up
@Override
protected KeyMap<ResultTableOperation> getKeys() {
	final KeyMap<ResultTableOperation> keys = new KeyMap<>();
	keys.setAmbiguousTimeout(200); // make ESC quicker
	keys.bind(ResultTableOperation.QUIT, "q", "Q", esc(), ctrl('c'));
	keys.bind(ResultTableOperation.REFRESH, "r", "R", key(client.getTerminal(), Capability.key_f5));
	keys.bind(ResultTableOperation.UP, "w", "W", key(client.getTerminal(), Capability.key_up));
	keys.bind(ResultTableOperation.DOWN, "s", "S", key(client.getTerminal(), Capability.key_down));
	keys.bind(ResultTableOperation.LEFT, "a", "A", key(client.getTerminal(), Capability.key_left));
	keys.bind(ResultTableOperation.RIGHT, "d", "D", key(client.getTerminal(), Capability.key_right));
	keys.bind(ResultTableOperation.OPEN, "o", "O", "\r");
	keys.bind(ResultTableOperation.GOTO, "g", "G");
	keys.bind(ResultTableOperation.NEXT, "n", "N");
	keys.bind(ResultTableOperation.PREV, "p", "P");
	keys.bind(ResultTableOperation.LAST, "l", "L", key(client.getTerminal(), Capability.key_end));
	keys.bind(ResultTableOperation.INC_REFRESH, "+");
	keys.bind(ResultTableOperation.DEC_REFRESH, "-");
	return keys;
}
 
Example #10
Source File: QueryResultLogView.java    From samza with Apache License 2.0 5 votes vote down vote up
public void run() {
  KeyMap<Action> keyMap = bindActionKey();

  Action action = keyReader.readBinding(keyMap, null, true);
  while (action != null && keepRunning) {
    switch (action) {
      case QUIT:
        keepRunning = false;
        return;
      case SPACE:
        paused = !paused;
        break;
    }
    action = keyReader.readBinding(keyMap, null, true);
  }
}
 
Example #11
Source File: QueryResultLogView.java    From samza with Apache License 2.0 4 votes vote down vote up
private KeyMap<Action> bindActionKey() {
  KeyMap<Action> keyMap = new KeyMap<>();
  keyMap.bind(Action.QUIT, "Q", "q", ctrl('c'));
  keyMap.bind(Action.SPACE, " ");

  return keyMap;
}
 
Example #12
Source File: SqshConsole.java    From jsqsh with Apache License 2.0 4 votes vote down vote up
/**
 * @return The current line editing mode. This should be one of "vi" or "emacs"
 */
public String getEditingMode() {

    Map<String, KeyMap<Binding>> keyMaps = reader.getKeyMaps();
    KeyMap<Binding> currentKeyMap = keyMaps.get(LineReader.MAIN);
    if (currentKeyMap == keyMaps.get(LineReader.VICMD)
            || currentKeyMap == keyMaps.get(LineReader.VIOPP)) {

        return "vi";
    }
    else if (currentKeyMap == keyMaps.get(LineReader.VICMD)) {

        return "vi-move";
    }
    else if (currentKeyMap == keyMaps.get(LineReader.EMACS)) {

        return "emacs";
    }
    else {

        for (Map.Entry<String, KeyMap<Binding>> e : keyMaps.entrySet()) {

            if (e.getValue() == currentKeyMap) {

                return e.getKey();
            }
        }
    }

    return "unknown";
}
 
Example #13
Source File: CliChangelogResultView.java    From flink with Apache License 2.0 4 votes vote down vote up
@Override
protected KeyMap<ResultChangelogOperation> getKeys() {
	final KeyMap<ResultChangelogOperation> keys = new KeyMap<>();
	keys.setAmbiguousTimeout(200); // make ESC quicker
	keys.bind(ResultChangelogOperation.QUIT, "q", "Q", esc(), ctrl('c'));
	keys.bind(ResultChangelogOperation.REFRESH, "r", "R", key(client.getTerminal(), Capability.key_f5));
	keys.bind(ResultChangelogOperation.UP, "w", "W", key(client.getTerminal(), Capability.key_up));
	keys.bind(ResultChangelogOperation.DOWN, "s", "S", key(client.getTerminal(), Capability.key_down));
	keys.bind(ResultChangelogOperation.LEFT, "a", "A", key(client.getTerminal(), Capability.key_left));
	keys.bind(ResultChangelogOperation.RIGHT, "d", "D", key(client.getTerminal(), Capability.key_right));
	keys.bind(ResultChangelogOperation.OPEN, "o", "O", "\r");
	keys.bind(ResultChangelogOperation.INC_REFRESH, "+");
	keys.bind(ResultChangelogOperation.DEC_REFRESH, "-");
	return keys;
}
 
Example #14
Source File: CliRowView.java    From flink with Apache License 2.0 4 votes vote down vote up
@Override
protected KeyMap<RowOperation> getKeys() {
	final KeyMap<RowOperation> keys = new KeyMap<>();
	keys.setAmbiguousTimeout(200); // make ESC quicker
	keys.bind(RowOperation.QUIT, "q", "Q", esc());
	keys.bind(RowOperation.UP, "w", "W", key(client.getTerminal(), Capability.key_up));
	keys.bind(RowOperation.DOWN, "s", "S", key(client.getTerminal(), Capability.key_down));
	keys.bind(RowOperation.LEFT, "a", "A", key(client.getTerminal(), Capability.key_left));
	keys.bind(RowOperation.RIGHT, "d", "D", key(client.getTerminal(), Capability.key_right));
	return keys;
}
 
Example #15
Source File: CliChangelogResultView.java    From flink with Apache License 2.0 4 votes vote down vote up
@Override
protected KeyMap<ResultChangelogOperation> getKeys() {
	final KeyMap<ResultChangelogOperation> keys = new KeyMap<>();
	keys.setAmbiguousTimeout(200); // make ESC quicker
	keys.bind(ResultChangelogOperation.QUIT, "q", "Q", esc(), ctrl('c'));
	keys.bind(ResultChangelogOperation.REFRESH, "r", "R", key(client.getTerminal(), Capability.key_f5));
	keys.bind(ResultChangelogOperation.UP, "w", "W", key(client.getTerminal(), Capability.key_up));
	keys.bind(ResultChangelogOperation.DOWN, "s", "S", key(client.getTerminal(), Capability.key_down));
	keys.bind(ResultChangelogOperation.LEFT, "a", "A", key(client.getTerminal(), Capability.key_left));
	keys.bind(ResultChangelogOperation.RIGHT, "d", "D", key(client.getTerminal(), Capability.key_right));
	keys.bind(ResultChangelogOperation.OPEN, "o", "O", "\r");
	keys.bind(ResultChangelogOperation.INC_REFRESH, "+");
	keys.bind(ResultChangelogOperation.DEC_REFRESH, "-");
	return keys;
}
 
Example #16
Source File: CliRowView.java    From Flink-CEPplus with Apache License 2.0 4 votes vote down vote up
@Override
protected KeyMap<RowOperation> getKeys() {
	final KeyMap<RowOperation> keys = new KeyMap<>();
	keys.setAmbiguousTimeout(200); // make ESC quicker
	keys.bind(RowOperation.QUIT, "q", "Q", esc());
	keys.bind(RowOperation.UP, "w", "W", key(client.getTerminal(), Capability.key_up));
	keys.bind(RowOperation.DOWN, "s", "S", key(client.getTerminal(), Capability.key_down));
	keys.bind(RowOperation.LEFT, "a", "A", key(client.getTerminal(), Capability.key_left));
	keys.bind(RowOperation.RIGHT, "d", "D", key(client.getTerminal(), Capability.key_right));
	return keys;
}
 
Example #17
Source File: CliChangelogResultView.java    From Flink-CEPplus with Apache License 2.0 4 votes vote down vote up
@Override
protected KeyMap<ResultChangelogOperation> getKeys() {
	final KeyMap<ResultChangelogOperation> keys = new KeyMap<>();
	keys.setAmbiguousTimeout(200); // make ESC quicker
	keys.bind(ResultChangelogOperation.QUIT, "q", "Q", esc(), ctrl('c'));
	keys.bind(ResultChangelogOperation.REFRESH, "r", "R", key(client.getTerminal(), Capability.key_f5));
	keys.bind(ResultChangelogOperation.UP, "w", "W", key(client.getTerminal(), Capability.key_up));
	keys.bind(ResultChangelogOperation.DOWN, "s", "S", key(client.getTerminal(), Capability.key_down));
	keys.bind(ResultChangelogOperation.LEFT, "a", "A", key(client.getTerminal(), Capability.key_left));
	keys.bind(ResultChangelogOperation.RIGHT, "d", "D", key(client.getTerminal(), Capability.key_right));
	keys.bind(ResultChangelogOperation.OPEN, "o", "O", "\r");
	keys.bind(ResultChangelogOperation.INC_REFRESH, "+");
	keys.bind(ResultChangelogOperation.DEC_REFRESH, "-");
	return keys;
}
 
Example #18
Source File: CliView.java    From flink with Apache License 2.0 votes vote down vote up
protected abstract KeyMap<OP> getKeys(); 
Example #19
Source File: CliView.java    From Flink-CEPplus with Apache License 2.0 votes vote down vote up
protected abstract KeyMap<OP> getKeys(); 
Example #20
Source File: CliView.java    From flink with Apache License 2.0 votes vote down vote up
protected abstract KeyMap<OP> getKeys();