Public Member Functions | Public Attributes | Static Public Attributes | Private Member Functions | Private Attributes | Static Private Attributes | List of all members
grepros.common.ConsolePrinter Class Reference
Inheritance diagram for grepros.common.ConsolePrinter:
Inheritance graph
[legend]

Public Member Functions

def configure (cls, color=True, apimode=False)
 
def debug (cls, text="", *args, **kwargs)
 
def error (cls, text="", *args, **kwargs)
 
def flush (cls)
 
def init_terminal (cls)
 
def log (cls, level, text="", *args, **kwargs)
 
def print (cls, text="", *args, **kwargs)
 
def warn (cls, text="", *args, **kwargs)
 

Public Attributes

 APIMODE
 
 WIDTH
 

Static Public Attributes

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

Private Member Functions

def _format (cls, text="", *args, **kwargs)
 

Private Attributes

 _LINEOPEN
 

Static Private Attributes

 _COLORFLAG = None
 
bool _LINEOPEN = False
 
 _UNIQUES = set()
 

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 75 of file common.py.

Member Function Documentation

◆ _format()

def grepros.common.ConsolePrinter._format (   cls,
  text = "",
args,
**  kwargs 
)
private
Returns text formatted with printf-style or format() arguments.

@param  __once  registers text, returns "" if text not unique

Definition at line 259 of file common.py.

◆ configure()

def grepros.common.ConsolePrinter.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.

@param   color    True / False / None for auto-detect from TTY support;
          will be disabled if terminal does not support colors
@param   apimode  whether to log debugs and warnings to logger and raise errors,
          instead of printing

Definition at line 113 of file common.py.

◆ debug()

def grepros.common.ConsolePrinter.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 218 of file common.py.

◆ error()

def grepros.common.ConsolePrinter.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 190 of file common.py.

◆ flush()

def grepros.common.ConsolePrinter.flush (   cls)
Ends current open line, if any.

Definition at line 252 of file common.py.

◆ init_terminal()

def grepros.common.ConsolePrinter.init_terminal (   cls)
Initializes terminal for color output, or disables color output if unsupported.

Definition at line 134 of file common.py.

◆ log()

def grepros.common.ConsolePrinter.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.

@param   level  logging level like `logging.ERROR` or "ERROR"

Definition at line 233 of file common.py.

◆ print()

def grepros.common.ConsolePrinter.print (   cls,
  text = "",
args,
**  kwargs 
)
Prints text, formatted with args and kwargs.

@param   __file   file object to print to if not sys.stdout
@param   __end    line end to use if not linefeed "\n"
@param   __once   whether text should be printed only once
          and discarded on any further calls (applies to unformatted text)

Definition at line 164 of file common.py.

◆ warn()

def grepros.common.ConsolePrinter.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 203 of file common.py.

Member Data Documentation

◆ _COLORFLAG

grepros.common.ConsolePrinter._COLORFLAG = None
staticprivate

Definition at line 106 of file common.py.

◆ _LINEOPEN [1/2]

bool grepros.common.ConsolePrinter._LINEOPEN = False
staticprivate

Definition at line 108 of file common.py.

◆ _LINEOPEN [2/2]

grepros.common.ConsolePrinter._LINEOPEN
private

Definition at line 183 of file common.py.

◆ _UNIQUES

grepros.common.ConsolePrinter._UNIQUES = set()
staticprivate

Definition at line 110 of file common.py.

◆ APIMODE [1/2]

bool grepros.common.ConsolePrinter.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]

grepros.common.ConsolePrinter.APIMODE

Definition at line 124 of file common.py.

◆ COLOR

grepros.common.ConsolePrinter.COLOR = None
static

Whether using colors in output.

Definition at line 95 of file common.py.

◆ DEBUG_END

grepros.common.ConsolePrinter.DEBUG_END
static

Definition at line 90 of file common.py.

◆ DEBUG_START

grepros.common.ConsolePrinter.DEBUG_START
static

Definition at line 90 of file common.py.

◆ ERROR_END

grepros.common.ConsolePrinter.ERROR_END
static

Definition at line 92 of file common.py.

◆ ERROR_START

grepros.common.ConsolePrinter.ERROR_START
static

Definition at line 92 of file common.py.

◆ PRINTS

dictionary grepros.common.ConsolePrinter.PRINTS = {}
static

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

Definition at line 101 of file common.py.

◆ STYLE_ERROR

string grepros.common.ConsolePrinter.STYLE_ERROR = "\x1b[31m\x1b[2m"
static

Definition at line 88 of file common.py.

◆ STYLE_HIGHLIGHT

string grepros.common.ConsolePrinter.STYLE_HIGHLIGHT = "\x1b[31m"
static

Definition at line 83 of file common.py.

◆ STYLE_LOWLIGHT

string grepros.common.ConsolePrinter.STYLE_LOWLIGHT = "\x1b[38;2;105;105;105m"
static

Definition at line 84 of file common.py.

◆ STYLE_RESET

string grepros.common.ConsolePrinter.STYLE_RESET = "\x1b(B\x1b[m"
static

Definition at line 82 of file common.py.

◆ STYLE_SPECIAL

string grepros.common.ConsolePrinter.STYLE_SPECIAL = "\x1b[35m"
static

Definition at line 85 of file common.py.

◆ STYLE_SPECIAL2

string grepros.common.ConsolePrinter.STYLE_SPECIAL2 = "\x1b[36m"
static

Definition at line 86 of file common.py.

◆ STYLE_WARN

string grepros.common.ConsolePrinter.STYLE_WARN = "\x1b[33m"
static

Definition at line 87 of file common.py.

◆ WARN_END

grepros.common.ConsolePrinter.WARN_END
static

Definition at line 91 of file common.py.

◆ WARN_START

grepros.common.ConsolePrinter.WARN_START
static

Definition at line 91 of file common.py.

◆ WIDTH [1/2]

int grepros.common.ConsolePrinter.WIDTH = 80
static

Console width in characters, updated from shutil and curses.

Definition at line 98 of file common.py.

◆ WIDTH [2/2]

grepros.common.ConsolePrinter.WIDTH

Definition at line 138 of file common.py.


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


grepros
Author(s): Erki Suurjaak
autogenerated on Sat Jan 6 2024 03:11:30