gotableview

package module
v0.0.0-...-77ac742 Latest Latest
Warning

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

Go to latest
Published: Oct 12, 2025 License: MIT Imports: 10 Imported by: 0

README

GoTableView (gtv) - Go Table Viewer

A lightweight, Windows-native table viewer for Go with zero external dependencies (except Windows API). Perfect for displaying data with minimal API footprint.

Features

  • 🚀 Zero Dependencies - Uses Windows API directly via syscall
  • 📊 Auto-inference - Automatically extracts columns from structs
  • 🔄 Fluent API - Chainable methods for clean code
  • 📄 Pagination - Built-in support for large datasets
  • 🔍 Search - Filter data in real-time
  • 🔗 plyGO Integration - Seamless integration with plyGO data pipelines
  • Lightweight - Minimal execution overhead

Installation

go get github.com/mansoldof/goTableView

Requires: golang.org/x/sys/windows (automatically installed)

Quick Start

Basic Table
package main

import "github.com/mansoldof/goTableView"

func main() {
// Simple string data
gotableview.New("My Data").
    Columns("Name", "Age", "City").
    Row("Alice", "30", "NYC").
    Row("Bob", "25", "LA").
    Show()
}

goTableView basic table example

Rendered GUI table — built directly from Go code.

From Structs (Auto-inference)
type Person struct {
    Name   string
    Age    int
    City   string
    Salary float64
}

people := []Person{
    {"Alice", 30, "NYC", 75000},
    {"Bob", 25, "LA", 60000},
}

// Columns automatically inferred from struct fields
gotableview.FromStructs("People", people).Show()
goTableView basic table example

Paginated Table
    products := [][]string{
        {"001", "Laptop", "Electronics", "999.99", "15"},
        {"002", "Desk", "Furniture", "299.99", "8"},
        {"003", "Mouse", "Electronics", "24.99", "50"},
        {"004", "Chair", "Furniture", "199.99", "12"},
    }
    
    gotableview.NewPaginated("Products", 50).
        Columns("ID", "Name", "Category", "Price", "Stock").
        Rows(products).
        WithColumnSelector().  // Add dropdown for column selection
        Show()
goTableView basic table example

plyGO Integration

plyGO brings the elegance of R's dplyr to Go, making data manipulation intuitive and enjoyable. Chain operations together to build complex data pipelines with minimal code.

import (
    "github.com/mansoldof/goTableView"
    "github.com/frpm/plygo"
)

func main() {

type Employee struct {
    Name       string
    Age        int
    Department string
    Salary     float64
}

employees := []Employee{
    {"Alice", 40, "Engineering", 75000},
    {"Bob", 25, "Marketing", 60000},
    {"Charlie", 35, "Engineering", 90000},
    {"Diana", 28, "Sales", 70000},
}
// Filters employees where Age > 30 and orders results by Salary in descending order
result := plygo.From(employees).
    Where("Age").GreaterThan(30).
    OrderBy("Salary").Desc().
    Collect()

gotableview.FromStructs("Filtered dataset", result).Show()

}

goTableView basic table example

Non-Blocking Windows
import (
    "fmt"
    "github.com/mansoldof/goTableView"
)

// Show window and continue execution
gotableview.New("Statistics").
    Columns("Metric", "Value").
    Row("Total", "100").
    Show(false)  // Non-blocking - returns immediately

fmt.Println("This prints while window is still open")

// Multiple windows simultaneously
gotableview.FromStructs("Dataset 1", data1).Show(false)
gotableview.FromStructs("Dataset 2", data2).Show(false)
gotableview.FromStructs("Dataset 3", data3).Show(false)

// Wait for all windows to close
gotableview.WaitAll()
fmt.Println("All windows closed!")

// Sequential windows - each closes independently
gotableview.New("Step 1").Columns(...).Show()  // Blocks
gotableview.New("Step 2").Columns(...).Show()  // Opens after Step 1 closes

API Reference

Basic Table
// Create new table
table := gotableview.New(title string) *Table

// Set columns
table.Columns(cols ...string) *Table

// Add single row
table.Row(values ...string) *Table

// Add multiple rows
table.Rows(data [][]string) *Table

// Set column widths (pixels)
table.ColumnWidths(widths ...int) *Table

// Display the table
// hold defaults to true (blocking)
// Show() or Show(true) - blocks until window is closed
// Show(false) - returns immediately, window stays open
table.Show(hold ...bool)

// Wait for all open windows to close
gotableview.WaitAll()
From Structs
// Auto-infer from struct slice
gotableview.FromStructs[T](title string, data []T) *Table

