### Install ASCII Table dependency Source: https://github.com/freva/ascii-table/blob/master/README.md Add the library to your project using Maven or Gradle. ```xml com.github.freva ascii-table 1.12.1 ``` ```gradle compile 'com.github.freva:ascii-table:1.12.1' ``` -------------------------------- ### ASCII Table with FANCY_ASCII Style Source: https://github.com/freva/ascii-table/blob/master/README.md This example demonstrates the `AsciiTable.FANCY_ASCII` style, which uses Unicode characters to create a visually appealing, bordered table. ```text ╔═══╤═════════╤══════════╤══════╤═════════════════════════════════╗ ║ │ Name │ Diameter │ Mass │ Atmosphere ║ ╠═══╪═════════╪══════════╪══════╪═════════════════════════════════╣ ║ 1 │ Mercury │ 0.382 │ 0.06 │ minimal ║ ╟───┼─────────┼──────────┼──────┼─────────────────────────────────╢ ║ 2 │ Venus │ 0.949 │ 0.82 │ Carbon dioxide, Nitrogen ║ ╟───┼─────────┼──────────┼──────┼─────────────────────────────────╢ ║ 3 │ Earth │ 1.000 │ 1.00 │ Nitrogen, Oxygen, Argon ║ ╟───┼─────────┼──────────┼──────┼─────────────────────────────────╢ ║ 4 │ Mars │ 0.532 │ 0.11 │ Carbon dioxide, Nitrogen, Argon ║ ╠═══╪═════════╪══════════╪══════╪═════════════════════════════════╣ ║ │ Average │ 0.716 │ 0.50 │ ║ ╚═══╧═════════╧══════════╧══════╧═════════════════════════════════╝ ``` -------------------------------- ### Configure AsciiTable with Builder Pattern Source: https://context7.com/freva/ascii-table/llms.txt Utilize the AsciiTable builder for advanced customization, including setting line separators, border styles, maximum table width, and output destinations. This example shows building a string output and writing to a file. ```java // Build table with custom configuration String table = AsciiTable.builder() .lineSeparator("\n") .border(AsciiTable.FANCY_ASCII) .data(planets, Arrays.asList( new Column().with(planet -> Integer.toString(planet.num)), new Column().header("Name").with(planet -> planet.name), new Column().header("Diameter").with(planet -> String.format("%.03f", planet.diameter)), new Column().header("Mass").with(planet -> String.format("%.02f", planet.mass)) )) .maxTableWidth(50) .asString(); System.out.println(table); ``` ```java // Write directly to file try (OutputStream fos = Files.newOutputStream(Paths.get("table.txt"))) { AsciiTable.builder() .lineSeparator("\r\n") .border(AsciiTable.BASIC_ASCII_NO_OUTSIDE_BORDER) .header("ID", "Name", "Value") .data(new String[][] { {"1", "Item A", "100"}, {"2", "Item B", "200"} }) .writeTo(fos); } ``` -------------------------------- ### ASCII Table with RE_STRUCTURED_TEXT Style Source: https://github.com/freva/ascii-table/blob/master/README.md This example shows an ASCII table using the `AsciiTable.RE_STRUCTURED_TEXT` style, which mimics the reStructuredText table format. ```text +---+---------+----------+------+---------------------------------+ | | Name | Diameter | Mass | Atmosphere | +===+=========+==========+======+=================================+ | 1 | Mercury | 0.382 | 0.06 | minimal | ``` -------------------------------- ### ASCII Table with NO_BORDERS Style Source: https://github.com/freva/ascii-table/blob/master/README.md This example shows an ASCII table using the `AsciiTable.NO_BORDERS` style, which removes all borders and separators for a minimalist look. ```text Name Diameter Mass Atmosphere 1 Mercury 0.382 0.06 minimal 2 Venus 0.949 0.82 Carbon dioxide, Nitrogen 3 Earth 1.000 1.00 Nitrogen, Oxygen, Argon 4 Mars 0.532 0.11 Carbon dioxide, Nitrogen, Argon Average 0.716 0.50 ``` -------------------------------- ### ASCII Table with BASIC_ASCII_NO_DATA_SEPARATORS_NO_OUTSIDE_BORDER Style Source: https://github.com/freva/ascii-table/blob/master/README.md This example illustrates an ASCII table with the `AsciiTable.BASIC_ASCII_NO_DATA_SEPARATORS_NO_OUTSIDE_BORDER` style. It lacks both outer borders and horizontal data separators. ```text | Name | Diameter | Mass | Atmosphere ---+---------+----------+------+--------------------------------- 1 | Mercury | 0.382 | 0.06 | minimal 2 | Venus | 0.949 | 0.82 | Carbon dioxide, Nitrogen 3 | Earth | 1.000 | 1.00 | Nitrogen, Oxygen, Argon 4 | Mars | 0.532 | 0.11 | Carbon dioxide, Nitrogen, Argon ---+---------+----------+------+--------------------------------- | Average | 0.716 | 0.50 | ``` -------------------------------- ### ASCII Table with BASIC_ASCII_NO_DATA_SEPARATORS Style Source: https://github.com/freva/ascii-table/blob/master/README.md This example shows an ASCII table using the `AsciiTable.BASIC_ASCII_NO_DATA_SEPARATORS` style. It includes outer borders but omits the horizontal separators between data rows. ```text +---+---------+----------+------+---------------------------------+ | | Name | Diameter | Mass | Atmosphere | +---+---------+----------+------+---------------------------------+ | 1 | Mercury | 0.382 | 0.06 | minimal | | 2 | Venus | 0.949 | 0.82 | Carbon dioxide, Nitrogen | | 3 | Earth | 1.000 | 1.00 | Nitrogen, Oxygen, Argon | | 4 | Mars | 0.532 | 0.11 | Carbon dioxide, Nitrogen, Argon | +---+---------+----------+------+---------------------------------+ | | Average | 0.716 | 0.50 | | +---+---------+----------+------+---------------------------------+ ``` -------------------------------- ### ASCII Table with BASIC_ASCII_NO_OUTSIDE_BORDER Style Source: https://github.com/freva/ascii-table/blob/master/README.md This example demonstrates the output of an ASCII table when using the `AsciiTable.BASIC_ASCII_NO_OUTSIDE_BORDER` style. It removes the outer border lines. ```text | Name | Diameter | Mass | Atmosphere ---+---------+----------+------+--------------------------------- 1 | Mercury | 0.382 | 0.06 | minimal ---+---------+----------+------+--------------------------------- 2 | Venus | 0.949 | 0.82 | Carbon dioxide, Nitrogen ---+---------+----------+------+--------------------------------- 3 | Earth | 1.000 | 1.00 | Nitrogen, Oxygen, Argon ---+---------+----------+------+--------------------------------- 4 | Mars | 0.532 | 0.11 | Carbon dioxide, Nitrogen, Argon ---+---------+----------+------+--------------------------------- | Average | 0.716 | 0.50 | ``` -------------------------------- ### Define Custom Border Style Template Source: https://github.com/freva/ascii-table/blob/master/README.md A template array of length 29 used as a starting point for defining custom border characters. ```java public static final Character[] CUSTOM = { null, //A null, //B null, //C null, //D null, //E null, //F null, //G null, //H null, //I null, //J null, //K null, //L null, //M null, //N null, //O null, //P null, //Q null, //R null, //S null, //T null, //U null, //V null, //W null, //X null, //Y null, //Z null, //1 null, //2 null //3 }; ``` -------------------------------- ### Initialize Border Styles Array Source: https://github.com/freva/ascii-table/blob/master/README.md Demonstrates how to create a Character array of length 29 for mapping table border elements. ```java Character[] borderStyles = "ABCDEFGHIJKLMNOPQRSTUVWXYZ123".chars().mapToObj(c -> (char)c).toArray(Character[]::new); ``` -------------------------------- ### Built-in and Custom Border Styles for AsciiTable Source: https://context7.com/freva/ascii-table/llms.txt Demonstrates the use of predefined border styles like BASIC_ASCII and FANCY_ASCII, and shows how to create a custom border style using a character array. Use these to control the visual appearance of your tables. ```java AsciiTable.BASIC_ASCII AsciiTable.BASIC_ASCII_NO_DATA_SEPARATORS AsciiTable.BASIC_ASCII_NO_OUTSIDE_BORDER AsciiTable.BASIC_ASCII_NO_DATA_SEPARATORS_NO_OUTSIDE_BORDER AsciiTable.FANCY_ASCII AsciiTable.RE_STRUCTURED_TEXT AsciiTable.NO_BORDERS ``` ```java String fancyTable = AsciiTable.getTable( AsciiTable.FANCY_ASCII, planets, Arrays.asList( new Column().with(planet -> Integer.toString(planet.num)), new Column().header("Name").with(planet -> planet.name), new Column().header("Mass").with(planet -> String.format("%.02f", planet.mass)) ) ); ``` ```java Character[] customBorder = {'ℹ', '─', '┬', '℺', '│', '│', '│', '├', '─', '┼', '┤', '│', '│', '│', '├', '─', '┼', '┤', '├', '─', '┼', '┤', '│', '│', '│', 'ℚ', '─', '┴', 'ℛ'}; ``` -------------------------------- ### Create basic ASCII table from arrays Source: https://github.com/freva/ascii-table/blob/master/README.md Generate a table by providing a string array for headers and a 2D string array for data. ```java String[] headers = {"", "Name", "Diameter", "Mass", "Atmosphere"}; String[][] data = { {"1", "Mercury", "0.382", "0.06", "minimal"}, {"2", "Venus", "0.949", "0.82", "Carbon dioxide, Nitrogen"}, {"3", "Earth", "1.000", "1.00", "Nitrogen, Oxygen, Argon"}, {"4", "Mars", "0.532", "0.11", "Carbon dioxide, Nitrogen, Argon"}}; System.out.println(AsciiTable.getTable(headers, data)); ``` -------------------------------- ### Add Footer Rows with Aggregations to AsciiTable Source: https://context7.com/freva/ascii-table/llms.txt Use footer configurations within Column definitions to display summary information like averages or totals at the bottom of the table. Ensure necessary imports are included. ```java import static com.github.freva.asciitable.HorizontalAlign.CENTER; String table = AsciiTable.getTable(planets, Arrays.asList( new Column().with(planet -> Integer.toString(planet.num)), new Column() .header("Name") .footer("Average") .headerAlign(CENTER) .dataAlign(HorizontalAlign.RIGHT) .with(planet -> planet.name), new Column() .header("Diameter") .headerAlign(HorizontalAlign.RIGHT) .dataAlign(CENTER) .footerAlign(CENTER) .footer(String.format("%.03f", planets.stream() .mapToDouble(p -> p.diameter).average().orElse(0))) .with(planet -> String.format("%.03f", planet.diameter)), new Column() .header("Mass") .headerAlign(HorizontalAlign.RIGHT) .dataAlign(HorizontalAlign.LEFT) .footer(String.format("%.02f", planets.stream() .mapToDouble(p -> p.mass).average().orElse(0))) .with(planet -> String.format("%.02f", planet.mass)), new Column() .header("Atmosphere") .headerAlign(HorizontalAlign.LEFT) .dataAlign(CENTER) .with(planet -> planet.atmosphere) )); ``` -------------------------------- ### Set column width constraints in Java Source: https://github.com/freva/ascii-table/blob/master/README.md Use minWidth and maxWidth methods on Column objects to control the layout of table cells. ```java System.out.println(AsciiTable.getTable(planets, Arrays.asList( new Column().minWidth(5).with(planet -> Integer.toString(planet.num)), new Column().header("Name").with(planet -> planet.name), new Column().header("Diameter").with(planet -> String.format("%.03f", planet.diameter)), new Column().header("Mass").with(planet -> String.format("%.02f", planet.mass)), new Column().header("Atmosphere Composition").maxWidth(12).with(planet -> planet.atmosphere)))); ``` -------------------------------- ### Generate Basic Table from 2D Array Source: https://context7.com/freva/ascii-table/llms.txt Use this method for quick table generation from raw data arrays. Headers are optional and passed as a separate string array. ```java // Basic table with headers String[] headers = {"", "Name", "Diameter", "Mass", "Atmosphere"}; String[][] data = { {"1", "Mercury", "0.382", "0.06", "minimal"}, {"2", "Venus", "0.949", "0.82", "Carbon dioxide, Nitrogen"}, {"3", "Earth", "1.000", "1.00", "Nitrogen, Oxygen, Argon"}, {"4", "Mars", "0.532", "0.11", "Carbon dioxide, Nitrogen, Argon"} }; System.out.println(AsciiTable.getTable(headers, data)); ``` -------------------------------- ### Dynamic Column Visibility Control Source: https://context7.com/freva/ascii-table/llms.txt Demonstrates how to control the visibility of columns in an AsciiTable using the `visible()` method. This is useful for conditionally displaying detailed information based on a flag, such as `showDetails`. ```java boolean showDetails = false; String table = AsciiTable.getTable(planets, Arrays.asList( new Column().header("Name").with(planet -> planet.name), new Column() .header("Diameter") .visible(showDetails) // Column hidden when showDetails is false .with(planet -> String.format("%.03f", planet.diameter)), new Column() .header("Mass") .visible(showDetails) // Column hidden when showDetails is false .with(planet -> String.format("%.02f", planet.mass)), new Column().header("Atmosphere").with(planet -> planet.atmosphere) )); ``` -------------------------------- ### Customize Table Output with Builder Source: https://github.com/freva/ascii-table/blob/master/README.md Uses the builder pattern to configure line separators, borders, and write the table directly to an OutputStream. ```java try (OutputStream fos = Files.newOutputStream(Paths.get("table.txt"))) { AsciiTable.builder() .lineSeparator("\r\n") .border(AsciiTable.BASIC_ASCII_NO_OUTSIDE_BORDER) .data(planets, Arrays.asList( new Column().with(planet -> Integer.toString(planet.num)), new Column().header("Name").footer("Average").headerAlign(CENTER).dataAlign(RIGHT).with(planet -> planet.name), new Column().header("Diameter").headerAlign(RIGHT).dataAlign(CENTER).footerAlign(CENTER) .footer(String.format("%.03f", planets.stream().mapToDouble(planet -> planet.diameter).average().orElse(0))) .with(planet -> String.format("%.03f", planet.diameter)), new Column().header("Mass").headerAlign(RIGHT).dataAlign(LEFT) .footer(String.format("%.02f", planets.stream().mapToDouble(planet -> planet.mass).average().orElse(0))) .with(planet -> String.format("%.02f", planet.mass)), new Column().header("Atmosphere").headerAlign(LEFT).dataAlign(CENTER).with(planet -> planet.atmosphere))) .writeTo(fos); } ``` -------------------------------- ### Set Column Minimum and Maximum Width Source: https://context7.com/freva/ascii-table/llms.txt Control column widths using minWidth() and maxWidth() methods. Content exceeding maxWidth will wrap to new lines by default. ```java String table = AsciiTable.getTable(planets, Arrays.asList( new Column().minWidth(5).with(planet -> Integer.toString(planet.num)), new Column().header("Name").with(planet -> planet.name), new Column().header("Diameter").with(planet -> String.format("%.03f", planet.diameter)), new Column().header("Mass").with(planet -> String.format("%.02f", planet.mass)), new Column().header("Atmosphere Composition").maxWidth(12).with(planet -> planet.atmosphere) )); ``` -------------------------------- ### Generate Table from Collections with Column Definitions Source: https://context7.com/freva/ascii-table/llms.txt Use this approach to map object properties to table columns using lambda functions. Requires defining column headers and data extraction logic. ```java // Define a simple Planet class class Planet { int num; String name; double diameter; double mass; String atmosphere; Planet(int num, String name, double diameter, double mass, String atmosphere) { this.num = num; this.name = name; this.diameter = diameter; this.mass = mass; this.atmosphere = atmosphere; } } List planets = Arrays.asList( new Planet(1, "Mercury", 0.382, 0.06, "minimal"), new Planet(2, "Venus", 0.949, 0.82, "Carbon dioxide, Nitrogen"), new Planet(3, "Earth", 1.0, 1.0, "Nitrogen, Oxygen, Argon"), new Planet(4, "Mars", 0.532, 0.11, "Carbon dioxide, Nitrogen, Argon") ); String table = AsciiTable.getTable(planets, Arrays.asList( new Column().with(planet -> Integer.toString(planet.num)), new Column().header("Name").with(planet -> planet.name), new Column().header("Diameter").with(planet -> String.format("%.03f", planet.diameter)), new Column().header("Mass").with(planet -> String.format("%.02f", planet.mass)), new Column().header("Atmosphere").with(planet -> planet.atmosphere) )); System.out.println(table); ``` -------------------------------- ### Create ASCII table from Collections Source: https://github.com/freva/ascii-table/blob/master/README.md Generate a table from a list of objects using Column definitions to map data. ```java List planets = Arrays.asList( new Planet(1, "Mercury", 0.382, 0.06, "minimal"), new Planet(2, "Venus", 0.949, 0.82, "Carbon dioxide, Nitrogen"), new Planet(3, "Earth", 1.0, 1.0, "Nitrogen, Oxygen, Argon"), new Planet(4, "Mars", 0.532, 0.11, "Carbon dioxide, Nitrogen, Argon")); System.out.println(AsciiTable.getTable(planets, Arrays.asList( new Column().with(planet -> Integer.toString(planet.num)), new Column().header("Name").with(planet -> planet.name), new Column().header("Diameter").with(planet -> String.format("%.03f", planet.diameter)), new Column().header("Mass").with(planet -> String.format("%.02f", planet.mass)), new Column().header("Atmosphere").with(planet -> planet.atmosphere)))); ``` -------------------------------- ### Generate ASCII Table with Custom Border Style Source: https://github.com/freva/ascii-table/blob/master/README.md Use this code to generate an ASCII table with a specified border style. Ensure you have the AsciiTable library imported and the necessary data structures (borderStyles, planets, Column definitions) prepared. ```java Character[] borderStyle = ...; System.out.println(AsciiTable.getTable(borderStyles, planets, Arrays.asList( new Column().with(planet -> Integer.toString(planet.num)), new Column().header("Name").footer("Average").headerAlign(CENTER).dataAlign(RIGHT).with(planet -> planet.name), new Column().header("Diameter").headerAlign(RIGHT).dataAlign(CENTER).footerAlign(CENTER) .footer(String.format("%.03f", planets.stream().mapToDouble(planet -> planet.diameter).average().orElse(0))) .with(planet -> String.format("%.03f", planet.diameter)), new Column().header("Mass").headerAlign(RIGHT).dataAlign(LEFT) .footer(String.format("%.02f", planets.stream().mapToDouble(planet -> planet.mass).average().orElse(0))) .with(planet -> String.format("%.02f", planet.mass)), new Column().header("Atmosphere").headerAlign(LEFT).dataAlign(CENTER).with(planet -> planet.atmosphere)))); ``` -------------------------------- ### Constrain AsciiTable Width with MaxTableWidth Source: https://context7.com/freva/ascii-table/llms.txt Set a maximum width for the entire table using `maxTableWidth()`. Columns will be proportionally adjusted to fit within this constraint, respecting any defined minimum or maximum column widths. ```java String table = AsciiTable.builder() .data(planets, Arrays.asList( new Column().with(planet -> Integer.toString(planet.num)), new Column().minWidth(10).with(planet -> planet.name), new Column().with(planet -> String.format("%.03f", planet.diameter)), new Column().with(planet -> String.format("%.02f", planet.mass)), new Column().maxWidth(12).with(planet -> planet.atmosphere) )) .maxTableWidth(50) .asString(); ``` -------------------------------- ### Configure overflow behavior in Java Source: https://github.com/freva/ascii-table/blob/master/README.md Specify OverflowBehaviour when setting maxWidth to handle text that exceeds the column width limit. ```java System.out.println(AsciiTable.getTable(planets, Arrays.asList( new Column().header("Atmosphere Composition").maxWidth(12, OverflowBehaviour.NEWLINE).with(planet -> planet.atmosphere), new Column().header("Atmosphere Composition").maxWidth(12, OverflowBehaviour.CLIP_LEFT).with(planet -> planet.atmosphere), new Column().header("Atmosphere Composition").maxWidth(12, OverflowBehaviour.CLIP_RIGHT).with(planet -> planet.atmosphere), new Column().header("Atmosphere Composition").maxWidth(12, OverflowBehaviour.ELLIPSIS_LEFT).with(planet -> planet.atmosphere), new Column().header("Atmosphere Composition").maxWidth(12, OverflowBehaviour.ELLIPSIS_RIGHT).with(planet -> planet.atmosphere)))); new Column().header("Atmosphere Composition").maxWidth(12, OverflowBehaviour.ELLIPSIS_CENTER).with(planet -> planet.atmosphere)))); ``` -------------------------------- ### Configure Column Overflow Behavior Source: https://context7.com/freva/ascii-table/llms.txt Control how text exceeding maxWidth is handled: NEWLINE (default), CLIP_LEFT, CLIP_RIGHT, ELLIPSIS_LEFT, ELLIPSIS_RIGHT, or ELLIPSIS_CENTER. ```java String table = AsciiTable.getTable(planets, Arrays.asList( new Column() .header("Newline") .maxWidth(12, OverflowBehaviour.NEWLINE) .with(planet -> planet.atmosphere), new Column() .header("Clip Left") .maxWidth(12, OverflowBehaviour.CLIP_LEFT) .with(planet -> planet.atmosphere), new Column() .header("Clip Right") .maxWidth(12, OverflowBehaviour.CLIP_RIGHT) .with(planet -> planet.atmosphere), new Column() .header("Ellipsis L") .maxWidth(12, OverflowBehaviour.ELLIPSIS_LEFT) .with(planet -> planet.atmosphere), new Column() .header("Ellipsis R") .maxWidth(12, OverflowBehaviour.ELLIPSIS_RIGHT) .with(planet -> planet.atmosphere), new Column() .header("Ellipsis C") .maxWidth(12, OverflowBehaviour.ELLIPSIS_CENTER) .with(planet -> planet.atmosphere) )); ``` -------------------------------- ### Add Footer to AsciiTable Columns Source: https://github.com/freva/ascii-table/blob/master/README.md Appends a summary row at the bottom of the table, useful for displaying totals or averages. ```java System.out.println(AsciiTable.getTable(planets, Arrays.asList( new Column().with(planet -> Integer.toString(planet.num)), new Column().header("Name").footer("Average").headerAlign(CENTER).dataAlign(RIGHT).with(planet -> planet.name), new Column().header("Diameter").headerAlign(RIGHT).dataAlign(CENTER).footerAlign(CENTER) .footer(String.format("%.03f", planets.stream().mapToDouble(planet -> planet.diameter).average().orElse(0))) .with(planet -> String.format("%.03f", planet.diameter)), new Column().header("Mass").headerAlign(RIGHT).dataAlign(LEFT) .footer(String.format("%.02f", planets.stream().mapToDouble(planet -> planet.mass).average().orElse(0))) .with(planet -> String.format("%.02f", planet.mass)), new Column().header("Atmosphere").headerAlign(LEFT).dataAlign(CENTER).with(planet -> planet.atmosphere)))); ``` -------------------------------- ### Configure column alignments Source: https://github.com/freva/ascii-table/blob/master/README.md Set horizontal alignment for headers and data cells independently using HorizontalAlign. ```java System.out.println(AsciiTable.getTable(planets, Arrays.asList( new Column().with(planet -> Integer.toString(planet.num)), new Column().header("Name").headerAlign(HorizontalAlign.CENTER).dataAlign(HorizontalAlign.LEFT).with(planet -> planet.name), new Column().header("Diameter").with(planet -> String.format("%.03f", planet.diameter)), new Column().header("Mass").with(planet -> String.format("%.02f", planet.mass)), new Column().header("Atmosphere").headerAlign(HorizontalAlign.RIGHT).dataAlign(HorizontalAlign.CENTER).with(planet -> planet.atmosphere)))); ``` -------------------------------- ### Set Maximum Table Width in Java Source: https://github.com/freva/ascii-table/blob/master/README.md Limits the total width of the generated ASCII table to a specified number of characters. ```java System.out.println(AsciiTable.builder().data(planets, Arrays.asList( new Column().with(planet -> Integer.toString(planet.num)), new Column().minWidth(10).with(planet -> planet.name), new Column().with(planet -> String.format("%.03f", planet.diameter)), new Column().with(planet -> String.format("%.02f", planet.mass)), new Column().maxWidth(12).with(planet -> planet.atmosphere))) .maxTableWidth(50) .asString()); ``` -------------------------------- ### Configure Column Alignment Source: https://context7.com/freva/ascii-table/llms.txt Set horizontal alignment for headers, data, and footers independently using the HorizontalAlign enum (LEFT, CENTER, RIGHT). ```java String table = AsciiTable.getTable(planets, Arrays.asList( new Column().with(planet -> Integer.toString(planet.num)), new Column() .header("Name") .headerAlign(HorizontalAlign.CENTER) .dataAlign(HorizontalAlign.LEFT) .with(planet -> planet.name), new Column() .header("Diameter") .with(planet -> String.format("%.03f", planet.diameter)), new Column() .header("Mass") .with(planet -> String.format("%.02f", planet.mass)), new Column() .header("Atmosphere") .headerAlign(HorizontalAlign.RIGHT) .dataAlign(HorizontalAlign.CENTER) .with(planet -> planet.atmosphere) )); ``` -------------------------------- ### Applying ANSI Color and Formatting with Styler Source: https://context7.com/freva/ascii-table/llms.txt Utilizes the Styler interface to apply ANSI escape codes for terminal colors and formatting to table headers and cells. This allows for colored output without affecting table alignment. Ensure ANSI escape codes are correctly defined. ```java String BOLD = "\u001b[1m"; String RED = "\u001b[31m"; String GREEN = "\u001b[32m"; String RESET = "\u001b[0m"; ``` ```java String table = AsciiTable.builder() .border(AsciiTable.BASIC_ASCII) .styler(new Styler() { @Override public List styleHeader(Column column, int col, List data) { return data.stream() .map(line -> BOLD + line + RESET) .collect(Collectors.toList()); } @Override public List styleCell(Column column, int row, int col, List data) { // Color negative numbers red, positive green String color = row % 2 == 0 ? GREEN : RED; return data.stream() .map(line -> color + line + RESET) .collect(Collectors.toList()); } }) .data(planets, Arrays.asList( new Column().header("Name").with(planet -> planet.name), new Column().header("Mass").with(planet -> String.format("%.02f", planet.mass)) )) .asString(); ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.