Library with useful output stream tools like: color and style manipulators, progress bars and terminal graphics.

Library with useful output stream tools like: color and style manipulators, progress bars and terminal graphics

v3.0 license C++17
code size repo size total lines


Table of contents

Introduction

Here I want to present you osmanip: a C++ library containing useful tools to customize the output stream of your programs. Within this tools you can manipulate an output stream with colors, styles (ex: bold, italics, etc...) and manage other tools like progress bars and terminal graphics. You can also manipulate ANSI escape sequences / codes, with proper functions provided by the library. Using this features may be very useful to better read error messages or special information you want to be sure other users see when they run your code, or to adorn your general output stream log.

If you want to use this software in one of your project, please cite it. You can find the citation template here.

NOTE: all the manipulators of this library are compatible with iomanip.

NOTE 2: this library doesn't make use of any GUI.

Example output of the main.cpp program demo:

Colors and styles manipulators

Progress bars

2D terminal-graphics

The software is and will stay free, but if you want to support me with a donation it would be really appreciated!

Buy Me A Coffee

Supported and tested operating systems:

  • Ubuntu (and the other Linux OSs).
  • Windows Subsystem for Linux (WSL).

Documentation

In the doc folder useful documentation files are stored, in order to help the user learning how to properly use the library:

  • Code structure: contains general information about the code structure of the library, therefore details on classes, functions and variables used in it.
  • Download and install: a guide to download, install and run the library into your system.
  • Contributing: if you want to contribute to the development of this library or you want to raise an issue, please carefully read this document before.
  • Todo: contains a list of future implementations of the library.
  • How-to-use guides: contains a set of guides about how to use the library tools.

Repository structure

osmanip/
├── img/
├── doc/
│   ├── Code structure.md
│   ├── Contributing.md
│   ├── Download and install.md
│   ├── Todo.md
│   ├── How-to-use guides.md
├── include/
│   ├── graphics/
│   │   ├── canvas.hpp
│   │   ├── plot_2D.hpp
│   ├── manipulators/
│   │   ├── csmanip.hpp
│   ├── progressbar/
│   │   ├── progress_bar.hpp
│   │   ├── multi_progress_bar.hpp
├── src/
│   ├── graphics/
│   │   ├── canvas.cpp
│   │   ├── plot_2D.cpp
│   ├── manipulators/
│   │   ├── csmanip.cpp
│   ├── progressbar/
│   │   ├── progress_bar.cpp
│   │   ├── multi_progress_bar.cpp
│   ├── main.cpp
├── scripts/
│   ├── debug.sh
│   ├── install.sh
│   ├── uninstall.sh
│   ├── update.sh
│   ├── size_of_dir.sh
├── test/
│   ├── graphics/
│   │   ├── tests_canvas.cpp
│   │   ├── tests_plot_2D.cpp
│   ├── manipulators/
│   │   ├── tests_csmanip.cpp
│   ├── progressbar/
│   │   ├── tests_progress_bar.cpp
│   │   ├── tests_multi_progress_bar.cpp
│── README.md
│── License
│── CITATION.cff
│── Makefile
│── .gitignore
│── .clang-format
│── .valgrindrc
│── .gitignore
│── .all-contributorsrc

News from the last version

Most recent relevant news from the last version:

  • A new feature to plot 2D graphics and functions in the terminal has been added. See here.
  • Progress spinner has been added to the ProgressBar class.
  • New features have been added to the progress bar: time-reamining info.
  • Added a new map for the feat function to deal with clear screen / line commands.
  • Added a new print function inspired by the Python one.

List of features

Here you can find the list of features implemented in the current version of the library:

Why choosing this library for color / styles / escape sequences manipulation:

  • All the functions used to manipulate these sequences are very easy to use and don't require complex code signatures.
  • All the most common ANSI sequences can be manipulated.

Why choosing this library for progress bars? Some properties:

  • Extremely easy to use.
  • Compatible with positive or negative variable of any standard type (integer, float, double and others).
  • Maximum and minimum values can be set with any value you prefer and the progress bars will be self-built with respect to them.
  • Each progress bar feature can be fully customized (messages, style, color, brackets type, time remaining info etc...) regarding to your requirements. You can also choose to use only a progress indicator or a loading bar instead of a complete progress bar.
  • It is thread-safe, hence you can use also multiple progress bars simultaneously.

