Skip to content

Commit

Permalink
Update JLine
Browse files Browse the repository at this point in the history
  • Loading branch information
electrum committed Sep 23, 2019
1 parent b142e8a commit f702af7
Show file tree
Hide file tree
Showing 20 changed files with 487 additions and 456 deletions.
12 changes: 0 additions & 12 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -749,18 +749,6 @@
<version>7.0.0.jre8</version>
</dependency>

<dependency>
<groupId>jline</groupId>
<artifactId>jline</artifactId>
<version>2.14.6</version>
<exclusions>
<exclusion>
<groupId>org.fusesource.jansi</groupId>
<artifactId>jansi</artifactId>
</exclusion>
</exclusions>
</dependency>

<dependency>
<groupId>org.jdbi</groupId>
<artifactId>jdbi</artifactId>
Expand Down
24 changes: 22 additions & 2 deletions presto-cli/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
<properties>
<air.main.basedir>${project.parent.basedir}</air.main.basedir>
<main-class>io.prestosql.cli.Presto</main-class>
<dep.jline.version>3.12.1</dep.jline.version>
</properties>

<dependencies>
Expand All @@ -27,6 +28,11 @@
<artifactId>presto-parser</artifactId>
</dependency>

<dependency>
<groupId>org.antlr</groupId>
<artifactId>antlr4-runtime</artifactId>
</dependency>

<dependency>
<groupId>io.airlift</groupId>
<artifactId>airline</artifactId>
Expand Down Expand Up @@ -69,8 +75,22 @@
</dependency>

<dependency>
<groupId>jline</groupId>
<artifactId>jline</artifactId>
<groupId>org.jline</groupId>
<artifactId>jline-reader</artifactId>
<version>${dep.jline.version}</version>
</dependency>

<dependency>
<groupId>org.jline</groupId>
<artifactId>jline-terminal</artifactId>
<version>${dep.jline.version}</version>
</dependency>

<dependency>
<groupId>org.jline</groupId>
<artifactId>jline-terminal-jna</artifactId>
<version>${dep.jline.version}</version>
<scope>runtime</scope>
</dependency>

<dependency>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
package io.prestosql.cli;

import io.prestosql.client.Warning;
import org.jline.utils.AttributedStringBuilder;

import java.util.List;
import java.util.OptionalInt;
Expand All @@ -22,13 +23,12 @@
import static io.prestosql.cli.ConsolePrinter.REAL_TERMINAL;
import static java.lang.String.format;
import static java.util.Objects.requireNonNull;
import static org.jline.utils.AttributedStyle.DEFAULT;
import static org.jline.utils.AttributedStyle.YELLOW;

abstract class AbstractWarningsPrinter
implements WarningsPrinter
{
private static final String WARNING_BEGIN = ((char) 27) + "[33m";
private static final String WARNING_END = ((char) 27) + "[39m";

private final OptionalInt maxWarnings;
private boolean hasProcessedWarnings;
private int processedWarnings;
Expand All @@ -42,7 +42,12 @@ private String getWarningMessage(Warning warning)
{
// If this is a real terminal color the warnings yellow
if (REAL_TERMINAL) {
return format("%sWARNING: %s%s", WARNING_BEGIN, warning.getMessage(), WARNING_END);
return new AttributedStringBuilder()
.style(DEFAULT.foreground(YELLOW))
.append("WARNING: ")
.append(warning.getMessage())
.style(DEFAULT)
.toAnsi();
}
return format("WARNING: %s", warning.getMessage());
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@
import com.google.common.collect.ImmutableList;
import com.google.common.collect.ImmutableSet;
import io.prestosql.client.Column;
import org.fusesource.jansi.AnsiString;

import java.io.IOException;
import java.io.Writer;
Expand All @@ -42,7 +41,8 @@
import static java.lang.Math.max;
import static java.lang.String.format;
import static java.util.Objects.requireNonNull;
import static jline.console.WCWidth.wcwidth;
import static org.jline.utils.AttributedString.stripAnsi;
import static org.jline.utils.WCWidth.wcwidth;

public class AlignedTablePrinter
implements OutputPrinter
Expand Down Expand Up @@ -224,12 +224,7 @@ static int maxLineLength(String s)

static int consoleWidth(String s)
{
return consoleWidth(new AnsiString(s));
}

private static int consoleWidth(AnsiString s)
{
CharSequence plain = s.getPlain();
CharSequence plain = stripAnsi(s);
int n = 0;
for (int i = 0; i < plain.length(); i++) {
n += max(wcwidth(plain.charAt(i)), 0);
Expand Down
21 changes: 9 additions & 12 deletions presto-cli/src/main/java/io/prestosql/cli/Completion.java
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,12 @@
package io.prestosql.cli;

import com.google.common.collect.ImmutableSet;
import jline.console.completer.Completer;
import jline.console.completer.StringsCompleter;
import org.jline.reader.Completer;
import org.jline.reader.impl.completer.StringsCompleter;

import java.util.Locale;
import java.util.Set;

import static java.util.Locale.ENGLISH;
import static java.util.stream.Collectors.toSet;

public final class Completion
Expand All @@ -44,14 +44,11 @@ private Completion() {}

public static Completer commandCompleter()
{
return new StringsCompleter(COMMANDS);
}

// TODO: create a case-insensitive completer
public static Completer lowerCaseCommandCompleter()
{
return new StringsCompleter(COMMANDS.stream()
.map(s -> s.toLowerCase(Locale.ENGLISH))
.collect(toSet()));
return new StringsCompleter(ImmutableSet.<String>builder()
.addAll(COMMANDS)
.addAll(COMMANDS.stream()
.map(value -> value.toLowerCase(ENGLISH))
.collect(toSet()))
.build());
}
}
Loading

0 comments on commit f702af7

Please sign in to comment.