Skip to content

Commit

Permalink
Console example: fixed widgets enabling/disabling
Browse files Browse the repository at this point in the history
  • Loading branch information
mattirn committed May 31, 2020
1 parent d31b678 commit 1aa0bda
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 8 deletions.
12 changes: 6 additions & 6 deletions console/src/main/java/org/jline/console/Widgets.java
Original file line number Diff line number Diff line change
Expand Up @@ -382,19 +382,19 @@ public AutopairWidgets(LineReader reader, boolean addCurlyBrackets) {

public void enable() {
if (!enabled) {
executeWidget(AP_TOGGLE);
toggle();
}
}

public void disable() {
if (enabled) {
executeWidget(AP_TOGGLE);
toggle();
}
}

public boolean toggle() {
boolean before = enabled;
executeWidget(AP_TOGGLE);
toggleKeyBindings();
return !before;
}

Expand Down Expand Up @@ -822,7 +822,7 @@ public boolean isEnabled() {

public void disable() {
if (enabled) {
executeWidget(Widgets.TT_TOGGLE);
toggleKeyBindings();
}
}

Expand Down Expand Up @@ -1048,7 +1048,7 @@ public boolean toggleWindow() {
} else {
destroyDescription();
}
callWidget(LineReader.REDRAW_LINE);
executeWidget(LineReader.REDRAW_LINE);
return true;
}

Expand All @@ -1062,7 +1062,7 @@ public boolean toggleKeyBindings() {
initDescription(descriptionSize);
}
}
callWidget(LineReader.REDRAW_LINE);
executeWidget(LineReader.REDRAW_LINE);
return enabled;
}

Expand Down
8 changes: 6 additions & 2 deletions console/src/test/java/org/jline/example/Console.java
Original file line number Diff line number Diff line change
Expand Up @@ -233,6 +233,9 @@ private void sleep(CommandInput input) {

private void autopair(CommandInput input) {
try {
if (tailtipWidgets.isEnabled()) {
tailtipWidgets.disable();
}
terminal().writer().print("Autopair widgets are ");
if (autopairWidgets.toggle()) {
terminal().writer().println("enabled.");
Expand All @@ -254,7 +257,7 @@ private void autosuggestion(CommandInput input) {
autosuggestionWidgets.enable();
} else if (type.startsWith("tai")) {
autosuggestionWidgets.disable();
tailtipWidgets.enable();
autopairWidgets.disable();
if (argv.length > 1) {
String mode = argv[1].toLowerCase();
if (mode.startsWith("tai")) {
Expand All @@ -265,6 +268,7 @@ private void autosuggestion(CommandInput input) {
tailtipWidgets.setTipType(TipType.COMBINED);
}
}
tailtipWidgets.enable();
} else if (type.startsWith("com")) {
autosuggestionWidgets.disable();
tailtipWidgets.disable();
Expand Down Expand Up @@ -402,7 +406,7 @@ public void complete(LineReader reader, ParsedLine line, List<Candidate> candida
break;
}
catch (Exception e) {
masterRegistry.trace(e);
masterRegistry.trace(true, e);
}
}
masterRegistry.close();
Expand Down

0 comments on commit 1aa0bda

Please # to comment.