Permalink
Browse files

moved console color code to consolecolor.py file

  • Loading branch information...
1 parent ec6520e commit 41285e5c6a639708b9ae9e4886f2f8f4ae159540 @devhawk committed Mar 20, 2009
Showing with 39 additions and 24 deletions.
  1. +30 −0 consolecolor.py
  2. +9 −24 ipydbg.py
View
@@ -0,0 +1,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
View
@@ -18,23 +18,8 @@
from Microsoft.Samples.Debugging.CorMetadata.NativeApi import IMetadataImport
from Microsoft.Samples.Debugging.CorSymbolStore import SymbolBinder
-#--------------------------------------------
-# helper class to manage console color
-
-class ConsoleColorMgr(object):
- def __init__(self, color):
- self.color = color
-
- def __enter__(self):
- self.temp = Console.ForegroundColor
- Console.ForegroundColor = self.color
-
- def __exit__(self, t, v, tr):
- Console.ForegroundColor = self.temp
+import consolecolor as CC
-CCDarkGray = ConsoleColorMgr(ConsoleColor.DarkGray)
-CCGray = ConsoleColorMgr(ConsoleColor.Gray)
-CCYellow = ConsoleColorMgr(ConsoleColor.Yellow)
#--------------------------------------------
# sequence point functions
@@ -180,10 +165,10 @@ def run(self, py_file):
def _print_source_line(self, sp, lines):
line = lines[sp.start_line-1]
- with CCGray:
+ with CC.Gray:
Console.Write("%d: " % sp.start_line)
Console.Write(line.Substring(0, sp.start_col-1))
- with CCYellow:
+ with CC.Yellow:
if sp.start_col > len(line):
Console.Write(" ^^^")
else:
@@ -237,18 +222,18 @@ def _input(self):
print "\nPlease enter a valid command"
def OnCreateAppDomain(self, sender,e):
- with CCDarkGray:
+ with CC.DarkGray:
print "OnCreateAppDomain", e.AppDomain.Name
e.AppDomain.Attach()
def OnProcessExit(self, sender,e):
- with CCDarkGray:
+ with CC.DarkGray:
print "OnProcessExit"
self.terminate_event.Set()
def OnClassLoad(self, sender, e):
mt = e.Class.GetTypeInfo()
- with CCDarkGray:
+ with CC.DarkGray:
print "OnClassLoad", mt.Name
#python code is always in a dynamic module,
@@ -274,7 +259,7 @@ def OnClassLoad(self, sender, e):
f.JMCStatus = False
def OnUpdateModuleSymbols(self, sender,e):
- with CCDarkGray:
+ with CC.DarkGray:
print "OnUpdateModuleSymbols"
metadata_import = e.Module.GetMetaDataInterface[IMetadataImport]()
@@ -294,13 +279,13 @@ def OnUpdateModuleSymbols(self, sender,e):
def OnBreakpoint(self, sender,e):
method_info = e.Thread.ActiveFrame.Function.GetMethodInfo()
offset, sp = self._get_location(e.Thread.ActiveFrame)
- with CCDarkGray:
+ with CC.DarkGray:
print "OnBreakpoint", method_info.Name, "Location:", sp if sp != None else "offset %d" % offset
self._do_break_event(e)
def OnStepComplete(self, sender,e):
offset, sp = self._get_location(e.Thread.ActiveFrame)
- with CCDarkGray:
+ with CC.DarkGray:
print "OnStepComplete Reason:", e.StepReason, "Location:", sp if sp != None else "offset %d" % offset
if e.StepReason == CorDebugStepReason.STEP_CALL:
self._do_step(e.Thread, False)

0 comments on commit 41285e5

Please sign in to comment.