loading...

Box CLI Maker 📦: Highly Customized Terminal Box Creator

delta456 profile image Swastik Baranwal Updated on ・4 min read

Box CLI Maker is a Highly Customized Terminal Box Creator written in Go. It is also my first module ever written so I am very proud releasing this!

Github

GitHub logo Delta456 / box-cli-maker

Make highly customized Boxes for your CLI with Box CLI Maker

Box CLI Maker 📦

go.dev reference Build Status Go Report Card

Box CLI Maker is a Highly Customized Terminal Box Creator.

Features

  • Make Terminal Box in 8️⃣ inbuilt different style
  • Color Support 🎨
  • Custom Title Positions
  • Make your own Terminal Box style 📦
  • Align the text according to the need
  • Unicode and Emoji Support 😋
  • Written in 🇬 🇴

Installation

 go get github.com/Delta456/box-cli-maker

Usage

In main.go

package main
import "github.com/Delta456/box-cli-maker"
func main() {
    Box := box.New(box.Config{Px: 2, Py: 5, Type: "Single", Color: "Cyan"})
    Box.Print("Box CLI Maker", "Highly Customized Terminal Box Maker")
}

box.New(config Config) accepts a Config struct with following parameters and returns a Box struct.

  • Parameters
    • Px : Horizontal Padding
    • Py : Vertical Padding
    • ContentAlign : Align the content inside the Box i.e. Center, Left and Right
    • Type: Type of Box click

Features

  • Make Terminal Box in 8️⃣ inbuilt different style
  • Color Support 🎨
  • Custom Title Positions
  • Make your own Terminal Box style 📦
  • Align the text according to the need
  • Unicode and Emoji Support 😋
  • Written in 🇬 🇴

Installation

 go get github.com/Delta456/box-cli-maker

Usage

In main.go

package main

import "github.com/Delta456/box-cli-maker"

func main() {
    Box := box.New(box.Config{Px: 2, Py: 5, Type: "Single", Color: "Cyan"})
    Box.Print("Box CLI Maker", "Highly Customized Terminal Box Maker")
}

box.New(config Config) accepts a Config struct with following parameters and returns a Box struct.

  • Parameters
    • Px : Horizontal Padding
    • Py : Vertical Padding
    • ContentAlign : Align the content inside the Box i.e. Center, Left and Right
    • Type: Type of Box (see below)
    • TitlePos : Position of the Title i.e. Inside, Top and Bottom (see below)
    • Color : Color of the Box (see below)

Box struct Methods

Box.Print(title, lines string) prints Box from the specified arguments.

  • Parameters
    • title : Title of the Box
    • lines : Content to be written inside the Box

Box.Println(title, lines string) prints Box in a newline from the specified arguments.

  • Parameters
    • title : Title of the Box
    • lines : Content to be written inside the Box

Box.String(title, lines string) string return string representation of Box.

  • Parameters
    • title : Title of the Box
    • lines : Content to be written inside the Box

Box Types

  • Single

single

  • Single Double

single_double

  • Double

double

  • Double Single

double_single

  • Bold

bold

  • Round

round

  • Hidden

hidden

  • Classic

classic

Title Positions

  • Inside

single

  • Top

top

  • Bottom

bottom

Making custom Box

You can make your custom Box by using the inbuilt Box struct provided by the module.

type Box struct {
    TopRight    string // TopRight corner used for Symbols
    TopLeft     string // TopLeft corner used for Symbols
    Vertical    string // Symbols used for Vertical Bars
    BottomRight string // BottomRight corner used for Symbols
    BottomLeft  string // BotromLeft corner used for Symbols
    Horizontal  string // Symbols used for Horizontal Bars
    Con      Config // Configuration for the Box to be made
}

Using it:

package main

import "github.com/Delta456/box-cli-maker"

func main() {
    config := box.Config{Px: 2, Py: 3, Type: "", TitlePos: "Inside"}
    boxNew := box.Box{TopRight: "*", TopLeft: "*", BottomRight: "*", BottomLeft: "*", Horizontal: "-", Vertical: "|", Config: config}
    boxNew.Print("Box CLI Maker", "Make Highly Customized Terminal Boxes")
}

Output:

custom

Color Types

It has color support from fatih/color module from which this module uses FgColor and FgHiColor. Color is a key for the following maps:

var fgColors = map[string]color.Attribute{
    "Black":   color.FgBlack,
    "Blue":    color.FgBlue,
    "Red":     color.FgRed,
    "Green":   color.FgGreen,
    "Yellow":  color.FgYellow,
    "Cyan":    color.FgCyan,
    "Magenta": color.FgMagenta,
}

var fgHiColors = map[string]color.Attribute{
    "HiBlack":   color.FgHiBlack,
    "HiBlue":    color.FgHiBlue,
    "HiRed":     color.FgHiRed,
    "HiGreen":   color.FgHiGreen,
    "HiYellow":  color.FgHiYellow,
    "HiCyan":    color.FgHiCyan,
    "HiMagenta": color.FgHiMagenta,
}

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.

Note

Vertical Alignment

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.

Limitations of Unicode and Emoji

It uses 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.
  • Marathi Text only works on very few Terminals as less support it.
  • It is recommended not to use Online Playgrounds like Go Playground and 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.

Acknowledgements

I thank the following people and their packages whom I have studied and was able to port to Go accordingly.

Special thanks to @elimsteve who helped me to optimize and tell me the best ways possible to fix my problems.

Related

License

Licensed under MIT

Discussion

markdown guide
 

The main post has been updated with more information and features!