// Auto-infer from map slice
gotableview.FromMaps(title string, data []map[string]any) *Table
Paginated Table
// Create paginated table
table := gotableview.NewPaginated(title string, pageSize int) *PaginatedTable

// Enable search (all columns)
table.WithSearch() *PaginatedTable

// Enable search in specific columns by name
table.SearchInColumns(columnNames ...string) *PaginatedTable

// Enable search in specific columns by index
table.SearchInColumnIndices(indices ...int) *PaginatedTable

// Enable column selector dropdown (user chooses column)
table.WithColumnSelector() *PaginatedTable

// Enable column sorting (future)
table.WithSort() *PaginatedTable

// Same column/row methods as basic table
table.Columns(...).Rows(...).Show()
Struct Tags
type Product struct {
    ID          int     `gotableview:"Product ID"`
    Name        string  `gotableview:"Product Name"`
    Price       float64 `gotableview:"Price ($)"`
    InternalKey string  `gotableview:"-"` // Skip this field
}

Examples

See the examples/ directory for complete examples:

  • examples/basic/ - Basic table usage
  • examples/pagination/ - Pagination and search
  • examples/plygo/ - plyGO integration

Run examples:

cd examples/basic
go run main.go

cd examples/pagination
go run main.go

cd examples/plygo
go run main.go

Type Formatting

Auto-formatting for common types:

  • bool → "Yes" / "No"
  • float32/float64 → 2 decimal places
  • time.Time → "2006-01-02 15:04:05"
  • *T (pointers) → Handled gracefully (nil → empty string)

Platform Support

Windows only (uses native ListView control via Windows API).

For cross-platform table display, consider using terminal-based libraries.

Performance

  • Handles 100K+ rows efficiently with pagination
  • Minimal memory footprint
  • Direct Windows API calls for best performance

License

MIT

Documentation

Index

Constants

View Source
const (
	WS_OVERLAPPEDWINDOW = 0x00CF0000
	WS_VISIBLE          = 0x10000000
	WS_CHILD            = 0x40000000
	WS_VSCROLL          = 0x00200000
	WS_HSCROLL          = 0x00100000
	WS_BORDER           = 0x00800000

	LVS_REPORT           = 0x0001
	LVS_SHOWSELALWAYS    = 0x0008
	LVS_SINGLESEL        = 0x0004
	LVS_EX_FULLROWSELECT = 0x00000020
	LVS_EX_GRIDLINES     = 0x00000001

	LVM_FIRST                    = 0x1000
	LVM_INSERTCOLUMNW            = LVM_FIRST + 97
	LVM_INSERTITEMW              = LVM_FIRST + 77
	LVM_SETITEMW                 = LVM_FIRST + 76
	LVM_SETEXTENDEDLISTVIEWSTYLE = LVM_FIRST + 54
	LVM_GETHEADER                = LVM_FIRST + 31

	LVCF_TEXT  = 0x0004
	LVCF_WIDTH = 0x0002
	LVCF_FMT   = 0x0001

	LVCFMT_LEFT   = 0x0000
	LVCFMT_RIGHT  = 0x0001
	LVCFMT_CENTER = 0x0002

	LVIF_TEXT = 0x0001

	WM_SIZE    = 0x0005
	WM_DESTROY = 0x0002
	WM_CLOSE   = 0x0010
	WM_SETFONT = 0x0030

	CW_USEDEFAULT = 0x80000000

	FW_NORMAL = 400
	FW_BOLD   = 700

	DEFAULT_CHARSET     = 1
	OUT_DEFAULT_PRECIS  = 0
	CLIP_DEFAULT_PRECIS = 0
	DEFAULT_QUALITY     = 0
	DEFAULT_PITCH       = 0
	FF_DONTCARE         = 0

	SW_SHOW = 5
)
View Source
const (
	WS_TABSTOP       = 0x00010000
	BS_PUSHBUTTON    = 0x00000000
	BS_DEFPUSHBUTTON = 0x00000001

	WM_COMMAND = 0x0111
	BN_CLICKED = 0

	ES_LEFT        = 0x0000
	ES_AUTOHSCROLL = 0x0080

	EM_SETSEL        = 0x00B1
	EM_GETLINE       = 0x00C4
	WM_GETTEXT       = 0x000D
	WM_GETTEXTLENGTH = 0x000E
	WM_SETTEXT       = 0x000C

	// ComboBox styles and messages
	CBS_DROPDOWNLIST = 0x0003
	CBS_HASSTRINGS   = 0x0200
	CB_ADDSTRING     = 0x0143
	CB_GETCURSEL     = 0x0147
	CB_SETCURSEL     = 0x014E
	CBN_SELCHANGE    = 1
)

Variables

This section is empty.

Functions

func Show

