Allows a programmer to print table-like outputs over std::ostream.

tableprinter

Allows a programmer to print table-like outputs over std::ostream.

It is a header only library.

No other dependency than STL.

Provides required files for cmake to be used with find_package( tableprinter )

C++17 compliant compiler is needed to make it worked.

Tested only on Linux.

Example

#include <iostream>
#include <sstream>
#include <tableprinter/tableprinter.hpp>

int main()
{
    using namespace tableprinter;

    std::stringstream ss;

    printer p
    {
        {
            { name { "id" }      , width { 4 }  } ,
            { name { "name" }    , width { 10 } } ,
            { name { "surname" } , width { 10 } } ,
            { name { "rank" }    , width { 6 }  } ,
            { name { "score" }   , width { 7 } , fixed { } , precision { 2 } }
        } ,
        { std::cout , ss }
    };

    p.sanity_check()
     .echo( "The scores are listed below with their ranks :" )
     .print_headers()
     .print( 1 , "Lucy"   , "Ballmer"  , 2 , 94.13 )
     .print( 2 , "Roger"  , "Bacon"    , 5 , 77.13 )
     .print( 3 , "Anna"   , "Smith"    , 3 , 87.13 )
     .print( 4 , "Robert" , "Schwartz" , 1 , 98.34 )
     .print( 5 , "Robert" , "Brown"    , 4 , 84.34 );

    /*
       # Run the command if you want to see maximum score
       ./print-scores | tail -n 5 | awk '{ printf "%d %d %s %s %f\n" , $4 , $1 , $2 , $3 , $5 }' | sort | head -n 1 | awk '{ print $5 }'
       # or lowest score
       ./print-scores | tail -n 5 | awk '{ printf "%d %d %s %s %f\n" , $4 , $1 , $2 , $3 , $5 }' | sort | tac | head -n 1 | awk '{ print $5 }'
    */
}
The scores are listed below with their ranks :
  id      name   surname  rank  score
   1      Lucy   Ballmer     2  94.13
   2     Roger     Bacon     5  77.13
   3      Anna     Smith     3  87.13
   4    Robert  Schwartz     1  98.34
   5    Robert     Brown     4  84.34

How to use ?

Way 1. Install to the system

  • Install tableprinter as system-wide.
cd $(mktemp -d)
git clone https://github.com/OzanCansel/tableprinter.git
cd tableprinter
mkdir build && cd build
cmake ..
sudo cmake --build . --target install -- -j$(nproc)

Way 1.1.

  • Include tableprinter to your cmake project with find_package( tableprinter )
cmake_minimum_required( VERSION 3.10 )
project( my_project )

# Allows you to use tableprinter
find_package( tableprinter REQUIRED )

add_executable( my_binary main.cpp )

target_link_libraries( my_binary PRIVATE tableprinter::tableprinter )

Way 1.2.

  • It is not obliged to be included by a cmake project. tableprinter is header only so it will be visible after it is installed to the system. So just include it and make sure that you enabled C++17 standard.

Way 2. Add as a subdirectory

  • Add as an subdirectory to your existing cmake project.
cd already_existing_project
git clone https://github.com/OzanCansel/tableprinter.git
cmake_minimum_required( VERSION 3.10 )
project( already_existing_project )

# Allows you to use tableprinter
add_subdirectory( tableprinter EXCLUDE_FROM_ALL )

add_executable( my_binary main.cpp )

target_link_libraries( my_binary PRIVATE tableprinter::tableprinter )

Way 3.

Just download tableprinter.hpp and include it.

Contributing

Pull requests are welcome. For major changes, please open an issue first to discuss what you would like to change.

Please make sure to update tests as appropriate.

License

MIT

Similar Resources

SCST is a SCSI target software stack that allows to export any block device or file via iSCSI, FC or RDMA (SRP).

Overview This is the source code repository of the SCST project. SCST is a collection of Linux kernel drivers that implement SCSI target functionality

Jun 8, 2022

A thread-safe, easy-to-use, utility for sending and receiving notifications. It allows you to decouple different modules of your application.

NotificationManager NotificationManager is a thread-safe, easy-to-use utility for sending and receiving notifications. It allows you to decouple diffe

Dec 27, 2021

A flutter plugin that runs a wayland compositor to stream textures onto flutter, allows creation of wayland based shells using flutter

flcompositor A new flutter plugin project. Getting Started This project is a starting point for a Flutter plug-in package, a specialized package that

