From 41285e5c6a639708b9ae9e4886f2f8f4ae159540 Mon Sep 17 00:00:00 2001 From: Harry Pierson Date: Thu, 19 Mar 2009 17:11:23 -0700 Subject: [PATCH] moved console color code to consolecolor.py file --- consolecolor.py | 30 ++++++++++++++++++++++++++++++ ipydbg.py | 33 +++++++++------------------------ 2 files changed, 39 insertions(+), 24 deletions(-) create mode 100644 consolecolor.py diff --git a/consolecolor.py b/consolecolor.py new file mode 100644 index 0000000..479f15c --- /dev/null +++ b/consolecolor.py @@ -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 \ No newline at end of file diff --git a/ipydbg.py b/ipydbg.py index bddadc0..b51f10d 100644 --- a/ipydbg.py +++ b/ipydbg.py @@ -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)