grepros 1.2.2
grep for ROS bag files and live topics
Loading...
Searching...
No Matches
ConsolePrinter Class Reference

Prints to console, supports color output. More...

Public Member Functions

 configure (cls, color=True, apimode=False)
 Initializes printer, for terminal output or library mode.
 
 debug (cls, text="", *args, **kwargs)
 Prints debug text to stderr, or logs to logger if APIMODE.
 
 error (cls, text="", *args, **kwargs)
 Prints error to stderr, formatted with args and kwargs, in error colors if supported.
 
 flush (cls)
 Ends current open line, if any.
 
 init_terminal (cls)
 Initializes terminal for color output, or disables color output if unsupported.
 
 log (cls, level, text="", *args, **kwargs)
 Prints text to stderr, or logs to logger if APIMODE.
 
 print (cls, text="", *args, **kwargs)
 Prints text, formatted with args and kwargs.
 
 warn (cls, text="", *args, **kwargs)
 Prints warning to stderr, or logs to logger if APIMODE.
 

Public Attributes

 APIMODE
 
 WIDTH
 

Static Public Attributes

bool APIMODE = False
 Whether logging debugs and warnings and raising errors, instead of printing.
 
 COLOR = None
 Whether using colors in output.
 
 DEBUG_END
 
 DEBUG_START
 
 ERROR_END
 
 ERROR_START
 
dict PRINTS = {}
 {sys.stdout: number of texts printed, sys.stderr: ..}
 
str STYLE_ERROR = "\x1b[31m\x1b[2m"
 
str STYLE_HIGHLIGHT = "\x1b[31m"
 
str STYLE_LOWLIGHT = "\x1b[38;2;105;105;105m"
 
str STYLE_RESET = "\x1b(B\x1b[m"
 
str STYLE_SPECIAL = "\x1b[35m"
 
str STYLE_SPECIAL2 = "\x1b[36m"
 
str STYLE_WARN = "\x1b[33m"
 
 WARN_END
 
 WARN_START
 
int WIDTH = 80
 Console width in characters, updated from shutil and curses.
 

Detailed Description

Prints to console, supports color output.

If configured with apimode=True, logs debugs and warnings to logger and raises errors.

Definition at line 80 of file common.py.

Member Function Documentation

◆ configure()

configure (   cls,
  color = True,
  apimode = False 
)

Initializes printer, for terminal output or library mode.

For terminal output, initializes terminal colors, or disables colors if unsupported.

Parameters
colorTrue / False / None for auto-detect from TTY support; will be disabled if terminal does not support colors
apimodewhether to log debugs and warnings to logger and raise errors, instead of printing

Definition at line 131 of file common.py.

◆ debug()

debug (   cls,
  text = "",
args,
**  kwargs 
)

Prints debug text to stderr, or logs to logger if APIMODE.

Text is formatted with args and kwargs, in warning colors if supported.

Definition at line 230 of file common.py.

◆ error()

error (   cls,
  text = "",
args,
**  kwargs 
)

Prints error to stderr, formatted with args and kwargs, in error colors if supported.

Raises exception instead if APIMODE.

Definition at line 202 of file common.py.

◆ flush()

flush (   cls)

Ends current open line, if any.

Definition at line 259 of file common.py.

◆ init_terminal()

init_terminal (   cls)

Initializes terminal for color output, or disables color output if unsupported.

Definition at line 142 of file common.py.

◆ log()

log (   cls,
  level,
  text = "",
args,
**  kwargs 
)

Prints text to stderr, or logs to logger if APIMODE.

Text is formatted with args and kwargs, in level colors if supported.

Parameters
levellogging level like logging.ERROR or "ERROR"

Definition at line 247 of file common.py.

◆ print()

print (   cls,
  text = "",
args,
**  kwargs 
)

Prints text, formatted with args and kwargs.

Parameters
__filefile object to print to if not sys.stdout
__endline end to use if not linefeed "\n"
__oncewhether text should be printed only once and discarded on any further calls (applies to unformatted text)

Definition at line 179 of file common.py.

◆ warn()

warn (   cls,
  text = "",
args,
**  kwargs 
)

Prints warning to stderr, or logs to logger if APIMODE.

Text is formatted with args and kwargs, in warning colors if supported.

Definition at line 215 of file common.py.

Member Data Documentation

◆ APIMODE [1/2]

bool APIMODE = False
static

Whether logging debugs and warnings and raising errors, instead of printing.

Definition at line 104 of file common.py.

◆ APIMODE [2/2]

APIMODE

Definition at line 132 of file common.py.

◆ COLOR

COLOR = None
static

Whether using colors in output.

Definition at line 95 of file common.py.

◆ DEBUG_END

DEBUG_END
static

Definition at line 90 of file common.py.

◆ DEBUG_START

DEBUG_START
static

Definition at line 90 of file common.py.

◆ ERROR_END

ERROR_END
static

Definition at line 92 of file common.py.

◆ ERROR_START

ERROR_START
static

Definition at line 92 of file common.py.

◆ PRINTS

dict PRINTS = {}
static

{sys.stdout: number of texts printed, sys.stderr: ..}

Definition at line 101 of file common.py.

◆ STYLE_ERROR

str STYLE_ERROR = "\x1b[31m\x1b[2m"
static

Definition at line 88 of file common.py.

◆ STYLE_HIGHLIGHT

str STYLE_HIGHLIGHT = "\x1b[31m"
static

Definition at line 83 of file common.py.

◆ STYLE_LOWLIGHT

str STYLE_LOWLIGHT = "\x1b[38;2;105;105;105m"
static

Definition at line 84 of file common.py.

◆ STYLE_RESET

str STYLE_RESET = "\x1b(B\x1b[m"
static

Definition at line 82 of file common.py.

◆ STYLE_SPECIAL

str STYLE_SPECIAL = "\x1b[35m"
static

Definition at line 85 of file common.py.

◆ STYLE_SPECIAL2

str STYLE_SPECIAL2 = "\x1b[36m"
static

Definition at line 86 of file common.py.

◆ STYLE_WARN

str STYLE_WARN = "\x1b[33m"
static

Definition at line 87 of file common.py.

◆ WARN_END

WARN_END
static

Definition at line 91 of file common.py.

◆ WARN_START

WARN_START
static

Definition at line 91 of file common.py.

◆ WIDTH [1/2]

int WIDTH = 80
static

Console width in characters, updated from shutil and curses.

Definition at line 98 of file common.py.

◆ WIDTH [2/2]

WIDTH

Definition at line 146 of file common.py.


The documentation for this class was generated from the following file: