Skip to content

Commit

Permalink
update docs, fix align issue and readme
Browse files Browse the repository at this point in the history
  • Loading branch information
Delta456 committed Nov 10, 2020
1 parent d4289eb commit 6b05cd8
Show file tree
Hide file tree
Showing 5 changed files with 45 additions and 53 deletions.
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ Box CLI Maker is a Highly Customized Terminal Box Creator.

<div align="center">

[![go.dev reference](https://img.shields.io/badge/go.dev-reference-007d9c?logo=go&logoColor=white)](https://pkg.go.dev/github.com/Delta456/box-cli-maker)
[![go.dev reference](https://img.shields.io/badge/go.dev-reference-007d9c?logo=go&logoColor=white)](https://pkg.go.dev/github.com/Delta456/box-cli-maker/v2)
[![CI](https://github.com/Delta456/box-cli-maker/workflows/Box%20CLI%20Maker/badge.svg)](https://github.com/Delta456/box-cli-maker/actions?query=workflow%3A"Box+CLI+Maker")
[![Go Report Card](https://goreportcard.com/badge/github.com/Delta456/box-cli-maker)](https://goreportcard.com/report/github.com/Delta456/box-cli-maker)
[![GolangCI](https://golangci.com/badges/github.com/moul/golang-repo-template.svg)](https://golangci.com/r/github.com/Delta456/box-cli-maker)
Expand Down Expand Up @@ -188,7 +188,7 @@ var fgHiColors = map[string]color.Attribute{

If you want High Intensity Colors then the Color name should start with `Hi`. If Color option is empty or invalid then Box with default Color is formed.

It can even have custom color which can be provided in `[3]uint` and `uint` though the elements of the array must be in a range of `[0x0, 0xFF]` and `uint` must be in a range of `[0x000000, 0xFFFFFF]`.
It can even have custom color which has to be provided as `[3]uint` and `uint` but the elements of the array must be in a range of `[0x0, 0xFF]` and `uint` must be in a range of `[0x000000, 0xFFFFFF]`.

If you want to use the string representation of the `Box` and print them for [`Windows Console`](https://en.wikipedia.org/wiki/Windows_Console) then you would have to use `box.Output` as the passing stream to the respective functions.

Expand All @@ -204,7 +204,7 @@ As different terminals have different font by default so the right vertical alig

It uses [mattn/go-runewidth](https://github.com/mattn/go-runewidth) for Unicode and Emoji support though there are some limitations:

- `Windows Terminal` and `Windows System Linux` are the only know terminals which can render Unicode and Emojis properly on Windows.
- `Windows Terminal` and `Windows SubSystem Linux` are the only know terminals which can render Unicode and Emojis properly on Windows.
- Marathi Text only works on very few Terminals as less support it.
- It is recommended not to use Online Playgrounds like [`Go Playground`](https://play.golang.org/) and [`Repl.it`](https://repl.it) because they use a font that only has ASCII support and other Character Set is used which becomes problematic for finding the length as the font changes during runtime.
- Change your font which supports Unicode and Emojis else the right vertical alignment will break.
Expand Down
6 changes: 3 additions & 3 deletions box.go
Original file line number Diff line number Diff line change
Expand Up @@ -173,7 +173,7 @@ inside:
spacing := space + sideMargin
var format string

if i < titleLen && title != "" {
if i < titleLen && title != "" && b.TitlePos == "Inside" {
format = centerAlign
} else {
format = b.findAlign()
Expand Down Expand Up @@ -235,7 +235,7 @@ func (b Box) Print(title, lines string) {
// then use Default Position which is Inside
if b.TitlePos == "" {
b.TitlePos = "Inside"
} else if b.TitlePos != "Bottom" && b.TitlePos != "Top" {
} else if b.TitlePos != "Inside" && b.TitlePos != "Bottom" && b.TitlePos != "Top" {
errorMsg("[warning]: invalid value provided for TitlePos, using default")
b.TitlePos = "Inside"
}
Expand Down Expand Up @@ -267,7 +267,7 @@ func (b Box) Println(title, lines string) {
// then use Default Position which is Inside
if b.TitlePos == "" {
b.TitlePos = "Inside"
} else if b.TitlePos != "Bottom" && b.TitlePos != "Top" {
} else if b.TitlePos != "Inside" && b.TitlePos != "Bottom" && b.TitlePos != "Top" {
errorMsg("[warning]: invalid value provided for TitlePos, using default")
b.TitlePos = "Inside"
}
Expand Down
83 changes: 38 additions & 45 deletions doc.go
Original file line number Diff line number Diff line change
@@ -1,89 +1,82 @@
/*
Package Box CLI Maker is a Highly Customized Terminal Box Creator written in Go.
It provides many styles and options to make Boxes. There are 8 inbuilt styles and Color support via RGB uint, RGB Array of [3]uint and string (given).
It provides many styles and options to make Boxes. There are 8 inbuilt styles and has Color support via RGB uint, RGB Array of [3]uint and string (given).
Inbuilt Box Styles:
Single
Double
Bold
Single Double
Double Single
Round
Hidden
Single,
Double,
Bold,
Single Double,
Double Single,
Round,
Hidden and
Classic
Inbuilt Colors:
Black
Blue
Red
Yellow
Green
Cyan
Magenta
HiBlack
HiBlue
HiRed
HiYellow
HiGreen
HiCyan
Black,
Blue,
Red,
Yellow,
Green,
Cyan,
Magenta,
HiBlack,
HiBlue,
HiRed,
HiYellow,
HiGreen,
HiCyan and
HiMagenta
It also has Unicode and Emoji support which works across all terminals though there might be some terminals which do not support
Unicode and Emoji like Windows CMD and Powershell. Unlike other terminals makers Box CLI Mkaer supports tab and multi line string.
Unicode and Emoji like Windows CMD and Powershell. Unlike other CLI Makers, Box CLI Maker supports tab and multi line string.
Note: As different terminals have different font by default so the right vertical alignment may not be aligned well.
You will have to change your font accordingly to make it work.
Basic Example:
Box := box.New(box.Config{Px: 2, Py: 5, Type: "Single", Color: "Cyan"})
Box.Print("Box CLI Maker", "Highly Customized Terminal Box Maker")
You can specify and change the options by changing the above Config struct.
If "Style" isn't provided in box.Config struct then by default it will be "Single".
You can customize and change the TitlePos to Inside, Top, Bottom and ContentAlign to Left, Right and Center.
By default TitlePos is Inside and ContentAlign is Left.
Box := box.New(box.Config{Px: 2, Py: 5, Type: "Single", TitlePos: "Top", ContentAlign: "Left"})
If you want the string representation of the Box then you can just use String() method of the Box:
You can also customize and change the TitlePos to Inside, Top, Bottom and ContentAlign to Left, Right and Center.
By default TitlePos is Inside, ContentAlign is Left and Style is Single.
If you want the Box to be printed correctly irrespective of it will form the correct color or not on Windows then you will have to add Box.Output
as the passing stream to Fprintf(), Fprintln() and etc to the passing stream functions:
You can also use the String() method for the string representation of the Box.
if runtime.GOOS == "windows" {
fmt.Fprintf(box.Output, box_str)
}
If you want the Box to be printed correctly irrespective of if it will form the correct Color or not on Windows (as Windows Console only supports 16 Colors) then you will have to add Box.Output
as the passing stream to stream based functions:
Box := box.New(box.Config{Px: 2, Py: 5, Type: "Single", Color: "Cyan"})
b := Box.String("Box CLI Maker", "Highly Customized Terminal Box Maker")
... // use it afterwards
fmt.Fprintf(box.Output, boxStr)
If you do not want the title and lines to be there then you can just leave i.e. put an empty in the both places.const
Box := box.New(box.Config{Px: 2, Py: 5, Type: "Single", Color: "Cyan"})
boxStr := Box.String("Box CLI Maker", "Highly Customized Terminal Box Maker")
The following two will not be applicable for terminals which don't have 24 bit support i.e. True Color ANSI Code.
If used then the color effect will not be there.
The Custom Color option will not be applicable for terminals which don't have 24 bit support i.e. True Color ANSI Code.
If it is used then the Color effect will not be there.
RBG Uint Example:
RGB Uint Example:
Box := box.New(box.Config{Px: 2, Py: 5, Type: "Single", Color: uint(0x34562f)})
Box.Print("Box CLI Maker", "Highly Customized Terminal Box Maker")
Note: Uint must be in a range of [0x000000, 0xFFFFFF] else it will panic.
RBG [3]uint Example:
RGB [3]uint Example:
Box := box.New(box.Config{Px: 2, Py: 5, Type: "Single", Color: [3]uint{23, 56, 78}})
Box.Print("Box CLI Maker", "Highly Customized Terminal Box Maker")
Note: [3]uint array elements must be in a range of [0x0, 0xFF] else it will panic.
You can even make your custom Box Style by using box.Box struct:
You can even make your custom Box Style by using struct box.Box:
config := box.Config{Px: 2, Py: 3, Type: "", TitlePos: "Inside"}
boxNew := box.Box{TopRight: "*", TopLeft: "*", BottomRight: "*", BottomLeft: "*", Horizontal: "-", Vertical: "|", Config: config}
... // use it afterwards
*/

package box
2 changes: 1 addition & 1 deletion types.go
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,6 @@ var (
}
// Output is an io.Writer and instance of
// color.Output which is needed
// for outputting in windows console
// for outputting on Windows Console
Output = color.Output
)
1 change: 0 additions & 1 deletion util.go
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,6 @@ func longestLine(lines []string) (int, []expandedLine) {
}

lineLen = runewidth.StringWidth(tmpLine.String())

expandedLines = append(expandedLines, expandedLine{tmpLine.String(), lineLen})

if lineLen > longest {
Expand Down

0 comments on commit 6b05cd8

Please sign in to comment.