box-cli-maker

Make Highly Customized Boxes for your CLI
授权协议 MIT License
开发语言 SHELL
所属分类 应用工具、 终端/远程登录
软件类型 开源软件
地区 不详
投 递 者 林魁
操作系统 跨平台
开源组织
适用人群 未知
 软件概览

Box CLI Maker ��

Box CLI Maker is a Highly Customized Terminal Box Creator.

CI

Features

  • Make Terminal Box in 8️⃣ inbuilt different styles
  • 16 Inbuilt Colors and True Color Support ��
  • Custom Title Positions
  • Make your own Terminal Box style ��
  • Align the text according to the need
  • Unicode, Emoji and Windows Console Support ��
  • Written in �� ��

Installation

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

Usage

In main.go

package main

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

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
    • TitlePos : Position of the Title i.e. Inside, Top and Bottom
    • Color : Color of the Box

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 Double

  • Double

  • Double Single

  • Bold

  • Round

  • Hidden

  • Classic

Title Positions

  • Inside

  • Top

  • Bottom

Making custom Box

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

type Box struct {
 TopRight    string // Symbols used for TopRight Corner
 TopLeft     string // Symbols used for TopLeft Corner
 Vertical    string // Symbols used for Vertical Bars
 BottomRight string // Symbols used for BottomRight Corner
 BottomLeft  string // Symbols used for BottomRight Corner
 Horizontal  string // Symbols used for Horizontal Bars
 Config // Config for the Box struct
}

An example:

package main

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

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

Output:

Color Types

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

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

 fgHiColors map[string]color.Color = {
  "HiBlack":   color.FgDarkGray,
  "HiBlue":    color.FgLightBlue,
  "HiRed":     color.FgLightRed,
  "HiGreen":   color.FgLightGreen,
  "HiYellow":  color.FgLightYellow,
  "HiCyan":    color.FgLightCyan,
  "HiMagenta": color.FgLightMagenta,
  "HiWhite":   color.FgLightWhite,
}

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

  1. True Color is also possible though you need to provide it as uint or [3]uint and make sure that the terminals which will be targetted must have it supported.

  2. [3]uint's element all must be in a range of [0, 0xFF] and uint in range of [0x000000, 0xFFFFFF].

As convenience, if the terminal's doesn't support True Color then it will round off according to the terminal's max supported colors which makes it easier for the users not to worry about other terminal for most of the cases.

Here's a list of 24 bit supported terminals and 8 bit supported terminals.

This module also enables True Color and 256 Colors support on Windows Console through Virtual Terminal Processing but you need have at least Windows 10 Version 1511 for 256 colors or Windows 10 Version 1607 for True Color Support.

4-bit Colors are now standardized so it should supported by all terminals now.

If ConEmu or ANSICON is installed for Windows systems then it will be also detected. It is highly recommended to use the latest versions of both of them to have the best experience!

Note

1. 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.

2. Limitations of Unicode and Emoji

It uses mattn/go-runewidth for Unicode and Emoji support though there are some limitations:

  • Windows Terminal, ConEmu and Mintty are the only know terminal emulators which can render Unicode and Emojis properly on Windows.
  • Indic Text only works on very few Terminals as less support it.
  • It is recommended not to use this for Online Playgrounds like Go Playground and Repl.it, CI/CDs etc. 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.
  • Some changes will be needed to your font which supports Unicode and Emojis else the right vertical alignment will break.

3. Terminal Color Detection

It is possible to round off true color provided to 8 bit or 16 bit according to your terminal's maximum capacity.

There is no standardized way of detecting the terminal's maximum color capacity so the way of detecting your terminal might not work for you. If this can be fixed for your terminal then you can always make a PR.

The following two points are just applicable for Unix systems:

  • If you think that the module can't detect True Color of the terminal then you must set your environment variable COLORTERM to truecolor or 24bit for True Color support.

  • If you are targetting 8 bit color based terminals and the module couln't detect it then set your environment variable TERM to name of the terminal emulator with 256color as suffix like xterm-256color.

There might be no color effect for very old terminals like Windows Console (Legacy Mode) or TERM environment variable which gives DUMB so the module will output some garbage value or a warning if used.

In Online Playgrounds, CI/CDs, Browsers etc, it is recommended not to use this module with color effect as few may have it but this is hard to detect in general. If you think that it's possible then open an issue and address the solution!

Projects using Box CLI Maker

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 the code and told me the best possible ways to fix my problems and @JalonSolov for tab lines support.

Kudos to moul/golang-repo-template for their Go template.

License

Licensed under MIT

  • (一)Vue-CLI and Leaflet:起步 - 在 Vue-CLI 中使用 Leaflet (二)Vue-CLI and Leaflet:地图基本操作(放大,缩小,平移,定位等) (三)Vue-CLI and Leaflet: 添加 marker, polyline, polygon (四)Vue-CLI and Leaflet: 添加 tooltips 和 popup (五)Vue-CL

 相关资料
  • gtk.Box类是一个抽象类,用于定义容器的功能,其中窗口小部件放置在矩形区域中。 gtk.HBox和gtk.VBox小部件都是从它派生的。 gtk.Hbox中的子窗口小部件水平排列在同一行中。 另一方面,gtk.VBox的子窗口小部件垂直排列在同一列中。 gtk.Box类使用以下构造函数 - gtk.Box(homogenous = True, spacing = 0) homogenous属

  • Box

    长方体是三维或实心形状。 长方体由6个矩形制成,它们以直角放置。 使用方形面的长方体是一个立方体,如果面是矩形,而不是立方体,它看起来像一个鞋盒。 长方体是三维形状,具有length (深度), width和height ,如下图所示 - 在JavaFX中,三维框由名为Box的类表示。 该类属于包javafx.scene.shape 。 通过实例化此类,您可以在JavaFX中创建Box节点。 这个

  • Box

    「Box」是 Hexo 用来处理特定文件夹中的文件的容器,在 Hexo 中有两个 Box,分别是 hexo.source 和 hexo.theme,前者用于处理 source 文件夹,而后者用于处理主题文件夹。 载入文件 Box 提供了两种方法来载入文件:process, watch,前者用于载入文件夹内的所有文件;而后者除了执行 process 以外,还会继续监视文件变动。 box.proces

  • Box

    Box 是一种专门设计用于简化矢量图形的语言,另外还有一个集成的开发环境,该环境通过交互显示图形输出来促进该语言的使用。Box结合了使用鼠标绘制图形的便利性和使用针对矢量图形量身定制的语言描述图形的便利性。 特性 具有自动边界框计算功能,另存为PNG,PDF,SVG,PS GUI编辑脚本并查看结果

  • 了解如何在Java编程中使用PDF Box。 以下是示例 - 如何使用Java创建一个空的PDF文档。 如何使用Java将页面添加到PDF文档。 如何使用Java从PDF文档中删除页面。 如何使用Java向PDF添加文本。 如何使用Java在PDF中插入图像。 如何使用Java将PDF拆分为多个。 如何使用Java合并两个PDF。 如何使用java从PDF中提取图像。

  • 问题内容: 我想为标签。 对于 Mozila Firefox, 我尝试过 对于 IE(Internet Explorer), 我已经尝试了以下两种方法 但它不能在 IE(Internet Explorer)中工作 。虽然我已经申请 了 Internet Explorer, 但它在元素的宽度中添加了边框和填充。为什么会发生? 应该是什么问题?请帮助并向我求婚。 注意: 我使用的是 Internet