Skip to content

Commit

Permalink
A few fixes in org.jline.example.Console
Browse files Browse the repository at this point in the history
  • Loading branch information
mattirn committed Jan 29, 2021
1 parent 18b4b4b commit 2aeff8e
Showing 1 changed file with 14 additions and 23 deletions.
37 changes: 14 additions & 23 deletions console/src/test/java/org/jline/example/Console.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2002-2020, the original author or authors.
* Copyright (c) 2002-2021, the original author or authors.
*
* This software is distributable under the BSD license. See the terms of the
* BSD license in the documentation provided with this software.
Expand All @@ -8,10 +8,10 @@
*/
package org.jline.example;

import java.io.IOException;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.util.*;
import java.util.function.Supplier;

import org.jline.console.ArgDesc;
import org.jline.console.CmdDesc;
Expand Down Expand Up @@ -90,9 +90,9 @@ private static class ExampleCommands implements CommandRegistry {
private AutopairWidgets autopairWidgets;
private final Map<String,CommandMethods> commandExecute = new HashMap<>();
private final Map<String,List<String>> commandInfo = new HashMap<>();
private Map<String,String> aliasCommand = new HashMap<>();
private final Map<String,String> aliasCommand = new HashMap<>();
private Exception exception;
private Printer printer;
private final Printer printer;

public ExampleCommands(Printer printer) {
this.printer = printer;
Expand Down Expand Up @@ -141,10 +141,7 @@ public List<String> commandInfo(String command) {
}

public boolean hasCommand(String command) {
if (commandExecute.containsKey(command) || aliasCommand.containsKey(command)) {
return true;
}
return false;
return commandExecute.containsKey(command) || aliasCommand.containsKey(command);
}

private String command(String name) {
Expand Down Expand Up @@ -311,16 +308,8 @@ private List<Completer> autosuggestionCompleter(String command) {
}
}

private static Path workDir() {
return Paths.get(System.getProperty("user.dir"));
}

public static void main(String[] args) throws IOException {
public static void main(String[] args) {
try {
String prompt = "prompt> ";
String rightPrompt = null;

boolean argument = true;
Completer completer = new ArgumentCompleter(new Completer() {
@Override
public void complete(LineReader reader, ParsedLine line, List<Candidate> candidates) {
Expand All @@ -340,15 +329,16 @@ public void complete(LineReader reader, ParsedLine line, List<Candidate> candida
Terminal terminal = TerminalBuilder.builder().build();
Parser parser = new DefaultParser();
//
// Command registeries
// Command registers
//
Builtins builtins = new Builtins(Console::workDir, null, null);
Supplier<Path> workDir = () -> Paths.get(System.getProperty("user.dir"));
Builtins builtins = new Builtins(workDir, null, null);
builtins.rename(Builtins.Command.TTOP, "top");
builtins.alias("zle", "widget");
builtins.alias("bindkey", "keymap");
DefaultPrinter printer = new DefaultPrinter(null);
ExampleCommands exampleCommands = new ExampleCommands(printer);
SystemRegistryImpl masterRegistry = new SystemRegistryImpl(parser, terminal, Console::workDir, null);
SystemRegistryImpl masterRegistry = new SystemRegistryImpl(parser, terminal, workDir, null);
masterRegistry.setCommandRegistries(exampleCommands, builtins);
masterRegistry.addCompleter(completer);
//
Expand All @@ -369,14 +359,15 @@ public void complete(LineReader reader, ParsedLine line, List<Candidate> candida
//
AutopairWidgets autopairWidgets = new AutopairWidgets(reader);
AutosuggestionWidgets autosuggestionWidgets = new AutosuggestionWidgets(reader);
TailTipWidgets tailtipWidgets = null;
TailTipWidgets tailtipWidgets;
boolean argument = true;
if (argument) {
tailtipWidgets = new TailTipWidgets(reader, compileTailTips(), 5, TipType.COMPLETER);
} else {
tailtipWidgets = new TailTipWidgets(reader, masterRegistry::commandDescription, 5, TipType.COMPLETER);
}
//
// complete command registeries
// complete command registers
//
builtins.setLineReader(reader);
exampleCommands.setLineReader(reader);
Expand All @@ -389,7 +380,7 @@ public void complete(LineReader reader, ParsedLine line, List<Candidate> candida
while (true) {
try {
masterRegistry.cleanUp();
String line = reader.readLine(prompt, rightPrompt, (MaskingCallback) null, null);
String line = reader.readLine("prompt> ", null, (MaskingCallback) null, null);
masterRegistry.execute(line);
}
catch (UserInterruptException e) {
Expand Down

0 comments on commit 2aeff8e

Please sign in to comment.