A C++ and Python library for formatting values (numbers, strings, etc.) in fixed-width fields. Useful for printing tabular data and similar.
-
A single formatter formats any value with the same width: useful for formatting tables, arrays, forms, etc.
-
The width is measured in Unicode code points.
-
ANSI terminal escape codes are ignored when counting width, so they may be used to format output for the terminal.
See cxx/README.md
for an introduction to the C++ API.
See python/README.md
for an introduction to the Python API.
With conda (binary packages for Linux and OS/X, Python 3.6):
conda install -c alexhsamuel fixfmt
From PyPI (a requires C++14 compiler and GNU make):
pip install fixfmt
Requires a C++14 compiler, GNU Make, and setuptools to build.
Tested with Python 3.6.
Requires Google Test for building and running the C++ tests:
At the top of the repository:
git clone https://github.com/google/googletest
(cd googletest/googletest/make; make)
Requires pytest to run Python tests. Invoke,
py.test test
Counting code points is broken, as is it is not a perfect proxy for display width.
However, for primarily data-oriented applications that this library targets, it does a reasonable job and produces better output than most similar systems. If you know a realible way to count grapheme clusters or invertibly determine display width in a fixed-width Linux and OS/X terminal, please contact the author.