diff --git a/README.md b/README.md index 5327918..dd0fe36 100644 --- a/README.md +++ b/README.md @@ -5,6 +5,8 @@ # Terminal Table +![example](./example.png) + ### How To Use ```shell @@ -14,22 +16,22 @@ go get github.com/ICU-Coders/table import "github.com/ICU-Coders/table" table.Show([]string{"Module", "Type", "Path", "Author"}, [][]string{ - {"1", "2", "3", "4"}, + {"1", "2", "3", "4"}, {"1", "2", "3", "4"}, {"1", "2", "3", "4"}, {"1", "2", "3", "4"}, }) ``` -![example](./example.png) ### Config ```go var MaxCellWidth = 40 -var LineEndTag = "*" +var LineEndTag = "+" var LineBody = "-" var LineDivider = "|" ``` + Example ```go func TestShow(t *testing.T) { @@ -55,6 +57,33 @@ Display / 1 / 2 / 3 / 4 / *========*======*======*========* ``` + +### Auto warp + +```go +MaxCellWidth = 20 // default 40 +Show([]string{"Module", "Type", "Path", "Author"}, [][]string{ + {"11111111111111111111111111111111111111", "2", "3", "4"}, + {"1", "2", "3", "4"}, + {"1", "2", "3", "4"}, + {"1", "2", "3", "4"}, +}) + + +``` + +```go ++----------------------+------+------+--------+ +| Module | Type | Path | Author | ++----------------------+------+------+--------+ +| 11111111111111111111 | 2 | 3 | 4 | +| 111111111111111111 | | | | +| 1 | 2 | 3 | 4 | +| 1 | 2 | 3 | 4 | +| 1 | 2 | 3 | 4 | ++----------------------+------+------+--------+ +``` + ## MIT License Copyright (c) 2022 ICU-Coders diff --git a/example.png b/example.png index 43e2bca..48952ac 100644 Binary files a/example.png and b/example.png differ diff --git a/main.go b/main.go index 728c442..4e3f855 100644 --- a/main.go +++ b/main.go @@ -7,7 +7,7 @@ import ( ) var MaxCellWidth = 40 -var LineEndTag = "*" +var LineEndTag = "+" var LineBody = "-" var LineDivider = "|" diff --git a/main_test.go b/main_test.go index 06b5972..81d429d 100644 --- a/main_test.go +++ b/main_test.go @@ -3,11 +3,12 @@ package table import "testing" func TestShow(t *testing.T) { - LineEndTag = "*" - LineBody = "=" - LineDivider = "/" + //LineEndTag = "*" + //LineBody = "=" + //LineDivider = "/" + MaxCellWidth = 20 Show([]string{"Module", "Type", "Path", "Author"}, [][]string{ - {"1111", "2", "3", "4"}, + {"11111111111111111111111111111111111111", "2", "3", "4"}, {"1", "2", "3", "4"}, {"1", "2", "3", "4"}, {"1", "2", "3", "4"},