Skip to content

Commit

Permalink
Make sure the bold attributed is outputed after the color in ansi seq…
Browse files Browse the repository at this point in the history
…uences, #218, #219
  • Loading branch information
gnodet committed Jan 25, 2018
1 parent e8bc984 commit 2973cec
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 13 deletions.
24 changes: 12 additions & 12 deletions terminal/src/main/java/org/jline/utils/AttributedCharSequence.java
Original file line number Diff line number Diff line change
Expand Up @@ -65,18 +65,6 @@ public String toAnsi(Terminal terminal) {
} else {
sb.append("\033[");
boolean first = true;
if ((d & (F_BOLD | F_FAINT)) != 0) {
if ( (d & F_BOLD) != 0 && (s & F_BOLD) == 0
|| (d & F_FAINT) != 0 && (s & F_FAINT) == 0) {
first = attr(sb, "22", first);
}
if ((d & F_BOLD) != 0 && (s & F_BOLD) != 0) {
first = attr(sb, "1", first);
}
if ((d & F_FAINT) != 0 && (s & F_FAINT) != 0) {
first = attr(sb, "2", first);
}
}
if ((d & F_ITALIC) != 0) {
first = attr(sb, (s & F_ITALIC) != 0 ? "3" : "23", first);
}
Expand Down Expand Up @@ -125,6 +113,18 @@ public String toAnsi(Terminal terminal) {
}
background = bg;
}
if ((d & (F_BOLD | F_FAINT)) != 0) {
if ( (d & F_BOLD) != 0 && (s & F_BOLD) == 0
|| (d & F_FAINT) != 0 && (s & F_FAINT) == 0) {
first = attr(sb, "22", first);
}
if ((d & F_BOLD) != 0 && (s & F_BOLD) != 0) {
first = attr(sb, "1", first);
}
if ((d & F_FAINT) != 0 && (s & F_FAINT) != 0) {
first = attr(sb, "2", first);
}
}
sb.append("m");
}
style = s;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,14 @@
*/
package org.jline.utils;

import org.jline.terminal.impl.ExternalTerminal;
import org.junit.Test;

import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.io.StringWriter;
import java.nio.charset.StandardCharsets;

import static org.junit.Assert.assertEquals;

Expand All @@ -25,7 +30,20 @@ public void testBoldOnWindows() throws IOException {
//sb.append(NOR);
AttributedString as = sb.toAttributedString();

assertEquals("\33[1;36mthe buffer\33[0m", as.toAnsi(null));
assertEquals("\33[36;1mthe buffer\33[0m", as.toAnsi(null));
}

@Test
public void testBold() throws IOException {
ExternalTerminal terminal = new ExternalTerminal(
"my term",
"windows",
new ByteArrayInputStream(new byte[0]),
new ByteArrayOutputStream(),
StandardCharsets.UTF_8);

assertEquals("\33[32;1mtest\33[0m", AttributedString.fromAnsi("\33[32m\33[1mtest\33[0m").toAnsi(terminal));
assertEquals("\33[32;1mtest\33[0m", AttributedString.fromAnsi("\33[1m\33[32mtest\33[0m").toAnsi(terminal));
}

}

0 comments on commit 2973cec

Please sign in to comment.