Package entropy :: Module output

Module output

source code

# DESCRIPTION: # Text formatting and colouring tools

Copyright 1998-2004 Gentoo Foundation # $Id: output.py 4906 2006-11-01 23:55:29Z zmedico $ Copyright (C) 2007-2008 Fabio Erculiani

This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version.

This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.

You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA

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
 
xtermTitle(mystr, raw=False)
Set new xterm title.
source code
 
xtermTitleReset()
Reset xterm title to default.
source code
 
notitles()
Turn off title setting.
source code
 
nocolor()
Turn off colorization process-wide.
source code
 
resetColor()
Reset terminal color currently set.
source code
string
colorize(color_key, text)
Colorize text with given color key using bash/terminal codes.
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
string
enlightenatom(atom)
Colorize package atoms with standard colors.
source code
 
print_menu(data, args=None)
Function used by Entropy text client (will be moved from here) to print the menu output given a properly formatted list.
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)
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)
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)
Service function used by Entropy text client (will be moved from here) to write warning messages to stdout (not stderr, atm).
source code
None
print_generic(msg)
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)
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
  nc = None
Function Details

xtermTitle(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

enlightenatom(atom)

source code 

Colorize package atoms with standard colors.

Parameters:
  • atom (string) - atom string
Returns: string
colorized string

print_menu(data, args=None)

source code 

Function used by Entropy text client (will be moved from here) to print the menu output given a properly formatted list. This method is not intended for general used and will be moved away from here.

print_error(msg, back=False, flush=True)

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)

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)

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(msg)

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.

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

writechar(chars)

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

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',
...