olog

package module
v0.1.20 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Mar 19, 2022 License: Apache-2.0 Imports: 5 Imported by: 2

README

Go CodeQL

olog

This is a box printing library for Go. It takes any array of structs and assembles an ascii box around the objects. This logger is not meant for large amount of data and instead should be used only on smaller arrays.

Installation

To download the library, simply run:

$ go get github.com/da0x/golang/olog

To import olog in your code, use:

import "github.com/da0x/golang/olog"
Example

Here is an example of how to use olog:

type Data struct {
	Name  string
	Age   int
	Score float32
}

func main() {
	var data = []Data{
		Data{Name: "John Smith", Age: 30, Score: 100.0},
		Data{Name: "Jane Smith", Age: 30, Score: 100.0},
	}
	olog.Print(data)
}

The above example prints the following output:

┌────────────┬─────┬────────┐
│ Name       │ Age │ Score  │
├────────────┼─────┼────────┤
│ John Smith │ 30  │ 99.223 │
│ Jane Smith │ 30  │ 99.223 │
└────────────┴─────┴────────┘

Styles

Here are the available styles

Soft
olog.Print(olog.Soft, data)
╭────────────┬─────┬────────╮
│ Name       │ Age │ Score  │
├────────────┼─────┼────────┤
│ John Smith │ 30  │ 99.223 │
│ Jane Smith │ 30  │ 99.223 │
╰────────────┴─────┴────────╯
Bold
olog.Print(olog.Bold, data)
┏━━━━━━━━━━━━┳━━━━━┳━━━━━━━━┓
┃ Name       ┃ Age ┃ Score  ┃
┣━━━━━━━━━━━━╋━━━━━╋━━━━━━━━┫
┃ John Smith ┃ 30  ┃ 99.223 ┃
┃ Jane Smith ┃ 30  ┃ 99.223 ┃
┗━━━━━━━━━━━━┻━━━━━┻━━━━━━━━┛
Strong
olog.Print(olog.Strong, data)
╔════════════╦═════╦════════╗
║ Name       ║ Age ║ Score  ║
╠════════════╬═════╬════════╣
║ John Smith ║ 30  ║ 99.223 ║
║ Jane Smith ║ 30  ║ 99.223 ║
╚════════════╩═════╩════════╝
Vertical Strong
olog.Print(olog.VStrong, data)
╓────────────╥─────╥────────╖
║ Name       ║ Age ║ Score  ║
╟────────────╫─────╫────────╢
║ John Smith ║ 30  ║ 99.223 ║
║ Jane Smith ║ 30  ║ 99.223 ║
╙────────────╨─────╨────────╜
Horizontal Strong
olog.Print(olog.HStrong, data)
╒════════════╤═════╤════════╕
│ Name       │ Age │ Score  │
╞════════════╪═════╪════════╡
│ John Smith │ 30  │ 99.223 │
│ Jane Smith │ 30  │ 99.223 │
╘════════════╧═════╧════════╛
Clear
olog.Print(olog.Clear, data)
 Name         Age   Score 
                          
 John Smith   30    99.223
 Jane Smith   30    99.223
Markdown
olog.Print(olog.Markdown, data)
| Name       | Age | Score  |
|:----------:|:---:|:------:|
| John Smith | 30  | 99.223 |
| Jane Smith | 30  | 99.223 |
Block
olog.Print(olog.Block, data)
▛▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▜
▌ Name       ┃ Age ┃ Score  ▐
▌━━━━━━━━━━━━╋━━━━━╋━━━━━━━━▐
▌ John Smith ┃ 30  ┃ 99.223 ▐
▌ Jane Smith ┃ 30  ┃ 99.223 ▐
▙▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▟
Maintainer

Daher Alfawares

Documentation

Index

Constants

This section is empty.

Variables

View Source
var Block = Style{
	T: StyleRow{B: "▛▀", M: "▀", I: "▀▀▀", E: "▀▜"},
	M: StyleRow{B: "▌ ", M: " ", I: " ┃ ", E: " ▐"},
	S: StyleRow{B: "▌━", M: "━", I: "━╋━", E: "━▐"},
	L: StyleRow{B: "▙▄", M: "▄", I: "▄▄▄", E: "▄▟"},
	B: StyleSep{B: "▌■", M: "■", U: "■", I: "■", L: "■", E: "■▐"},
}

Block is a slim border with a double lined horizantal borders.

View Source
var Bold = Style{
	T: StyleRow{B: "┏━", M: "━", I: "━┳━", E: "━┓"},
	M: StyleRow{B: "┃ ", M: " ", I: " ┃ ", E: " ┃"},
	S: StyleRow{B: "┣━", M: "━", I: "━╋━", E: "━┫"},
	L: StyleRow{B: "┗━", M: "━", I: "━┻━", E: "━┛"},
	B: StyleSep{B: "┣━", M: "━", U: "┻", I: "╋", L: "┳", E: "━┫"},
}

Bold is a thin bordered table.

