Skip to content

Commit

Permalink
Merge pull request #15 from garydgregory/better-Ansi
Browse files Browse the repository at this point in the history
Add missing Ansi fluent APIs.
  • Loading branch information
chirino committed Apr 26, 2016
2 parents 236d35f + 1a43ddc commit 23afd0e
Show file tree
Hide file tree
Showing 2 changed files with 119 additions and 4 deletions.
120 changes: 116 additions & 4 deletions jansi/src/main/java/org/fusesource/jansi/Ansi.java
Original file line number Diff line number Diff line change
Expand Up @@ -341,26 +341,138 @@ public static Ansi ansi(int size) {
return new Ansi(size);
}

public Ansi fg(Color color) {
attributeOptions.add(color.fg());
return this;
}
public Ansi fg(Color color) {
attributeOptions.add(color.fg());
return this;
}

public Ansi fgBlack() {
return this.fg(Color.BLACK);
}

public Ansi fgBlue() {
return this.fg(Color.BLUE);
}

public Ansi fgCyan() {
return this.fg(Color.CYAN);
}

public Ansi fgDefault() {
return this.fg(Color.DEFAULT);
}

public Ansi fgGreen() {
return this.fg(Color.GREEN);
}

public Ansi fgMagenta() {
return this.fg(Color.MAGENTA);
}

public Ansi fgRed() {
return this.fg(Color.RED);
}

public Ansi fgYellow() {
return this.fg(Color.YELLOW);
}

public Ansi bg(Color color) {
attributeOptions.add(color.bg());
return this;
}

public Ansi bgCyan() {
return this.fg(Color.CYAN);
}

public Ansi bgDefault() {
return this.bg(Color.DEFAULT);
}

public Ansi bgGreen() {
return this.bg(Color.GREEN);
}

public Ansi bgMagenta() {
return this.bg(Color.MAGENTA);
}

public Ansi bgRed() {
return this.bg(Color.RED);
}

public Ansi bgYellow() {
return this.bg(Color.YELLOW);
}

public Ansi fgBright(Color color) {
attributeOptions.add(color.fgBright());
return this;
}

public Ansi fgBrightBlack() {
return this.fgBright(Color.BLACK);
}

public Ansi fgBrightBlue() {
return this.fgBright(Color.BLUE);
}

public Ansi fgBrightCyan() {
return this.fgBright(Color.CYAN);
}

public Ansi fgBrightDefault() {
return this.fgBright(Color.DEFAULT);
}

public Ansi fgBrightGreen() {
return this.fgBright(Color.GREEN);
}

public Ansi fgBrightMagenta() {
return this.fgBright(Color.MAGENTA);
}

public Ansi fgBrightRed() {
return this.fgBright(Color.RED);
}

public Ansi fgBrightYellow() {
return this.fgBright(Color.YELLOW);
}

public Ansi bgBright(Color color) {
attributeOptions.add(color.bgBright());
return this;
}

public Ansi bgBrightCyan() {
return this.fgBright(Color.CYAN);
}

public Ansi bgBrightDefault() {
return this.bgBright(Color.DEFAULT);
}

public Ansi bgBrightGreen() {
return this.bgBright(Color.GREEN);
}

public Ansi bgBrightMagenta() {
return this.bg(Color.MAGENTA);
}

public Ansi bgBrightRed() {
return this.bgBright(Color.RED);
}

public Ansi bgBrightYellow() {
return this.bgBright(Color.YELLOW);
}

public Ansi a(Attribute attribute) {
attributeOptions.add(attribute.value());
return this;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,20 +49,23 @@ public void testRender() {
String str = render("@|bold foo|@");
System.out.println(str);
assertEquals(ansi().a(INTENSITY_BOLD).a("foo").reset().toString(), str);
assertEquals(ansi().bold().a("foo").reset().toString(), str);
}

@Test
public void testRender2() {
String str = render("@|bold,red foo|@");
System.out.println(str);
assertEquals(Ansi.ansi().a(INTENSITY_BOLD).fg(RED).a("foo").reset().toString(), str);
assertEquals(Ansi.ansi().bold().fgRed().a("foo").reset().toString(), str);
}

@Test
public void testRender3() {
String str = render("@|bold,red foo bar baz|@");
System.out.println(str);
assertEquals(ansi().a(INTENSITY_BOLD).fg(RED).a("foo bar baz").reset().toString(), str);
assertEquals(ansi().bold().fgRed().a("foo bar baz").reset().toString(), str);
}

@Test
Expand Down

0 comments on commit 23afd0e

Please sign in to comment.