Skip to content

Commit 1a43ddc

Browse files
committed
Add missing Ansi fluent APIs.
1 parent c56496c commit 1a43ddc

File tree

2 files changed

+119
-4
lines changed

2 files changed

+119
-4
lines changed

Diff for: jansi/src/main/java/org/fusesource/jansi/Ansi.java

+116-4
Original file line numberDiff line numberDiff line change
@@ -310,26 +310,138 @@ public static Ansi ansi(int size) {
310310
return new Ansi(size);
311311
}
312312

313-
public Ansi fg(Color color) {
314-
attributeOptions.add(color.fg());
315-
return this;
316-
}
313+
public Ansi fg(Color color) {
314+
attributeOptions.add(color.fg());
315+
return this;
316+
}
317+
318+
public Ansi fgBlack() {
319+
return this.fg(Color.BLACK);
320+
}
321+
322+
public Ansi fgBlue() {
323+
return this.fg(Color.BLUE);
324+
}
325+
326+
public Ansi fgCyan() {
327+
return this.fg(Color.CYAN);
328+
}
329+
330+
public Ansi fgDefault() {
331+
return this.fg(Color.DEFAULT);
332+
}
333+
334+
public Ansi fgGreen() {
335+
return this.fg(Color.GREEN);
336+
}
337+
338+
public Ansi fgMagenta() {
339+
return this.fg(Color.MAGENTA);
340+
}
341+
342+
public Ansi fgRed() {
343+
return this.fg(Color.RED);
344+
}
345+
346+
public Ansi fgYellow() {
347+
return this.fg(Color.YELLOW);
348+
}
317349

318350
public Ansi bg(Color color) {
319351
attributeOptions.add(color.bg());
320352
return this;
321353
}
322354

355+
public Ansi bgCyan() {
356+
return this.fg(Color.CYAN);
357+
}
358+
359+
public Ansi bgDefault() {
360+
return this.bg(Color.DEFAULT);
361+
}
362+
363+
public Ansi bgGreen() {
364+
return this.bg(Color.GREEN);
365+
}
366+
367+
public Ansi bgMagenta() {
368+
return this.bg(Color.MAGENTA);
369+
}
370+
371+
public Ansi bgRed() {
372+
return this.bg(Color.RED);
373+
}
374+
375+
public Ansi bgYellow() {
376+
return this.bg(Color.YELLOW);
377+
}
378+
323379
public Ansi fgBright(Color color) {
324380
attributeOptions.add(color.fgBright());
325381
return this;
326382
}
327383

384+
public Ansi fgBrightBlack() {
385+
return this.fgBright(Color.BLACK);
386+
}
387+
388+
public Ansi fgBrightBlue() {
389+
return this.fgBright(Color.BLUE);
390+
}
391+
392+
public Ansi fgBrightCyan() {
393+
return this.fgBright(Color.CYAN);
394+
}
395+
396+
public Ansi fgBrightDefault() {
397+
return this.fgBright(Color.DEFAULT);
398+
}
399+
400+
public Ansi fgBrightGreen() {
401+
return this.fgBright(Color.GREEN);
402+
}
403+
404+
public Ansi fgBrightMagenta() {
405+
return this.fgBright(Color.MAGENTA);
406+
}
407+
408+
public Ansi fgBrightRed() {
409+
return this.fgBright(Color.RED);
410+
}
411+
412+
public Ansi fgBrightYellow() {
413+
return this.fgBright(Color.YELLOW);
414+
}
415+
328416
public Ansi bgBright(Color color) {
329417
attributeOptions.add(color.bgBright());
330418
return this;
331419
}
332420

421+
public Ansi bgBrightCyan() {
422+
return this.fgBright(Color.CYAN);
423+
}
424+
425+
public Ansi bgBrightDefault() {
426+
return this.bgBright(Color.DEFAULT);
427+
}
428+
429+
public Ansi bgBrightGreen() {
430+
return this.bgBright(Color.GREEN);
431+
}
432+
433+
public Ansi bgBrightMagenta() {
434+
return this.bg(Color.MAGENTA);
435+
}
436+
437+
public Ansi bgBrightRed() {
438+
return this.bgBright(Color.RED);
439+
}
440+
441+
public Ansi bgBrightYellow() {
442+
return this.bgBright(Color.YELLOW);
443+
}
444+
333445
public Ansi a(Attribute attribute) {
334446
attributeOptions.add(attribute.value());
335447
return this;

Diff for: 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)