Skip to content

Commit

Permalink
less command: added repaint operations
Browse files Browse the repository at this point in the history
  • Loading branch information
mattirn committed Jul 26, 2019
1 parent f7eaabc commit 00891d4
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 5 deletions.
21 changes: 16 additions & 5 deletions builtins/src/main/java/org/jline/builtins/Less.java
Original file line number Diff line number Diff line change
Expand Up @@ -434,6 +434,15 @@ else if (buffer.length() > 0 && (buffer.charAt(0) == '/' || buffer.charAt(0) ==
openSource();
}
break;
case REPAINT:
size.copy(terminal.getSize());
display.clear();
break;
case REPAINT_AND_DISCARD:
message = null;
size.copy(terminal.getSize());
display.clear();
break;
case HELP:
help();
break;
Expand Down Expand Up @@ -780,7 +789,6 @@ private void help() throws IOException {
Operation op = null;
do {
checkInterrupted();

op = bindingReader.readBinding(keys, null, false);
if (op != null) {
switch (op) {
Expand All @@ -800,12 +808,12 @@ private void help() throws IOException {
ssp.restore(null);
}
}

protected void openSource() throws IOException {
boolean firstOpening = true;
boolean wasOpen = false;
if (reader != null) {
reader.close();
firstOpening = false;
wasOpen = true;
}
boolean open = false;
boolean displayMessage = false;
Expand All @@ -826,6 +834,7 @@ protected void openSource() throws IOException {
firstLineToDisplay = 0;
firstColumnToDisplay = 0;
offsetInLine = 0;
display.clear();
open = true;
if (displayMessage) {
AttributedStringBuilder asb = new AttributedStringBuilder();
Expand All @@ -840,7 +849,7 @@ protected void openSource() throws IOException {
if (sourceIdx > sources.size() - 1) {
sourceIdx = sources.size() - 1;
}
if (!firstOpening) {
if (wasOpen) {
throw exp;
} else {
AttributedStringBuilder asb = new AttributedStringBuilder();
Expand Down Expand Up @@ -1208,6 +1217,8 @@ private void bindKeys(KeyMap<Operation> map) {
map.bind(Operation.RIGHT_ONE_HALF_SCREEN, alt(')'), key(terminal, Capability.key_right));
map.bind(Operation.LEFT_ONE_HALF_SCREEN, alt('('), key(terminal, Capability.key_left));
map.bind(Operation.FORWARD_FOREVER, "F");
map.bind(Operation.REPAINT, "r", ctrl('R'), ctrl('L'));
map.bind(Operation.REPAINT_AND_DISCARD, "R");
map.bind(Operation.REPEAT_SEARCH_FORWARD, "n");
map.bind(Operation.REPEAT_SEARCH_BACKWARD, "N");
map.bind(Operation.REPEAT_SEARCH_FORWARD_SPAN_FILES, alt('n'));
Expand Down
2 changes: 2 additions & 0 deletions builtins/src/main/resources/org/jline/builtins/less-help.txt
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@
ESC-( LeftArrow * Right one half screen width (or N positions).
g < ESC-< * Go to first line in file (or line N).
G > ESC-> * Go to last line in file (or line N).
r ^R ^L Repaint screen.
R Repaint screen, discarding buffered input.
---------------------------------------------------
Default "window" is the screen height.
Default "half-window" is half of the screen height.
Expand Down

1 comment on commit 00891d4

@mattirn
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.