table

package module
v0.0.0-...-115f8d0 Latest Latest
Warning

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

Go to latest
Published: Jan 22, 2023 License: MIT Imports: 3 Imported by: 0

README

Golang Table Creator

Go Report Card

What is the aim of this?

I have posted my simple golang table creation tool for my past project that was never completed. I shall be posting more aspects of that project as time goes along, however I am still in the process of optimising those items to be posted, this includes tidying the code and making it more optimal to use than its current situation.

How do I use this?

It is simple, you just create the table contents, these are called headers. Inside of headers there is the store to contain all of the items that you want for that specific header inside.

Do not worry if some header objects have more items than another because the draw function will take that into account and resolve that issue with a blank space.

Example

package main

import (
    // Import the table from github.
    "github.com/prmzelol/go-table-creation"
    "fmt"
)

func main() {
    // Create the table contents.
    headers := []*table.Header{
        // Example data goes here.
		{
			Title: "header 1",
			Body: []string{
				"some",
				"data",
				"goes",
				"here",
			},
		},
		{
			Title: "header 2",
			Body: []string{
				"some more",
				"data goes",
				"in here",
			},
		},
		{
			Title: "header 3",
			Body: []string{
				"some more data",
				"goes in here",
			},
		},
	}

    // Create the new table.
    t := table.New(headers)
    // Execute the table by parsing the headers and drawing the table.
    t.Execute()
    fmt.Println(t.String()) // Print the final form of the table.
}
header 1 │header 2  │header 3       
─────────┼──────────┼───────────────
some     │some more │some more data 
data     │data goes │goes in here   
goes     │in here   │               
here     │          │                

Please Note

Any complaints or questions you have against this repository, please do not hesitate to message my discord: prmze#0797 with your complaint or querey.

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Repeat

func Repeat(item, wr string, count int) string

Types

type Header struct {
	// Title is the headers title.
	Title string
	// Body is where the header data is stored.
	Body []string
	// Longest item is the length of the longest item in the header.
	Longest int
}

Header model is used for storing the header data.

type Table

type Table struct {
	// Headers array stores the headers and the data inside of them.
	Headers []*Header
	// Canvas is where the table render is written to.
	Canvas *strings.Builder
	// Columns is how many columns the table needs to print.
	Columns int
}

Table model is used for storing table data.

func New

func New(h []*Header) *Table

func (*Table) Draw

func (t *Table) Draw()

func (*Table) Execute

func (t *Table) Execute()

func (*Table) ParseHeaders

func (t *Table) ParseHeaders()

func (*Table) String

func (t *Table) String() string

Jump to

Keyboard shortcuts

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