Skip to content

Commit

Permalink
Minor fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
gnodet committed Jan 17, 2024
1 parent 7a6f6f1 commit 49bcaa2
Show file tree
Hide file tree
Showing 5 changed files with 20 additions and 10 deletions.
10 changes: 9 additions & 1 deletion graal/src/main/java/org/jline/demo/graal/Graal.java
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
import java.nio.file.Paths;
import java.util.*;
import java.util.function.Supplier;
import java.util.logging.LogManager;

import org.jline.builtins.ConfigurationPath;
import org.jline.console.impl.Builtins;
Expand All @@ -25,6 +26,7 @@
import org.jline.terminal.Terminal;
import org.jline.terminal.Terminal.Signal;
import org.jline.terminal.TerminalBuilder;
import org.jline.terminal.spi.TerminalExt;
import org.jline.utils.OSUtils;
import org.jline.widget.TailTipWidgets;
import org.jline.widget.TailTipWidgets.TipType;
Expand All @@ -34,6 +36,11 @@ public class Graal {

public static void main(String[] args) {
try {
// Init log
String fname = System.getProperty("java.util.logging.config.file");
if (fname != null) {
LogManager.getLogManager().readConfiguration();
}
Supplier<Path> workDir = () -> Paths.get(System.getProperty("user.dir"));
//
// Parser & Terminal
Expand Down Expand Up @@ -95,7 +102,8 @@ public static void main(String[] args) {
//
// REPL-loop
//
System.out.println(terminal.getName() + ": " + terminal.getType());
System.out.println(terminal.getName() + ": " + terminal.getType() + ", provider="
+ ((TerminalExt) terminal).getProvider().name());
while (true) {
try {
systemRegistry.cleanUp(); // reset output streams
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
import org.jline.terminal.spi.Pty;
import org.jline.terminal.spi.SystemStream;
import org.jline.terminal.spi.TerminalProvider;
import org.jline.utils.Log;
import org.jline.utils.OSUtils;

public class JniTerminalProvider implements TerminalProvider {
Expand Down Expand Up @@ -137,6 +138,7 @@ public boolean isSystemStream(SystemStream stream) {
return isPosixSystemStream(stream);
}
} catch (Throwable t) {
Log.debug("Exception while checking system stream (this may disable the JNI provider)", t);
return false;
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -460,9 +460,9 @@ private Terminal doBuild() throws IOException {
if (terminal == null && (forceDumb || dumb == null || dumb)) {
if (!forceDumb && dumb == null) {
if (Log.isDebugEnabled()) {
Log.warn("input is tty: {}", system.get(SystemStream.Input));
Log.warn("output is tty: {}", system.get(SystemStream.Output));
Log.warn("error is tty: {}", system.get(SystemStream.Error));
Log.warn("input is tty: " + system.get(SystemStream.Input));
Log.warn("output is tty: " + system.get(SystemStream.Output));
Log.warn("error is tty: " + system.get(SystemStream.Error));
Log.warn("Creating a dumb terminal", exception);
} else {
Log.warn(
Expand Down
2 changes: 1 addition & 1 deletion terminal/src/main/java/org/jline/utils/Log.java
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ static LogRecord createRecord(final Level level, final Object... messages) {
ByteArrayOutputStream baos = new ByteArrayOutputStream();
PrintStream ps = new PrintStream(baos);
for (int i = 0; i < messages.length; i++) {
// Special handling for the last message if its a throwable, render its stack on the next line
// Special handling for the last message if it's a throwable, render its stack on the next line
if (i + 1 == messages.length && messages[i] instanceof Throwable) {
cause = (Throwable) messages[i];
} else {
Expand Down
10 changes: 5 additions & 5 deletions terminal/src/main/java/org/jline/utils/Status.java
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@

public class Status {

protected final AbstractTerminal terminal;
protected final Terminal terminal;
protected final boolean supported;
protected List<AttributedString> oldLines = Collections.emptyList();
protected List<AttributedString> linesToRestore = Collections.emptyList();
Expand All @@ -40,7 +40,7 @@ public static Status getStatus(Terminal terminal, boolean create) {
}

@SuppressWarnings("this-escape")
public Status(AbstractTerminal terminal) {
public Status(Terminal terminal) {
this.terminal = Objects.requireNonNull(terminal, "terminal can not be null");
this.supported = terminal.getStringCapability(Capability.change_scroll_region) != null
&& terminal.getStringCapability(Capability.save_cursor) != null
Expand Down Expand Up @@ -127,8 +127,8 @@ public void update(List<AttributedString> lines) {
if (oldLines.equals(lines) && !force) {
return;
}
int statusSize = lines.size() + (lines.size() == 0 ? 0 : border);
int nb = statusSize - oldLines.size() - (oldLines.size() == 0 ? 0 : border);
int statusSize = lines.size() + (lines.isEmpty() ? 0 : border);
int nb = statusSize - oldLines.size() - (oldLines.isEmpty() ? 0 : border);
if (nb > 0) {
for (int i = 0; i < nb; i++) {
terminal.puts(Capability.cursor_down);
Expand All @@ -145,7 +145,7 @@ public void update(List<AttributedString> lines) {
terminal.puts(Capability.clr_eol);
}
}
if (border == 1 && lines.size() > 0) {
if (border == 1 && !lines.isEmpty()) {
terminal.puts(Capability.cursor_address, rows - statusSize, 0);
borderString.columnSubSequence(0, columns).print(terminal);
}
Expand Down

0 comments on commit 49bcaa2

Please sign in to comment.