Package entropy :: Module output

Module output

source code


Author: Fabio Erculiani <[email protected]>

Contact: [email protected]

Copyright: Fabio Erculiani

License: GPL-2

Entropy Framework Output module.

This module contains Entropy (user) Output classes and routines.

Classes
  TextInterface
TextInterface is a base class for handling the communication between user and Entropy-based applications.
Functions
 
setcols() source code
 
color(fg, bg='default', attr=['normal']) source code
bool
is_mute()
Return whether writing to stderr/stdout is allowed.
source code
 
set_mute(status)
Set mute status.
source code
bool
is_interactive()
Return whether interactive mode is enabled.
source code
bool
is_stdout_a_tty()
Return whether current stdout is a TTY.
source code
 
xterm_title(mystr, raw=False)
Set new xterm title.
source code
 
xterm_title_reset()
Reset xterm title to default.
source code
 
notitles()
Turn off title setting.
source code
 
nocolor()
Turn off colorization process-wide.
source code
 
getcolor()
Return color status
source code
string
colorize(color_key, text)
Colorize text with given color key using bash/terminal codes.
source code
 
decolorize(text) source code
string
bold(text)
Make text bold using bash/terminal codes.
source code
string
white(text)
Make text white using bash/terminal codes.
source code
string
teal(text)
Make text teal using bash/terminal codes.
source code
string
turquoise(text)
Make text turquoise using bash/terminal codes.
source code
string
darkteal(text)
Make text darkteal using bash/terminal codes.
source code
string
purple(text)
Make text purple using bash/terminal codes.
source code
string
blue(text)
Make text blue using bash/terminal codes.
source code
string
darkblue(text)
Make text darkblue using bash/terminal codes.
source code
string
green(text)
Make text green using bash/terminal codes.
source code
string
darkgreen(text)
Make text darkgreen using bash/terminal codes.
source code
string
yellow(text)
Make text yellow using bash/terminal codes.
source code
string
brown(text)
Make text brown using bash/terminal codes.
source code
string
darkyellow(text)
Make text darkyellow using bash/terminal codes.
source code
string
red(text)
Make text red using bash/terminal codes.
source code
string
darkred(text)
Make text darkred using bash/terminal codes.
source code
 
reset_cursor()
Print to stdout the terminal code to push back cursor at the beginning of the line.
source code
None
print_error(msg, back=False, flush=True, end='\n')
Service function used by Entropy text client (will be moved from here) to write error messages to stdout (not stderr, atm).
source code
None
print_info(msg, back=False, flush=True, end='\n')
Service function used by Entropy text client (will be moved from here) to write info messages to stdout (not stderr, atm).
source code
None
print_warning(msg, back=False, flush=True, end='\n')
Service function used by Entropy text client (will be moved from here) to write warning messages to stdout (not stderr, atm).
source code
 
print_generic(*args, **kwargs)
Service function used by Entropy text client (will be moved from here) to write generic messages to stdout (not stderr, atm).
source code
 
