Skip to content

Commit 23afd0e

Browse files
committed
Merge pull request #15 from garydgregory/better-Ansi
Add missing Ansi fluent APIs.
2 parents 236d35f + 1a43ddc commit 23afd0e

File tree

2 files changed

+119
-4
lines changed

2 files changed

+119
-4
lines changed

jansi/src/main/java/org/fusesource/jansi/Ansi.java

+116-4
Original file line numberDiff line numberDiff line change
@@ -341,26 +341,138 @@ public static Ansi ansi(int size) {
341341
return new Ansi(size);
342342
}
343343

344-
public Ansi fg(Color color) {
345-
attributeOptions.add(color.fg());
346-
return this;
347-
}
344+
public Ansi fg(Color color) {
345+
attributeOptions.add(color.fg());
346+
return this;
347+
}
348+
349+
public Ansi fgBlack() {
350+
return this.fg(Color.BLACK);
351+
}
352+
353+
public Ansi fgBlue() {
354+
return this.fg(Color.BLUE);
355+
}
356+
357+
public Ansi fgCyan() {
358+
return this.fg(Color.CYAN);
359+
}
360+
361+
public Ansi fgDefault() {
362+
return this.fg(Color.DEFAULT);
363+
}
364+
365+
public Ansi fgGreen() {
366+
return this.fg(Color.GREEN);
367+
}
368+
369+
public Ansi fgMagenta() {
370+
return this.fg(Color.MAGENTA);
371+
}
372+
373+
public Ansi fgRed() {
374+
return this.fg(Color.RED);
375+
}
376+
377+
public Ansi fgYellow() {
378+
return this.fg(Color.YELLOW);
379+
}
348380

349381
public Ansi bg(Color color) {
350382
attributeOptions.add(color.bg());
351383
return this;
352384
}
353385

386+
public Ansi bgCyan() {
387+
return this.fg(Color.CYAN);
388+
}
389+
390+
public Ansi bgDefault() {
391+
return this.bg(Color.DEFAULT);
392+
}
393+
394+
public Ansi bgGreen() {
395+
return this.bg(Color.GREEN);
396+
}
397+
398+
public Ansi bgMagenta() {
399+
return this.bg(Color.MAGENTA);
400+
}
401+
402+
public Ansi bgRed() {
403+
return this.bg(Color.RED);
404+
}
405+
406+
public Ansi bgYellow() {
407+
return this.bg(Color.YELLOW);
408+
}
409+
354410
public Ansi fgBright(Color color) {
355411
attributeOptions.add(color.fgBright());
356412
return this;
357413
}
358414

415+
public Ansi fgBrightBlack() {
416+
return this.fgBright(Color.BLACK);
417+
}
418+
419+
public Ansi fgBrightBlue() {
420+
return this.fgBright(Color.BLUE);
421+
}
422+
423+
public Ansi fgBrightCyan() {
424+
return this.fgBright(Color.CYAN);
425+
}
426+
427+
public Ansi fgBrightDefault() {
428+
return this.fgBright(Color.DEFAULT);
429+
}
430+
431+
public Ansi fgBrightGreen() {
432+
return this.fgBright(Color.GREEN);
433+
}
434+
435+
public Ansi fgBrightMagenta() {
436+
return this.fgBright(Color.MAGENTA);
437+
}
438+
439+
public Ansi fgBrightRed() {
440+
return this.fgBright(Color.RED);
441+
}
442+
443+
public Ansi fgBrightYellow() {
444+
return this.fgBright(Color.YELLOW);
445+
}
446+
359447
public Ansi bgBright(Color color) {
360448
attributeOptions.add(color.bgBright());
361449
return this;
362450
}
363451

452+
public Ansi bgBrightCyan() {
453+
return this.fgBright(Color.CYAN);
454+
}
455+
456+
public Ansi bgBrightDefault() {
457+
return this.bgBright(Color.DEFAULT);
458+
}
459+
460+
public Ansi bgBrightGreen() {
461+
return this.bgBright(Color.GREEN);
462+
}
463+
464+
public Ansi bgBrightMagenta() {
465+
return this.bg(Color.MAGENTA);
466+
}
467+
468+
public Ansi bgBrightRed() {
469+
return this.bgBright(Color.RED);
470+
}
471+
472+
public Ansi bgBrightYellow() {
473+
return this.bgBright(Color.YELLOW);
474+
}
475+
364476
public Ansi a(Attribute attribute) {
365477
attributeOptions.add(attribute.value());
366478
return this;

jansi/src/test/java/org/fusesource/jansi/AnsiRendererTest.java

+3
Original file line numberDiff line numberDiff line change
@@ -49,20 +49,23 @@ public void testRender() {
4949
String str = render("@|bold foo|@");
5050
System.out.println(str);
5151
assertEquals(ansi().a(INTENSITY_BOLD).a("foo").reset().toString(), str);
52+
assertEquals(ansi().bold().a("foo").reset().toString(), str);
5253
}
5354

5455
@Test
5556
public void testRender2() {
5657
String str = render("@|bold,red foo|@");
5758
System.out.println(str);
5859
assertEquals(Ansi.ansi().a(INTENSITY_BOLD).fg(RED).a("foo").reset().toString(), str);
60+
assertEquals(Ansi.ansi().bold().fgRed().a("foo").reset().toString(), str);
5961
}
6062

6163
@Test
6264
public void testRender3() {
6365
String str = render("@|bold,red foo bar baz|@");
6466
System.out.println(str);
6567
assertEquals(ansi().a(INTENSITY_BOLD).fg(RED).a("foo bar baz").reset().toString(), str);
68+
assertEquals(ansi().bold().fgRed().a("foo bar baz").reset().toString(), str);
6669
}
6770

6871
@Test

0 commit comments

Comments
 (0)