Why choosing this library for terminal graphics:

  • There are very few C++ libraries doing this job, and this is one of them.
  • High level of customizability.
  • A faster and most comfortable alternative to plot simple functions without the needing of GUI.

Credits

Project leaders


Gianluca Bianco

Other contributors


MiguelMJ

Ted Lyngmo

myermo

nick-botticelli

Other contributors with no GitHub account

Owner
Gianluca Bianco
PhD student in particle physics at the University of Bologna and member of the CERN ATLAS experiment. Passionate about coding (C++ in particular)
Gianluca Bianco
Comments
  • Progressbar doc test failing due to static member varible

    Progressbar doc test failing due to static member varible

    Hi @JustWhit3, I'm implementing OutputRedirector tests and they've caused ProgressBar tests to throw an exception when it attempts to set an already existing style:

    [doctest] run with "--help" for options
    ===============================================================================
    test/unit_tests/progressbar/tests_progress_bar.cpp:39:
    TEST CASE:  Testing the ProgressBar class methods.<float>
      Testing addStyle method.
    
    test/unit_tests/progressbar/tests_progress_bar.cpp:39: ERROR: test case THREW exception: exception thrown in subcase - will translate later when the whole test case has been exited (cannot translate while there is an active exception)
    
    ===============================================================================
    test/unit_tests/progressbar/tests_progress_bar.cpp:39:
    TEST CASE:  Testing the ProgressBar class methods.<float>
    
    test/unit_tests/progressbar/tests_progress_bar.cpp:39: ERROR: test case THREW exception: Inserted ProgressBar style "|100" is already available!
    
    ===============================================================================
    [doctest] test cases:     15 |     13 passed |      2 failed |      0 skipped
    [doctest] assertions:   1130 |   1129 passed |      1 failed |
    [doctest] Status: FAILURE!
    

    I'm guessing that since the ProgressBar uses a static style map, OutputRedirector it adds the style to the before the ProgressBar performs its own test.

    Is there a way to the style map before/after use?

  • Install script raising an error.

    Install script raising an error.

    Executing ./scripts/install.sh raises the following error:

    Doctest is not installed, cannot compile the test codes!

    ./scripts/install.sh: line 22: eco: order not found. make: *** No rule to make target `bin/main'. Stop. Compilation failed!

    I'm opening the issue because in the documentation it is stated that Doctest is optional.

  • File redirection implemented

    File redirection implemented

    Hey there,

    I found this library recently through a Reddit post, and thought I would try to contribute.

    I have implemented a class to handle osmanip animation output redirection to a file. It's very simple to use, as you can see from the example file (and updated README.md). There are a few quirks, like having to flush the buffer on every loop iteration and it does not work well in a multi-threaded environment. But, other than that it's basically plug n play.

    I've included a basic test, with not check yet. However, the redirection example shows output redirection to both the console and the file before, during, and after the progress bar examples, except for the multi bars, and is a pretty good test in and of itself.

    Let me know what you think.

    Joel

  • Fix multibars printing in the same line

    Fix multibars printing in the same line

    It works checking the last bar updated and moving vertically the cursor to update the correct bar each time. Feel free to change anything to keep your own code style, I just made the changes for it to work 😅 There are not much, though. I hope it works correctly!

  • Redirection

    Redirection

    Major update to OutputRedirector, which includes the complete and correct use of OutputRedirector with all osmanip functions, including MultiProgressBar, regardless of the number of threads. Addition of osm::iostream, osm::Streambuf, osm::Ostreambuf, and a number of functions in strings.hpp/cpp that make handling ANSI CSI's possible.

    Modifications to README.md to come.

  • Make failing because of doctest::detail::MessageBuilder

    Make failing because of doctest::detail::MessageBuilder

    When building with

    make
    

    The following error occurs:

    In file included from test/tests_helper_tools.cpp:3:
    test/tests_helper_tools.cpp: In lambda function:
    test/tests_helper_tools.cpp:15:32: error: no match for ‘operator+’ (operand types are ‘doctest::detail::MessageBuilder’ and ‘std::string’ {aka ‘std::__cxx11::basic_string<char>’})
       15 | #define test_string_hp "first" +                            \
          |                                ^
       16 |                        static_cast <std::string>(" \"") +   \
          |                        ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
          |                        |
          |                        std::string {aka std::__cxx11::basic_string<char>}
    test/tests_helper_tools.cpp:65:80: note: in expansion of macro ‘test_string_hp’
       65 |   CHECK_THROWS_MESSAGE( throw( runtime_error_func( "first", var, "second" ) ), test_string_hp );
          |                                                                                ^~~~~~~~~~~~~~
    
    

    As I'm not familiar with doctest, I would just suggest to separate the tests into their own build, with something like make tests. Cheers!

  • Use of `NULL` and `nullptr` as numeric value

    Use of `NULL` and `nullptr` as numeric value

    NULL is implementation defined. This means every compiler is free to choose how the macro expands. IMHO, you should try to avoid implementation defined behavior as they don't have the best portability, and may change between compilers or even different versions of the same compiler.

    Most compilers since C++11 expand NULL to nullptr which is a nullptr_t type and cannot be assigned to non-pointer types; i.e., use of int max = NULL; is an error.

    error: cannot initialize a variable of type 'int' with an rvalue of type 'nullptr_t'
        int max = NULL;
            ^     ~~~~
    

    Check out cppreference article on NULL for information about the changes to NULL.

    That said, it looks like you should be using 0 in most of this code b/c you're assigning NULL to integer/floating point types, which is an compile-time error on compilers expanding NULL to nullptr.

    Describe the bug Assigning NULL to non-pointer types. Assigning nullptr to non-pointer types.

    Fix Without refactoring the code, worked around the problem by changing uses of NULL to 0 and nullptr to 0.

    Environment

    • OS: OpenBSD
    • Version: 7.1
    • Clang: OpenBSD clang version 13.0.0

    I opened the same issue on arsenalgear-cpp.

  • add first canvas functions

    add first canvas functions

    This PR is for a new feature: canvas objects to render 2D stuff in the console.

    This first commit contains just the proof of concept: the Canvas class with three functions.

    • clear(): reset the canvas to an empty one.
    • put(x, y, c, f): in column x, row y of the canvas, put the character c with the feats f.
    • refresh: display the canvas in the console.
    A small program to test it:

    This will display a little animation of an A character moving between other static characters.

    #include "osmanip.hpp"
    #include <chrono>
    #include <thread>
    
    using namespace osm;
    using namespace std;
    
    int main(){
        Canvas canvas(10,10);
        for(uint i=0; i < 10; i++){
            canvas.clear();
            canvas.put(0,2,'x');
            canvas.put(i,3,'A', feat(col, "red"));
            canvas.put(5,0,'B', feat(col, "blue"));
            canvas.put(7,8,'Z', feat(col, "bg cyan") + feat(col, "black") + feat(sty, "bold"));
            canvas.refresh();
            this_thread::sleep_for(chrono::milliseconds(100));
        }
        return 0;
    }
    

    Compile with

     g++ -std=c++17 -Iinclude mymain.cpp src/{canvas,csmanip,helper_tools,progress_bar}.cpp  -pthread
    

    This PR is just a draft, I plan to make it a definitive PR when the following features are supported and documented:

    • Options to put a frame the canvas.
    • Possibility to overwrite the 'empty' character (currently is a blank space with default background color).
    • A subclass of the Canvas that can plot functions (passed as lambdas or std::function) at a given scale.

    Any feedback is appreciated.

  • Handle output filenames correctly depending on OS

    Handle output filenames correctly depending on OS

    Only add .exe to the end of output filenames in bin on Windows. This also fixes an issue with scripts/install.sh not functioning as it looks for bin/main and not bin/main.exe.

GraphicsFuzz provides tools for automatically finding and simplifying bugs in graphics drivers, specifically graphics shader compilers.

GraphicsFuzz GraphicsFuzz is a set of tools for testing shader compilers GraphicsFuzz provides tools for automatically finding and simplifying bugs in

Nov 29, 2022
Two alphanumeric LCDs and 2 LED bars to show and manage some in-flight parameters
Two alphanumeric LCDs and 2 LED bars to show and manage some in-flight parameters

FS2020-LCD-Panel with Arduino Two alphanumeric LCDs and 2 LED bars to show and manage some in-flight parameters for FS2020. In this project you can pl

Sep 24, 2022
multi-sdr-gps-sim generates a IQ data stream on-the-fly to simulate a GPS L1 baseband signal using a SDR platform like HackRF or ADLAM-Pluto.

multi-sdr-gps-sim generates a GPS L1 baseband signal IQ data stream, which is then transmitted by a software-defined radio (SDR) platform. Supported at the moment are HackRF, ADLAM-Pluto and binary IQ file output. The software interacts with the user through a curses based text user interface (TUI) in terminal.

Oct 29, 2022
F Graphics Library (FGL) is a small graphics C++ portable library for LCD displays on embedded systems

F Graphics Library (FGL) Full documentation: fgl.docsforge.com (By Filipe Chagas) F Graphics Library is a C++ library that I created for use in embedd

Oct 31, 2022
A python package to provide you with many useful tools for osu! servers, written in C++ for the best speeds possible.

pysu_bindings A python package to provide you with many useful tools for osu! servers, written in C++ for the best speeds possible. What? As most peop

Nov 29, 2021
taos-tools are some useful tool collections for TDengine.

taos-tools taos-tools are some useful tool collections for TDengine. How to build from source? install dependencies For Ubuntu/Debian system sudo apt

Nov 11, 2022
Open-source node system framework, to change your algorithmic code into useful tools to create much more complicated simulations!
Open-source node system framework, to change your algorithmic code into useful tools to create much more complicated simulations!

Open-source node system framework, to change your algorithmic code into useful tools to create much more complicated simulations!

Nov 30, 2022
A program that read a program and output some shit-like code. /se

A program that read a program and output some shit-like code. /se

Jun 16, 2022
CSC404: Computer Graphics [CG] & CSL402: Computer Graphics Lab [CG Lab]

COMPUTER-GRAPHICS-AND-COMPUTER-GRAPHICS-LAB CSC404: CG & CSL402: CG LAB [SEMESTER IV] Syllabus CG - Reference Books THE WALL MEGA SATISH - AUTHOR CG C

Apr 28, 2022
Suckless-tools - My fork of suckless tools.

suckless-tools Here is my fork of suckless tools. I didn't include tabbed, i was using but not actively. I am using xfce4-terminal instead of st. Beca

Jan 7, 2022
The Vulkan Profiles Tools are a collection of tools delivered with the Vulkan SDK for Vulkan application developers to leverage Vulkan Profiles while developing a Vulkan application
The Vulkan Profiles Tools are a collection of tools delivered with the Vulkan SDK for Vulkan application developers to leverage Vulkan Profiles while developing a Vulkan application

Copyright © 2021-2022 LunarG, Inc. Vulkan Profiles Tools (BETA) The Vulkan Profiles Tools are a collection of tools delivered with the Vulkan SDK for

Dec 6, 2022
Text - A spicy text library for C++ that has the explicit goal of enabling the entire ecosystem to share in proper forward progress towards a bright Unicode future.

ztd.text Because if text works well in two of the most popular systems programming languages, the entire world over can start to benefit properly. Thi

Nov 26, 2022
The Kernel-Mode Winsock library, supporting TCP, UDP and Unix sockets (DGRAM and STREAM).

libwsk 简体中文 About libwsk is a wrapper for the WSK (Winsock-Kernel) interface. With libwsk, kernel-mode software modules can perform network I/O operat

Nov 29, 2022
Emergency alert and tracer for realtime high-performance computing app (work in progress, currently supported env is only Linux x86-64).

HPC Emerg Emergency alert and tracer for realtime high-performance computing app (work in progress, currently supported env is only Linux x86-64). Exa

Jan 19, 2022
a work in progress try to make an IDE with the CSFML

EatSleepCode A work in progress for educational purpose. To help better understanding the CSFML lib. Installation clone this repo and do make Use case

Nov 20, 2022
X11 file manager (work in progress)

xfiles This is a still incomplete file manager for X11. It can only navigate through directories, select files (and do nothing with them), call a sc

Apr 9, 2022
An in-progress matching decompilation of Final Fantasy VII For the PSX.

FFVII An in-progress decompilation of the original US release of Final Fantasy VII on the PSX. Building (Linux) Install build dependencies The build p

Oct 4, 2022
An in-progress decompilation of the 1.1 US release of Silent Hill on the Playstation 1.

Silent Hill Decompilation Project An in-progress decompilation of the 1.1 US release of Silent Hill on the Playstation 1. Building (Linux) Install bui

Oct 30, 2022