func Show(title string, columns []string, rows [][]string)

func ShowWithWidths

func ShowWithWidths(title string, columns []string, widths []int, rows [][]string)

func WaitAll

func WaitAll()

Types

type FontConfig

type FontConfig struct {
	// contains filtered or unexported fields
}

type INITCOMMONCONTROLSEX

type INITCOMMONCONTROLSEX struct {
	Size uint32
	ICC  uint32
}

type LVCOLUMNW

type LVCOLUMNW struct {
	Mask       uint32
	Fmt        int32
	Cx         int32
	PszText    *uint16
	CchTextMax int32
	ISubItem   int32
}

type LVITEMW

type LVITEMW struct {
	Mask       uint32
	IItem      int32
	ISubItem   int32
	State      uint32
	StateMask  uint32
	PszText    *uint16
	CchTextMax int32
}

type MSG

type MSG struct {
	Hwnd    windows.Handle
	Message uint32
	WParam  uintptr
	LParam  uintptr
	Time    uint32
	Pt      POINT
}

type POINT

type POINT struct {
	X, Y int32
}

type PaginatedTable

type PaginatedTable struct {
	*Table
	// contains filtered or unexported fields
}

func FromMapsPaginated

func FromMapsPaginated(title string, data []map[string]any, pageSize int) *PaginatedTable

func FromStructsPaginated

func FromStructsPaginated[T any](title string, data []T, pageSize int) *PaginatedTable

func NewPaginated

func NewPaginated(title string, pageSize int) *PaginatedTable

func (*PaginatedTable) ColumnNames

func (pt *PaginatedTable) ColumnNames(names ...string) *PaginatedTable

func (*PaginatedTable) Columns

func (pt *PaginatedTable) Columns(cols ...string) *PaginatedTable

func (*PaginatedTable) ContentFont

func (pt *PaginatedTable) ContentFont(name string, size int, bold, italic bool) *PaginatedTable

func (*PaginatedTable) HeaderFont

func (pt *PaginatedTable) HeaderFont(name string, size int, bold, italic bool) *PaginatedTable

func (*PaginatedTable) Row

func (pt *PaginatedTable) Row(values ...string) *PaginatedTable

func (*PaginatedTable) Rows

func (pt *PaginatedTable) Rows(data [][]string) *PaginatedTable

func (*PaginatedTable) SearchInColumnIndices

func (pt *PaginatedTable) SearchInColumnIndices(indices ...int) *PaginatedTable

func (*PaginatedTable) SearchInColumns

func (pt *PaginatedTable) SearchInColumns(columnNames ...string) *PaginatedTable

func (*PaginatedTable) Show

func (pt *PaginatedTable) Show(hold ...bool)

func (*PaginatedTable) WithColumnSelector

func (pt *PaginatedTable) WithColumnSelector() *PaginatedTable

func (*PaginatedTable) WithSearch

func (pt *PaginatedTable) WithSearch() *PaginatedTable

func (*PaginatedTable) WithSort

func (pt *PaginatedTable) WithSort() *PaginatedTable

type RECT

type RECT struct {
	Left, Top, Right, Bottom int32
}

type Table

type Table struct {
	// contains filtered or unexported fields
}

func FromMaps

func FromMaps(title string, data []map[string]any) *Table

func FromStructs

func FromStructs[T any](title string, data []T) *Table

func New

func New(title string) *Table

func (*Table) ColumnNames

func (t *Table) ColumnNames(names ...string) *Table

func (*Table) ColumnWidths

func (t *Table) ColumnWidths(widths ...int) *Table

func (*Table) Columns

func (t *Table) Columns(cols ...string) *Table

func (*Table) ContentFont

func (t *Table) ContentFont(name string, size int, bold, italic bool) *Table

func (*Table) Fields

func (t *Table) Fields(fieldNames ...string) *Table

func (*Table) HeaderFont

func (t *Table) HeaderFont(name string, size int, bold, italic bool) *Table

func (*Table) Row

func (t *Table) Row(values ...string) *Table

func (*Table) Rows

func (t *Table) Rows(data [][]string) *Table

func (*Table) Show

func (t *Table) Show(hold ...bool)

type WNDCLASSEXW

type WNDCLASSEXW struct {
	Size       uint32
	Style      uint32
	WndProc    uintptr
	ClsExtra   int32
	WndExtra   int32
	Instance   windows.Handle
	Icon       windows.Handle
	Cursor     windows.Handle
	Background windows.Handle
	MenuName   *uint16
	ClassName  *uint16
	IconSm     windows.Handle
}

Directories

Path Synopsis
examples
basic command
fonts command
independent command
nonblocking command
pagination command

Jump to

Keyboard shortcuts

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