~ubuntu-branches/ubuntu/natty/python-cogent/natty

« back to all changes in this revision

Viewing changes to cogent/util/terminal.py

  • Committer: Bazaar Package Importer
  • Author(s): Steffen Moeller
  • Date: 2010-12-04 22:30:35 UTC
  • mfrom: (1.1.1 upstream)
  • Revision ID: james.westby@ubuntu.com-20101204223035-j11kinhcrrdgg2p2
Tags: 1.5-1
* Bumped standard to 3.9.1, no changes required.
* New upstream version.
  - major additions to Cookbook
  - added AlleleFreqs attribute to ensembl Variation objects.
  - added getGeneByStableId method to genome objects.
  - added Introns attribute to Transcript objects and an Intron class.
  - added Mann-Whitney test and a Monte-Carlo version
  - exploratory and confirmatory period estimation techniques (suitable for
    symbolic and continuous data)
  - Information theoretic measures (AIC and BIC) added
  - drawing of trees with collapsed nodes
  - progress display indicator support for terminal and GUI apps
  - added parser for illumina HiSeq2000 and GAiix sequence files as 
    cogent.parse.illumina_sequence.MinimalIlluminaSequenceParser.
  - added parser to FASTQ files, one of the output options for illumina's
    workflow, also added cookbook demo.
  - added functionality for parsing of SFF files without the Roche tools in
    cogent.parse.binary_sff
  - thousand fold performance improvement to nmds
  - >10-fold performance improvements to some Table operations

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
#!/usr/bin/env python
 
2
 
 
3
__author__ = "Nadia Alramli"
 
4
__copyright__ = "Nadia Alramli"
 
5
__credits__ = ["Nadia Alramli"]
 
6
__license__ = "BSD"
 
7
__version__ = "1.5.0"
 
8
__maintainer__ = "Peter Maxwell"
 
9
__email__ = "pm67nz@gmail.com"
 
10
__status__ = "Production"
 
11
 
 
12
# Copyright: 2008 Nadia Alramli
 
13
# License: BSD
 
14
 
 
15
import sys
 
16
try:
 
17
    import curses
 
18
except ImportError:
 
19
    curses = None
 
20
 
 
21
COLORS = "BLUE GREEN CYAN RED MAGENTA YELLOW WHITE BLACK".split()
 
22
 
 
23
# List of terminal controls, you can add more to the list.
 
24
_CONTROLS = {
 
25
    'BOL':'cr', 'UP':'cuu1', 'DOWN':'cud1', 'LEFT':'cub1', 'RIGHT':'cuf1',
 
26
    'CLEAR_SCREEN':'clear', 'CLEAR_EOL':'el', 'CLEAR_BOL':'el1',
 
27
    'CLEAR_EOS':'ed', 'BOLD':'bold', 'BLINK':'blink', 'DIM':'dim',
 
28
    'REVERSE':'rev', 'UNDERLINE':'smul', 'NORMAL':'sgr0',
 
29
    'HIDE_CURSOR':'cinvis', 'SHOW_CURSOR':'cnorm'
 
30
        }
 
31
 
 
32
class TerminalUnavailableError(RuntimeError):
 
33
    pass
 
34
    
 
35
class CursesOutput(object):
 
36
    def __init__(self):
 
37
        if curses is None or not hasattr(sys.stdout, 'fileno'):
 
38
            raise TerminalUnavailableError("No curses modules")
 
39
        try:
 
40
            curses.setupterm()
 
41
        except curses.error, detail:
 
42
            raise TerminalUnavailableError(detail)
 
43
    
 
44
    def getColumns(self):
 
45
        return curses.tigetnum('cols')
 
46
    
 
47
    def getLines(self):
 
48
        return curses.tigetnum('lines')
 
49
    
 
50
    def getCodes(self):
 
51
        # Get the color escape sequence template or '' if not supported
 
52
        # setab and setaf are for ANSI escape sequences
 
53
        bgColorSeq = curses.tigetstr('setab') or curses.tigetstr('setb') or ''
 
54
        fgColorSeq = curses.tigetstr('setaf') or curses.tigetstr('setf') or ''
 
55
        codes = {}
 
56
 
 
57
        for color in COLORS:
 
58
            # Get the color index from curses
 
59
            colorIndex = getattr(curses, 'COLOR_%s' % color)
 
60
            # Set the color escape sequence after filling the template with index
 
61
            codes[color] = curses.tparm(fgColorSeq, colorIndex)
 
62
            # Set background escape sequence
 
63
            codes['BG_%s' % color] = curses.tparm(bgColorSeq, colorIndex)
 
64
        for control in _CONTROLS:
 
65
            # Set the control escape sequence
 
66
            codes[control] = curses.tigetstr(_CONTROLS[control]) or ''
 
67
        
 
68
        return codes