Jan 10, 2022

A texture compression algorithm for sprite sheets that allows decompression on the GPU during rendering.

A texture compression algorithm for sprite sheets that allows decompression on the GPU during rendering.

CRABBY A texture compression format for spritesheets Crabby TL;DR Crabby is a compressed texture format for spritesheets and flipbook animations. What

Apr 11, 2022

optional lite - A C++17-like optional, a nullable object for C++98, C++11 and later in a single-file header-only library

optional lite: A single-file header-only version of a C++17-like optional, a nullable object for C++98, C++11 and later Contents Example usage In a nu

Jun 7, 2022

span lite - A C++20-like span for C++98, C++11 and later in a single-file header-only library

span lite: A single-file header-only version of a C++20-like span for C++98, C++11 and later Contents Example usage In a nutshell License Dependencies

Jun 22, 2022

string_view lite - A C++17-like string_view for C++98, C++11 and later in a single-file header-only library

string_view lite: A single-file header-only version of a C++17-like string_view for C++98, C++11 and later Contents Example usage In a nutshell Licens

Jun 4, 2022

A header-only, unobtrusive, almighty alternative to the C++ switch statement that looks just like the original.

uberswitch A header-only, unobtrusive, almighty alternative to the C++ switch statement that looks just like the original. Sample usage (incomplete -

Jun 8, 2022

variant lite - A C++17-like variant, a type-safe union for C++98, C++11 and later in a single-file header-only library

variant lite: A single-file header-only version of a C++17-like variant, a type-safe union for C++98, C++11 and later Contents Example usage In a nuts

Jun 9, 2022
Comments
  • Kodu Anlamak Hk.

    Kodu Anlamak Hk.

    Merhaba. tableprinter.hpp içerisinde yazmış olduğunuz aşağıdaki kod parçacığını anlamakta zorluk çektim. Acaba yazılanları anlamak konusunda beni yönlendirir misiniz? Örneğin, hangi konulara hakim olmalıyım vs.

    template<typename... Ts> struct overloaded : Ts... { using Ts::operator ()...; };

    C++ öğrenmeye yeni başladım. Variadic Template Arguments konusuna pek hakim olmadığım için tam olarak anlayamadım ne yapılmak istenildiğini. İnternetten baktığım kadarıyla Variadic Template Data Structures konusu ile alakalı.

    Yardımcı olursanız çok sevinirim.

A collection of std-like single-header C++ libraries

itlib: iboB's Template Libraries A collection of small single-header C++ libraries similar to or extending the C++ standard library. See below for a l

Jun 20, 2022
A standard conforming C++20 implementation of std::optional.

A standard conforming C++20 implementation of std::optional.

Feb 11, 2022
C++11/14/17 std::expected with functional-style extensions

expected Single header implementation of std::expected with functional-style extensions. Clang + GCC: MSVC: Available on Vcpkg and Conan. std::expecte

Jun 15, 2022
C++11/14/17 std::optional with functional-style extensions and reference support

optional Single header implementation of std::optional with functional-style extensions and support for references. Clang + GCC: MSVC: std::optional i

Jun 21, 2022
Range library for C++14/17/20, basis for C++20's std::ranges

range-v3 Range library for C++14/17/20. This code was the basis of a formal proposal to add range support to the C++ standard library. That proposal e

Jun 14, 2022
Monadic interface for std::optional

optional Simple monadic interface for std::optional Installation Just copy and include optional.h header in your project Usage All operations are in b

Apr 15, 2022
Improved and configurable drop-in replacement to std::function that supports move only types, multiple overloads and more

fu2::function an improved drop-in replacement to std::function Provides improved implementations of std::function: copyable fu2::function move-only fu

Jun 11, 2022
This program allows superheroes to fight against one another. Below is a sample output:

SuperHeroFight This program allows superheroes to fight against one another. This was a fun project that familiarized myself with pointers, dynamic me

Oct 29, 2021
This plugin allows Flutter desktop apps to capture screenshots.

screen_capturer This plugin allows Flutter desktop apps to capture screenshots. screen_capturer Platform Support Quick Start Installation Usage Licens

Jun 9, 2022
Archive Extension Loader is a Cyberpunk 2077 mod that allows you to expand game resources that are currently not suitable for modifications without conflicts.

ArchiveXL Archive Extension Loader allows you to expand game resources that are currently not suitable for modifications without conflicts. Installati

Apr 1, 2022