devhawk / ipydbg

managed debugger for IronPython

This URL has Read+Write access

ipydbg / consolecolor.py
100644 30 lines (23 sloc) 0.841 kb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
from System import Console as _Console
 
class ConsoleColorMgr(object):
  def __init__(self, foreground = None, background = None):
    self.foreground = foreground
    self.background = background
 
  def __enter__(self):
    self._tempFG = _Console.ForegroundColor
    self._tempBG = _Console.BackgroundColor
    
    if self.foreground: _Console.ForegroundColor = self.foreground
    if self.background: _Console.BackgroundColor = self.background
      
  def __exit__(self, t, v, tr):
    _Console.ForegroundColor = self._tempFG
    _Console.BackgroundColor = self._tempBG
 
import sys
_curmodule = sys.modules[__name__]
 
from System import ConsoleColor, Enum
for n in Enum.GetNames(ConsoleColor):
  setattr(_curmodule, n, ConsoleColorMgr(Enum.Parse(ConsoleColor, n)))
  
del ConsoleColor
del Enum
del sys
del _curmodule
del n