Skip to content

Commit

Permalink
Fix bold / faint rendering problems
Browse files Browse the repository at this point in the history
  • Loading branch information
gnodet committed May 16, 2017
1 parent b50c103 commit fe928e4
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,16 @@ public String toAnsi(Terminal terminal) {
sb.append("\033[");
boolean first = true;
if ((d & (F_BOLD | F_FAINT)) != 0) {
first = attr(sb, (s & F_BOLD) != 0 ? "1" : (s & F_FAINT) != 0 ? "2" : "22", first);
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
16 changes: 16 additions & 0 deletions terminal/src/test/java/org/jline/utils/AttributedStringTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,22 @@ public void testAnsi() {
assertEquals(ansi, str.toAnsi());
}

@Test
public void testBoldThenFaint() {
AttributedStringBuilder sb = new AttributedStringBuilder();
sb.styled(AttributedStyle::bold, "bold ");
sb.styled(AttributedStyle::faint, "faint");
assertEquals("\u001b[1mbold \u001b[22;2mfaint\u001b[0m", sb.toAnsi());
}

@Test
public void testBoldAndFaint() {
AttributedStringBuilder sb = new AttributedStringBuilder();
sb.styled(AttributedStyle::bold,
s -> s.append("bold ").styled(AttributedStyle::faint, "faint"));
assertEquals("\u001b[1mbold \u001b[2mfaint\u001b[0m", sb.toAnsi());
}

@Test
public void test256Colors() throws IOException {
AttributedStringBuilder sb = new AttributedStringBuilder();
Expand Down

0 comments on commit fe928e4

Please sign in to comment.