Skip to content

Commit

Permalink
Merge branch '3.0.x'
Browse files Browse the repository at this point in the history
  • Loading branch information
gnodet committed Nov 21, 2016
2 parents 99ded1b + 349e39a commit 9ad43df
Show file tree
Hide file tree
Showing 7 changed files with 29 additions and 15 deletions.
11 changes: 4 additions & 7 deletions src/main/java/org/jline/builtins/Less.java
Original file line number Diff line number Diff line change
Expand Up @@ -9,15 +9,11 @@
package org.jline.builtins;

import java.io.BufferedReader;
import java.io.File;
import java.io.FilterInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.InterruptedIOException;
import java.net.URL;
import java.nio.file.Files;
import java.nio.file.Path;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashMap;
Expand Down Expand Up @@ -98,6 +94,7 @@ public Less(Terminal terminal) {
public void handle(Signal signal) {
size.copy(terminal.getSize());
try {
display.clear();
display();
} catch (IOException e) {
e.printStackTrace();
Expand Down Expand Up @@ -221,16 +218,16 @@ else if (buffer.length() > 0 && (buffer.charAt(0) == '/' || buffer.charAt(0) ==
// Command reading
//
else {
Object obj = bindingReader.readBinding(keys, null, false);
Operation obj = bindingReader.readBinding(keys, null, false);
if (obj == Operation.CHAR) {
char c = bindingReader.getLastBinding().charAt(0);
// Enter option mode or pattern edit mode
if (c == '-' || c == '/' || c == '?') {
buffer.setLength(0);
}
buffer.append(c);
} else if (obj instanceof Operation) {
op = (Operation) obj;
} else {
op = obj;
}
}
if (op != null) {
Expand Down
5 changes: 3 additions & 2 deletions src/main/java/org/jline/builtins/Nano.java
Original file line number Diff line number Diff line change
Expand Up @@ -1255,6 +1255,7 @@ private boolean save(String name) throws IOException {
}
Files.move(t, newPath, StandardCopyOption.REPLACE_EXISTING);
buffer.file = name;
buffer.dirty = false;
setMessage("Wrote " + buffer.lines.size() + " lines");
return true;
} catch (IOException e) {
Expand Down Expand Up @@ -1890,8 +1891,8 @@ protected List<AttributedString> computeFooter() {

Iterator<Entry<String, String>> sit = shortcuts.entrySet().iterator();
int cols = (shortcuts.size() + 1) / 2;
int cw = size.getColumns() / cols;
int rem = size.getColumns() % cols;
int cw = (size.getColumns() - 1) / cols;
int rem = (size.getColumns() - 1) % cols;
for (int l = 0; l < 2; l++) {
AttributedStringBuilder sb = new AttributedStringBuilder();
for (int c = 0; c < cols; c++) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -85,8 +85,9 @@ public void load() {
maybeResize();
}
}
} catch (IOException e) {
} catch (Exception e) {
Log.info("Error reloading history file: ", path, e);
internalClear();
}
}
}
Expand Down
5 changes: 4 additions & 1 deletion src/main/java/org/jline/terminal/TerminalBuilder.java
Original file line number Diff line number Diff line change
Expand Up @@ -164,6 +164,9 @@ private Terminal doBuild() throws IOException {
encoding = Charset.defaultCharset().name();
}
String type = this.type;
if (type == null) {
type = System.getProperty("org.jline.terminal.type");
}
if (type == null) {
type = System.getenv("TERM");
}
Expand Down Expand Up @@ -228,7 +231,7 @@ else if (OSUtils.IS_WINDOWS) {
if (dumb == null) {
Log.warn("Creating a dumb terminal", exception);
}
return new DumbTerminal(name, type,
return new DumbTerminal(name, type != null ? type : Terminal.TYPE_DUMB,
new FileInputStream(FileDescriptor.in),
new FileOutputStream(FileDescriptor.out),
encoding, signalHandler);
Expand Down
3 changes: 2 additions & 1 deletion src/main/java/org/jline/utils/AttributedCharSequence.java
Original file line number Diff line number Diff line change
Expand Up @@ -42,12 +42,13 @@ public String toAnsi(Terminal terminal) {
int style = 0;
Integer max_colors = terminal == null ? null
: terminal.getNumericCapability(Capability.max_colors);
boolean color8 = max_colors != null && max_colors >= 8;
boolean color256 = max_colors != null && max_colors >= 256;
for (int i = 0; i < length(); i++) {
char c = charAt(i);
int s = styleCodeAt(i) & ~F_HIDDEN; // The hidden flag does not change the ansi styles
int d = (style ^ s) & MASK;
if (d != 0) {
if (d != 0 && (color8 || color256)) {
if (s == 0) {
sb.append("\033[0m");
} else {
Expand Down
9 changes: 8 additions & 1 deletion src/main/java/org/jline/utils/InfoCmp.java
Original file line number Diff line number Diff line change
Expand Up @@ -575,6 +575,13 @@ public static void parseInfoCmp(
}
}

public static final String DUMB_CAPS =
"#\tReconstructed via infocmp from file: /usr/share/terminfo/64/dumb\n" +
"dumb|80-column dumb tty,\n" +
"\tam,\n" +
"\tcols#80,\n" +
"\tbel=^G, cr=^M, cud1=^J, ind=^J,\n";

public static final String WINDOWS_CAPS =
"windows|windows terminal compatibility,\n" +
"\tam, mc5i, mir, msgr,\n" +
Expand Down Expand Up @@ -732,7 +739,7 @@ public static void parseInfoCmp(
"\tu8=\\E[?1;2c, u9=\\E[c, vpa=\\E[%i%p1%dd,";

static {
setDefaultInfoCmp("dumb", ANSI_CAPS);
setDefaultInfoCmp("dumb", DUMB_CAPS);
setDefaultInfoCmp("ansi", ANSI_CAPS);
setDefaultInfoCmp("xterm", XTERM_CAPS);
setDefaultInfoCmp("xterm-256color", XTERM_256COLOR_CAPS);
Expand Down
8 changes: 6 additions & 2 deletions src/test/java/org/jline/example/Example.java
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
import org.jline.reader.impl.completer.StringsCompleter;
import org.jline.terminal.Terminal;
import org.jline.terminal.TerminalBuilder;
import org.jline.utils.AttributedString;
import org.jline.utils.AttributedStringBuilder;
import org.jline.utils.AttributedStyle;
import org.jline.utils.InfoCmp.Capability;
Expand Down Expand Up @@ -201,8 +202,11 @@ public static void main(String[] args) throws IOException {
}

line = line.trim();
if (color){
terminal.writer().println("\u001B[33m======>\u001B[0m\"" + line + "\"");

if (color) {
terminal.writer().println(
AttributedString.fromAnsi("\u001B[33m======>\u001B[0m\"" + line + "\"")
.toAnsi(terminal));

} else {
terminal.writer().println("======>\"" + line + "\"");
Expand Down

0 comments on commit 9ad43df

Please sign in to comment.