GithubHelp home page GithubHelp logo

serkonda7 / termtable Goto Github PK

View Code? Open in Web Editor NEW
44.0 5.0 4.0 254 KB

Simple and highly customizable library to display tables in the terminal.

License: MIT License

V 97.92% AMPL 2.08%
terminal table v vlang cli ascii hacktoberfest

termtable's Introduction

V Terminal Tables

CI

Simple and highly customizable library to display tables in the terminal.

Features

Installation

v install serkonda7.termtable

Usage

import serkonda7.termtable as tt

fn main() {
	data := [
		['Name', 'Age', 'Sex'],
		['Max', '13', 'male'],
		['Moritz', '12', 'male'],
		['Lisa', '42', 'female'],
	]
	t := tt.Table{
		data: data
		// The following settings are optional and have these defaults:
		style: .grid
		header_style: .bold
		align: .left
		orientation: .row
		padding: 1
		tabsize: 4
	}
	println(t)
}

Predefined Styles

Supported values for style: ... are:

  • .grid
  • .pretty
  • .plain
  • .simple
  • .fancy_grid
  • .md
  • .rst

.grid (default):

.pretty:

.plain:

.simple:

.fancy_grid:

.md follows the conventions of Markdown. It does not add alignment colons though:

.rst behaves like the reStructuredText simple table format:

Header Style

// header_style: ...
.bold (default) .plain

Alignment

// align: ...
| Max    | 13  | male   |  // .left (default)
|  Max   | 13  |  male  |  // .center
|    Max |  13 |   male |  // .right

Orientation

t := tt.Table{
	data: [
		['Name', 'Age'],
		['Max', '13'],
		['Moritz', '12'],
	]
	// orientation: ...
}
println(t)
.row (default) .column

Padding

Control the count of spaces between the cell border and the item.

// padding: ...
|   Lisa   |   42   |   female   |  // 3

| Lisa | 42 | female |  // 1 (default)

|Lisa|42|female|  // 0

Tabsize

t := tt.Table{
	data: [
		['\tName', 'Sex'],
		['1.\tMax', 'male\t'],
		['2. \tMoritz', '\tmale'],
	]
	// tabsize: ...
}
println(t)
4 (default) 2 8

Creating Custom Styles

To create a custom style set the tables style property to style: .custom and specify custom_style: tt.StyleConfig{...}.

StyleConfig Struct

topline      tt.Sepline{...}
headerline   tt.Sepline{...}
middleline   tt.Sepline{...}
bottomline   tt.Sepline{...}
colsep       string
fill_padding bool = true

Sepline Struct

left  string
right string
cross string
sep   string

Acknowledgements

License

Licensed under the MIT License

termtable's People

Contributors

rodabt avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar

termtable's Issues

Cell padding

Allow changing whitespace between cell border (left/right) and item

Create tests

This requires to split the code into smaller tasks.

There are bugs when using Chinese

+---------+-----------------+
| 键     | 值             |
+---------+-----------------+
| V版本 | V 0.2.2 0dafdb4 |
+---------+-----------------+

Update readme

  • install instructions

  • description (should also be updated in v.mod)

  • license

  • usage examples

  • ci badge (#2)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.