Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add missing Ansi fluent APIs. #15

Merged
merged 1 commit into from
Apr 26, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 @@ -310,26 +310,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