Introduce Examples class with comprehensive demos and enhance table/log functionalities
- Add `Examples` class showcasing extensive usage of terminal-ui components (e.g., tables, logs, heatmaps, charts, and trees). - Extend `Table` API with `rows` and `fromRows` methods for batch row addition and simplified table creation. - Enhance `Log` component with a `minLevel` filtering feature for selective log visibility. - Update `build.gradle.kts` to set `Examples` class as the main application entry point. - Expand `Examples.md` documentation with new examples, including table rows and filtered logs.
This commit is contained in:
@@ -37,6 +37,21 @@ Terminal.table()
|
||||
.row("1", "2", "3")
|
||||
.row("4", "5", "6")
|
||||
.print(System.out);
|
||||
|
||||
// From a list of rows (e.g. from CSV or DB)
|
||||
List<String[]> rows = List.of(
|
||||
new String[]{"Alice", "10"},
|
||||
new String[]{"Bob", "20"}
|
||||
);
|
||||
Terminal.table()
|
||||
.header("Name", "Score")
|
||||
.rows(rows)
|
||||
.print(System.out);
|
||||
|
||||
// One-liner with header + data
|
||||
Terminal.table()
|
||||
.fromRows(new String[]{"A", "B"}, List.of(new String[]{"1", "2"}, new String[]{"3", "4"}))
|
||||
.print(System.out);
|
||||
```
|
||||
|
||||
## Tree
|
||||
@@ -178,8 +193,18 @@ Terminal.log()
|
||||
.error("Something failed")
|
||||
.withTimestamp()
|
||||
.print(System.out);
|
||||
|
||||
// Only WARN and ERROR (e.g. for production)
|
||||
Terminal.log()
|
||||
.info("Hidden")
|
||||
.warn("Visible")
|
||||
.error("Visible")
|
||||
.minLevel(Log.Level.WARN)
|
||||
.print(System.out);
|
||||
```
|
||||
|
||||
(Use `import dev.jakub.terminal.components.Log;` for `Log.Level`.)
|
||||
|
||||
## Timeline
|
||||
|
||||
```java
|
||||
|
||||
Reference in New Issue
Block a user