Skip to content

Commit

Permalink
Widget refactoring and fixed formatting
Browse files Browse the repository at this point in the history
  • Loading branch information
mattirn committed Oct 12, 2019
1 parent ca0278a commit 6535be3
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 24 deletions.
32 changes: 16 additions & 16 deletions builtins/src/main/java/org/jline/builtins/Widgets.java
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ public boolean apply() {
}

public void callWidget(String name) {
reader.callWidget(name);
reader.callWidget("." + name);
}

public KeyMap<Binding> getKeyMap(String name) {
Expand Down Expand Up @@ -239,15 +239,15 @@ public boolean toggleKeyBindings() {
if (autopair) {
defaultBindings();
} else {
autopairBindings();
customBindings();
}
return autopair;
}
/*
* key bindings...
*
*/
private void autopairBindings() {
private void customBindings() {
KeyMap<Binding> map = getKeyMap(LineReader.MAIN);
for (Map.Entry<String, String> p: pairs.entrySet()) {
map.bind(new Reference("_autopair-insert"), p.getKey());
Expand Down Expand Up @@ -378,11 +378,11 @@ public AutosuggestionWidgets(LineReader reader) {
for (Map.Entry<String, Binding> bound : map.getBoundKeys().entrySet()) {
if (bound.getValue() instanceof Reference) {
Reference w = (Reference)bound.getValue();
if (w.name().equals(LineReader.FORWARD_CHAR)){
if (w.name().equals(LineReader.FORWARD_CHAR)) {
addKeySequence(w, bound.getKey());
} else if (w.name().equals(LineReader.END_OF_LINE)){
} else if (w.name().equals(LineReader.END_OF_LINE)) {
addKeySequence(w, bound.getKey());
} else if (w.name().equals(LineReader.FORWARD_WORD)){
} else if (w.name().equals(LineReader.FORWARD_WORD)) {
addKeySequence(w, bound.getKey());
}
}
Expand Down Expand Up @@ -427,7 +427,7 @@ public boolean toggleKeyBindings() {
if (autosuggestion) {
defaultBindings();
} else {
autosuggestionBindings();
customBindings();
}
return autosuggestion;
}
Expand All @@ -446,7 +446,7 @@ private boolean accept(String widget) {
* key bindings...
*
*/
public void autosuggestionBindings() {
public void customBindings() {
if (autosuggestion) {
return;
}
Expand Down Expand Up @@ -525,13 +525,13 @@ public TailTipWidgets(LineReader reader, Map<String,List<ArgDesc>> tailTips, int
for (Map.Entry<String, Binding> bound : map.getBoundKeys().entrySet()) {
if (bound.getValue() instanceof Reference) {
Reference w = (Reference)bound.getValue();
if (w.name().equals(LineReader.ACCEPT_LINE)){
if (w.name().equals(LineReader.ACCEPT_LINE)) {
addKeySequence(w, bound.getKey());
} else if (w.name().equals(LineReader.BACKWARD_DELETE_CHAR)){
} else if (w.name().equals(LineReader.BACKWARD_DELETE_CHAR)) {
addKeySequence(w, bound.getKey());
} else if (w.name().equals(LineReader.DELETE_CHAR)){
} else if (w.name().equals(LineReader.DELETE_CHAR)) {
addKeySequence(w, bound.getKey());
} else if (w.name().equals(LineReader.EXPAND_OR_COMPLETE)){
} else if (w.name().equals(LineReader.EXPAND_OR_COMPLETE)) {
addKeySequence(w, bound.getKey());
}
}
Expand Down Expand Up @@ -579,7 +579,7 @@ public boolean tailtipComplete() {
}

public boolean tailtipAcceptLine() {
if (tipType != TipType.TAIL_TIP){
if (tipType != TipType.TAIL_TIP) {
setSuggestionType(SuggestionType.COMPLETER);
}
clearDescription();
Expand Down Expand Up @@ -631,7 +631,7 @@ private boolean doTailTip(String widget) {
}
} else {
setTailTip("");
if (tipType != TipType.TAIL_TIP){
if (tipType != TipType.TAIL_TIP) {
setSuggestionType(SuggestionType.COMPLETER);
}
}
Expand Down Expand Up @@ -666,7 +666,7 @@ public boolean toggleKeyBindings() {
if (autosuggestion) {
defaultBindings();
} else {
autosuggestionBindings();
customBindings();
}
return autosuggestion;
}
Expand All @@ -675,7 +675,7 @@ public boolean toggleKeyBindings() {
* key bindings...
*
*/
public void autosuggestionBindings() {
public void customBindings() {
if (autosuggestion) {
return;
}
Expand Down
4 changes: 2 additions & 2 deletions builtins/src/test/java/org/jline/example/Example.java
Original file line number Diff line number Diff line change
Expand Up @@ -491,10 +491,10 @@ else if ("autosuggestion".equals(pl.word())) {
String type = pl.words().get(1).toLowerCase();
if (type.startsWith("his")) {
tailtipWidgets.defaultBindings();
autosuggestionWidgets.autosuggestionBindings();
autosuggestionWidgets.customBindings();
} else if (type.startsWith("tai")) {
autosuggestionWidgets.defaultBindings();
tailtipWidgets.autosuggestionBindings();
tailtipWidgets.customBindings();
tailtipWidgets.setDescriptionSize(5);
if (pl.words().size() > 2) {
String mode = pl.words().get(2).toLowerCase();
Expand Down
12 changes: 6 additions & 6 deletions reader/src/main/java/org/jline/reader/impl/LineReaderImpl.java
Original file line number Diff line number Diff line change
Expand Up @@ -341,7 +341,7 @@ public SuggestionType getAutosuggestion() {
}

@Override
public String getTailTip(){
public String getTailTip() {
return tailTip;
}

Expand Down Expand Up @@ -727,12 +727,12 @@ public String readLine(String prompt, String rightPrompt, MaskingCallback maskin
}
}

private boolean isTerminalDumb(){
private boolean isTerminalDumb() {
return Terminal.TYPE_DUMB.equals(terminal.getType())
|| Terminal.TYPE_DUMB_COLOR.equals(terminal.getType());
}

private void doDisplay(){
private void doDisplay() {
// Cache terminal size for the duration of the call to readLine()
// It will eventually be updated with WINCH signals
size.copy(terminal.getBufferSize());
Expand Down Expand Up @@ -2178,7 +2178,7 @@ protected boolean insertClose(String s) {
return true;
}

private void removeIndentation(){
private void removeIndentation() {
int indent = getInt(INDENTATION, DEFAULT_INDENTATION);
if (indent > 0) {
buf.move(-1);
Expand Down Expand Up @@ -3994,13 +3994,13 @@ public AttributedString getDisplayedBufferWithPrompts(List<AttributedString> sec
&& (!lastBinding.equals("\t") || buf.prevChar() == ' ')) {
clearChoices();
listChoices(true);
} else if (!lastBinding.equals("\t")){
} else if (!lastBinding.equals("\t")) {
clearChoices();
clearStatus();
}
} else if (autosuggestion == SuggestionType.TAIL_TIP) {
if (buf.length() == buf.cursor()) {
if (!lastBinding.equals("\t")){
if (!lastBinding.equals("\t") || buf.prevChar() == ' ') {
clearChoices();
}
AttributedStringBuilder sb = new AttributedStringBuilder();
Expand Down

0 comments on commit 6535be3

Please sign in to comment.