writechar(chars, stderr=False)
Write characters to stdout (will be moved from here).
source code
string
readtext(request, password=False)
Read text from stdin and return it (will be moved from here).
source code
Variables
  stuff = {'ESC': '\x1b', 'cleanline': ' ...
  havecolor = 1
  dotitles = 1
  esc_seq = '\x1b['
  g_attr = {'bg_black': 40, 'bg_blue': 44, 'bg_cyan': 46, 'bg_de...
  codes = {'0x000000': '\x1b[30m', '0x0000AA': '\x1b[34m', '0x00...
  ansi_color_codes = ['30m', '30;01m', '31m', '31;01m', '32m', '...
  rgb_ansi_colors = ['0x000000', '0x555555', '0xAA0000', '0xFF55...
  default_xterm_title = None
hash(x)
  nc = None
hash(x)
  MESSAGE_HEADER = u''
  ERROR_MESSAGE_HEADER = u''
  WARNING_MESSAGE_HEADER = u''
  __package__ = 'entropy'
  x = 15
Function Details

is_mute()

source code 

Return whether writing to stderr/stdout is allowed.

Returns: bool
mute status

set_mute(status)

source code 

Set mute status.

Parameters:
  • status (bool) - new mute status

is_interactive()

source code 

Return whether interactive mode is enabled.

Returns: bool
True, if interactive is enabled

is_stdout_a_tty()

source code 

Return whether current stdout is a TTY.

Returns: bool
tty? => True

xterm_title(mystr, raw=False)

source code 

Set new xterm title.

Parameters:
  • mystr (string) - new xterm title
  • raw (bool) - write title in raw mode

notitles()

source code 

Turn off title setting. In this way, xterm title won't be touched.

colorize(color_key, text)

source code 

Colorize text with given color key using bash/terminal codes.

Parameters:
  • color_key (string) - color identifier available in entropy.output.codes
Returns: string
coloured text

bold(text)

source code 

Make text bold using bash/terminal codes.

Parameters:
  • text (string) - text to colorize
Returns: string
colorized text

white(text)

source code 

Make text white using bash/terminal codes.

Parameters:
  • text (string) - text to colorize
Returns: string
colorized text

teal(text)

source code 

Make text teal using bash/terminal codes.

Parameters:
  • text (string) - text to colorize
Returns: string
colorized text

turquoise(text)

source code 

Make text turquoise using bash/terminal codes.

Parameters:
  • text (string) - text to colorize
Returns: string
colorized text

darkteal(text)

source code 

Make text darkteal using bash/terminal codes.

Parameters:
  • text (string) - text to colorize
Returns: string
colorized text

purple(text)

source code 

Make text purple using bash/terminal codes.

Parameters:
  • text (string) - text to colorize
Returns: string
colorized text

blue(text)

source code 

Make text blue using bash/terminal codes.

Parameters:
  • text (string) - text to colorize
Returns: string
colorized text

darkblue(text)

source code 

Make text darkblue using bash/terminal codes.

Parameters:
  • text (string) - text to colorize
Returns: string
colorized text

green(text)

source code 

Make text green using bash/terminal codes.

Parameters:
  • text (string) - text to colorize
Returns: string
colorized text

darkgreen(text)

source code 

Make text darkgreen using bash/terminal codes.

Parameters:
  • text (string) - text to colorize
Returns: string
colorized text

yellow(text)

source code 

Make text yellow using bash/terminal codes.

Parameters:
  • text (string) - text to colorize
Returns: string
colorized text

brown(text)

source code 

Make text brown using bash/terminal codes.

Parameters:
  • text (string) - text to colorize
Returns: string
colorized text

darkyellow(text)

source code 

Make text darkyellow using bash/terminal codes.

Parameters:
  • text (string) - text to colorize
Returns: string
colorized text

red(text)

source code 

Make text red using bash/terminal codes.

Parameters:
  • text (string) - text to colorize
Returns: string
colorized text

darkred(text)

source code 

Make text darkred using bash/terminal codes.

Parameters:
  • text (string) - text to colorize
Returns: string
colorized text

print_error(msg, back=False, flush=True, end='\n')

source code 

Service function used by Entropy text client (will be moved from here) to write error messages to stdout (not stderr, atm). NOTE: don't use this directly but rather subclass TextInterface class.

Parameters:
  • msg (string) - text message to print
  • back (bool) - move text cursor back to the beginning of the line
  • flush (bool) - flush stdout and stderr
Returns: None
None

print_info(msg, back=False, flush=True, end='\n')

source code 

Service function used by Entropy text client (will be moved from here) to write info messages to stdout (not stderr, atm). NOTE: don't use this directly but rather subclass TextInterface class.

Parameters:
  • msg (string) - text message to print
  • back (bool) - move text cursor back to the beginning of the line
  • flush (bool) - flush stdout and stderr
Returns: None
None

print_warning(msg, back=False, flush=True, end='\n')

source code 

Service function used by Entropy text client (will be moved from here) to write warning messages to stdout (not stderr, atm). NOTE: don't use this directly but rather subclass TextInterface class.

Parameters:
  • msg (string) - text message to print
  • back (bool) - move text cursor back to the beginning of the line
  • flush (bool) - flush stdout and stderr
Returns: None
None

print_generic(*args, **kwargs)

source code 

Service function used by Entropy text client (will be moved from here) to write generic messages to stdout (not stderr, atm). NOTE: don't use this directly but rather subclass TextInterface class.

writechar(chars, stderr=False)

source code 

Write characters to stdout (will be moved from here).

Parameters:
  • chars (string) - chars to write

readtext(request, password=False)

source code 

Read text from stdin and return it (will be moved from here).

Parameters:
  • request (string) - textual request to print
  • password (bool) - if you are requesting a password, set this to True
Returns: string
text read back from stdin
Raises:
  • EOFError - if CTRL+D is pressed

Variables Details

stuff

Value:
{'ESC': '\x1b',
 'cleanline': '                              ',
 'cols': 30,
 'cursor': False}

g_attr

Value:
{'bg_black': 40,
 'bg_blue': 44,
 'bg_cyan': 46,
 'bg_default': 49,
 'bg_green': 42,
 'bg_magenta': 45,
 'bg_red': 41,
 'bg_white': 47,
...

codes

Value:
{'0x000000': '\x1b[30m',
 '0x0000AA': '\x1b[34m',
 '0x00AA00': '\x1b[32m',
 '0x00AAAA': '\x1b[36m',
 '0x555555': '\x1b[30;01m',
 '0x5555FF': '\x1b[34;01m',
 '0x55FF55': '\x1b[32;01m',
 '0x55FFFF': '\x1b[36;01m',
...

ansi_color_codes

Value:
['30m',
 '30;01m',
 '31m',
 '31;01m',
 '32m',
 '32;01m',
 '33m',
 '33;01m',
...

rgb_ansi_colors

Value:
['0x000000',
 '0x555555',
 '0xAA0000',
 '0xFF5555',
 '0x00AA00',
 '0x55FF55',
 '0xAA5500',
 '0xFFFF55',
...