CppTools
Loading...
Searching...
No Matches
IOTools.hpp File Reference

Contains useful set of functions to work with std::string and to convert various types in std::string. More...

#include <stdio.h>
#include <sys/ioctl.h>
#include <unistd.h>
#include <vector>
#include "ErrorHandler.hpp"
#include "StrTools.hpp"

Go to the source code of this file.

Functions

template<typename... T>
void CppTools::Print (T... args)
 Variadic print functions.
int CppTools::GetTerminalWidth ()
 Returns terminal width.
void CppTools::PrintInfo (const std::string &message)
 Prints info prompt.
void CppTools::PrintSimpleSeparator (const std::string &leftEdge="|", const std::string &body="-", const std::string &rightEdge="|", int length=-1)
 Prints vertical separator (with width of terminal by default).
void CppTools::PrintSeparator (const std::string &message, const std::string &color="", const std::string &leftEdge="//", const std::string &body="-", const std::string &rightEdge="//", int length=-1)
 Prints vertical separator (with width of terminal by default) with message in the middle.
void CppTools::Print2EntrySeparator (const std::string &entry1, const std::string &entry2, const std::string &leftEdge="|", const std::string &rightEdge="|", int length=-1)
 Prints vertical separator (with width of terminal by default) with one text entry on the left and the other on the left.
void CppTools::PrintMessageBox (const std::string &message, const std::string &ULCorner="╓", const std::string &URCorner="╖", const std::string &horizontalLine="─", const std::string &verticalLine="║", const std::string &BLCorner="╙", const std::string &BRCorner="╜", int length=-1)
 Prints vertical separator (with width of terminal by default) constisting of 3 lines with message in the middle.

Detailed Description

Contains useful set of functions to work with std::string and to convert various types in std::string.

In order to use functions from this file libStrTools.so must be loaded

This file is a part of a project CppTools (https://github.com/Sergeyir/CppTools).

Author
Sergei Antsupov (antsu.nosp@m.pov0.nosp@m.124@g.nosp@m.mail.nosp@m..com)

Function Documentation

◆ Print()

template<typename... T>
void CppTools::Print ( T... args)

Variadic print functions.

Parameters
[in]argsparameter pack, every element of which will be printed

◆ Print2EntrySeparator()

void CppTools::Print2EntrySeparator ( const std::string & entry1,
const std::string & entry2,
const std::string & leftEdge = "|",
const std::string & rightEdge = "|",
int length = -1 )

Prints vertical separator (with width of terminal by default) with one text entry on the left and the other on the left.

Parameters
[in]entry1- text to be printed on the left
[in]entry2- text to be printed on the right
[in]leftEdge- left edge of a separator, only printed once
[in]rightEdge- right edge of a separator, only printed once
[in]length- length of a separator; negative values will result separator to be printed with a width of a terminal

Example: Calling Print2EntrySeparator("left", "right", "|", "|", 20) will print without quotes

| left       right |

◆ PrintInfo()

void CppTools::PrintInfo ( const std::string & message)

Prints info prompt.

Parameters
[in]messagetext to be printed in the info prompt

◆ PrintMessageBox()

void CppTools::PrintMessageBox ( const std::string & message,
const std::string & ULCorner = "╓",
const std::string & URCorner = "╖",
const std::string & horizontalLine = "─",
const std::string & verticalLine = "║",
const std::string & BLCorner = "╙",
const std::string & BRCorner = "╜",
int length = -1 )

Prints vertical separator (with width of terminal by default) constisting of 3 lines with message in the middle.

Parameters
[in]message- text to be printed in the middle
[in]ULCorner- upper left corner of a separator
[in]URCorner- upper right corner of a separator
[in]horizontalLine- horizontal line of a separator
[in]BLCorner- bottom left corner of a separator
[in]BRCorner- bottom right corner of a separator
[in]length- length of a separator; negative values will result separator to be printed with a width of a terminal

Example: Calling PrintBigSeparator("text", "UL", "UR", "-", "|", "BL", "BR", 20) will print (note the spaces on the left and on the right since they contribute to the length)

 UL---------------UR 
 |      text       | 
 BL---------------BR 

◆ PrintSeparator()

void CppTools::PrintSeparator ( const std::string & message,
const std::string & color = "",
const std::string & leftEdge = "//",
const std::string & body = "-",
const std::string & rightEdge = "//",
int length = -1 )

Prints vertical separator (with width of terminal by default) with message in the middle.

Parameters
[in]message- text to be printed in the middle
[in]color- color of the message (see OutputColors.hpp file)
[in]leftEdge- left edge of a separator, only printed once
[in]body- body of a separator, can be printed multiple times to fill in the length.
[in]rightEdge- right edge of a separator, only printed once
[in]length- length of a separator; negative values will result separator to be printed with a width of a terminal

Example: Calling PrintSeparator("text", "", "|", "*", "|", 12) will print (note the spaces on the left and on the right since they contribute to the length)

|***text***|

◆ PrintSimpleSeparator()

void CppTools::PrintSimpleSeparator ( const std::string & leftEdge = "|",
const std::string & body = "-",
const std::string & rightEdge = "|",
int length = -1 )

Prints vertical separator (with width of terminal by default).

Parameters
[in]leftEdge- left edge of a separator, only printed once
[in]body- body of a separator, can be printed multiple times to fill in the length.
[in]rightEdge- right edge of a separator, only printed once
[in]length- length of a separator; negative values will result separator to be printed with a width of a terminal

Example: Calling PrintSimpleSeparator("|", "*", "|", 7) will print

|*****|