https://github.com/linka-cloud/printer
https://github.com/linka-cloud/printer
Last synced: 3 months ago
JSON representation
- Host: GitHub
- URL: https://github.com/linka-cloud/printer
- Owner: linka-cloud
- License: apache-2.0
- Created: 2023-01-27T20:23:54.000Z (over 2 years ago)
- Default Branch: main
- Last Pushed: 2024-02-21T17:01:21.000Z (over 1 year ago)
- Last Synced: 2024-12-30T07:22:36.742Z (5 months ago)
- Language: Go
- Size: 35.2 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# Printer
Printer is a simple tool to print a table on the terminal.
## Installation
```bash
go get go.linka.cloud/printer
```## Usage
The main exported function is `Print` which takes any value as input and prints it on the terminal.
The table is formatted using the struct's `printer` tags.
It is expected to have the following format: `printer:"(,)"`, or `printer:"-"` to ignore the field.
If no `printer` tag is found, the field name is used as the column name.
**Only exported fields are printed.**
## API
```go
package printer // import "go.linka.cloud/printer"FUNCTIONS
func Print(v any, opts ...Option) (err error)
TYPES
type Encoder func(v any) ([]byte, error)
type Format int
const (
Table Format = iota
JSON
YAML
)
func (f Format) String() stringtype Option func(*printer)
func WithFields(fields ...string) Option
func WithFormat(format Format) Option
func WithFormatter(fieldName string, fn func(v any) string) Option
func WithJSON() Option
func WithJSONMarshaler(fn Encoder) Option
func WithLowerHeaders() Option
func WithLowerValues() Option
func WithMax(max int) Option
func WithNoHeaders() Option
func WithTypeFormatter(t any, fn func(v any) string) Option
func WithUpperHeaders() Option
func WithUpperValues() Option
func WithWriter(writer *tabwriter.Writer) Option
func WithYAML() Option
func WithYAMLMarshaler(fn Encoder) Option
```