View Source
var Clear = Style{
	T: StyleRow{B: " ", M: " ", I: "   ", E: ""},
	M: StyleRow{B: " ", M: " ", I: "   ", E: ""},
	S: StyleRow{B: " ", M: " ", I: "   ", E: ""},
	L: StyleRow{B: " ", M: " ", I: "   ", E: ""},
	B: StyleSep{B: "", M: "", U: "", I: "", L: "", E: ""},
}

Clear is a thin bordered table.

View Source
var HStrong = Style{
	T: StyleRow{B: "╒═", M: "═", I: "═╤═", E: "═╕"},
	M: StyleRow{B: "│ ", M: " ", I: " │ ", E: " │"},
	S: StyleRow{B: "╞═", M: "═", I: "═╪═", E: "═╡"},
	L: StyleRow{B: "╘═", M: "═", I: "═╧═", E: "═╛"},
	B: StyleSep{B: "╞═", M: "═", U: "╧", I: "╪", L: "╤", E: "═╡"},
}

StrongHorizantal is a slim border with a double lined horizantal borders.

View Source
var Markdown = Style{
	T: StyleRow{B: "  ", M: " ", I: "   ", E: "  "},
	M: StyleRow{B: "| ", M: " ", I: " | ", E: " |"},
	S: StyleRow{B: "|:", M: "-", I: ":|:", E: ":|"},
	L: StyleRow{B: "  ", M: " ", I: "   ", E: "  "},
	B: StyleSep{B: "", M: "", U: "", I: "", L: "", E: ""},
}

Markdown is a thin bordered table.

View Source
var Normal = Style{
	T: StyleRow{B: "┌─", M: "─", I: "─┬─", E: "─┐"},
	M: StyleRow{B: "│ ", M: " ", I: " │ ", E: " │"},
	S: StyleRow{B: "├─", M: "─", I: "─┼─", E: "─┤"},
	L: StyleRow{B: "└─", M: "─", I: "─┴─", E: "─┘"},
	B: StyleSep{B: "├─", M: "─", U: "┴", I: "┼", L: "┬", E: "─┤"},
}

Normal is a thin bordered table.

View Source
var Soft = Style{
	T: StyleRow{B: "╭─", M: "─", I: "─┬─", E: "─╮"},
	M: StyleRow{B: "│ ", M: " ", I: " │ ", E: " │"},
	S: StyleRow{B: "├─", M: "─", I: "─┼─", E: "─┤"},
	L: StyleRow{B: "╰─", M: "─", I: "─┴─", E: "─╯"},
	B: StyleSep{B: "╞═", M: "═", U: "╧", I: "╪", L: "╤", E: "═╡"},
}

Soft is a thin bordered table.

View Source
var Strong = Style{
	T: StyleRow{B: "╔═", M: "═", I: "═╦═", E: "═╗"},
	M: StyleRow{B: "║ ", M: " ", I: " ║ ", E: " ║"},
	S: StyleRow{B: "╠═", M: "═", I: "═╬═", E: "═╣"},
	L: StyleRow{B: "╚═", M: "═", I: "═╩═", E: "═╝"},
	B: StyleSep{B: "╠═", M: "═", U: "╩", I: "╬", L: "╦", E: "═╣"},
}

Strong is a double lined table.

View Source
var VStrong = Style{
	T: StyleRow{B: "╓─", M: "─", I: "─╥─", E: "─╖"},
	M: StyleRow{B: "║ ", M: " ", I: " ║ ", E: " ║"},
	S: StyleRow{B: "╟─", M: "─", I: "─╫─", E: "─╢"},
	L: StyleRow{B: "╙─", M: "─", I: "─╨─", E: "─╜"},
	B: StyleSep{B: "╟─", M: "─", U: "╨", I: "╫", L: "╥", E: "─╢"},
}

StrongVertical is a slim border with a double lined vertical borders.

Functions

func Print

func Print(input ...interface{})

func Sprint added in v0.1.20

func Sprint(input ...interface{}) string

Types

type Style

type Style struct {
	T StyleRow
	M StyleRow
	S StyleRow
	L StyleRow
	B StyleSep
}

Style represents the table structure in 4 strings. 't' for top. 'm' for middle. 's' for seperator. 'b' for bottom. ┌─┬┐ ╔═╦╗ ╓─╥╖ ╒═╤╕ │ ││ ║ ║║ ║ ║║ │ ││ ├─┼┤ ╠═╬╣ ╟─╫╢ ╞═╪╡ └─┴┘ ╚═╩╝ ╙─╨╜ ╘═╧╛ ┌───────────────────┐ │ ╔═══╗ Some Text │▒ │ ╚═╦═╝ in the box │▒ ╞═╤══╩══╤═══════════╡▒ │ ├──┬──┤ │▒ │ └──┴──┘ │▒ └───────────────────┘▒

▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒

https://en.wikipedia.org/wiki/Box-drawing_character

type StyleRow

type StyleRow struct {
	B string
	M string
	I string
	E string
}

StyleRow represents one row of a style. b for begining. m for middle. i for intersection. e for end.

type StyleSep added in v0.1.7

type StyleSep struct {
	B string
	M string
	U string
	I string
	L string
	E string
}

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL