From 1a43ddc896969909519f8ce91c91bb88b6c16d51 Mon Sep 17 00:00:00 2001 From: Gary Gregory Date: Wed, 31 Oct 2012 09:32:13 -0400 Subject: [PATCH] Add missing Ansi fluent APIs. --- .../main/java/org/fusesource/jansi/Ansi.java | 120 +++++++++++++++++- .../fusesource/jansi/AnsiRendererTest.java | 3 + 2 files changed, 119 insertions(+), 4 deletions(-) diff --git a/jansi/src/main/java/org/fusesource/jansi/Ansi.java b/jansi/src/main/java/org/fusesource/jansi/Ansi.java index 6d42d8d5..00d8781e 100644 --- a/jansi/src/main/java/org/fusesource/jansi/Ansi.java +++ b/jansi/src/main/java/org/fusesource/jansi/Ansi.java @@ -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; diff --git a/jansi/src/test/java/org/fusesource/jansi/AnsiRendererTest.java b/jansi/src/test/java/org/fusesource/jansi/AnsiRendererTest.java index 8ab728a2..d6159d09 100644 --- a/jansi/src/test/java/org/fusesource/jansi/AnsiRendererTest.java +++ b/jansi/src/test/java/org/fusesource/jansi/AnsiRendererTest.java @@ -49,6 +49,7 @@ 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 @@ -56,6 +57,7 @@ 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 @@ -63,6 +65,7 @@ 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