tabletool 0.5.0

A table generator library inspired by Python's tabulate compatible with east-asian character


To use this package, run the following command in your project's root directory:

Manual usage
Put the following dependency into your project's dependences section:

tabletool

test DUB

A table generator library inspired by Python's tabulate compatible with east-asian character.

import std.stdio;
import tabletool;

// Basic
const data = [
    ["D-man", "Programming Language"],
    ["D言語くん", "プログラミング言語"],
];
const header = ["マスコットキャラクタ", "about"];
writeln(tabulate(data, header), "\n");

// Also works with struct
struct Data
{
    @DisplayName("マスコットキャラクタ")
    string name;
    string about;
}

const structData = [
    Data("D-man", "Programming Language"),
    Data("D言語くん", "プログラミング言語"),
];

writeln(tabulate(structData, Config(Style.grid, Align.left, true)), "\n");

// Also works for colored data
const coloredData = [
    Data("\033[31mD-man\033[0m", "Programming Language"),
    Data("D言語くん", "\033[33m\033[3mプログラミング言語\033[0m"),
];

writeln(tabulate(coloredData, Config(Style.grid, Align.center, true)), "\n");

// Also works for multiline data
const multilineData = [
    [
        "This is a long text\n to show how the multiline text is displayed",
        "empty"
    ],
    [
        "空",
        "これは改行を含む文書が\nどのように表示されるかを確認するための文字列"
    ],
];

writeln(tabulate(multilineData, ["text1", "文書2"], Config(Style.grid)), "\n");

// <br> is used instead for marudown
writeln(tabulate(multilineData, ["text1", "文書2"], Config(Style.markdown)), "\n");

img

See example for executable example.

Features

  • Compatible with east-asian characters (Thank to eastasianwidth)
  • Generate a table from 2-D array of any element which can be converted to string
  • Generate a table from 1-D array of a struct (Can override display name by UDA @DisplayName("<name>"))
  • Generate a table from 1-D array of an associated array whose key and value can be converted to string
  • Configure table appearance (style, alignment)
  • Turn on/off header
  • Handle bash color sequence
  • Multiline text
Authors:
  • nonanonno
Dependencies:
east_asian_width
Versions:
0.5.0 2023-May-20
0.4.0 2023-May-16
0.3.0 2022-Dec-11
0.2.0 2022-Sep-24
0.1.1 2022-Sep-24
Show all 7 versions
Download Stats:
  • 0 downloads today

  • 8 downloads this week

  • 155 downloads this month

  • 2014 downloads total

Score:
2.4
Short URL:
tabletool.dub.pm