Skip to content

Commit

Permalink
moved console color code to consolecolor.py file
Browse files Browse the repository at this point in the history
  • Loading branch information
Harry Pierson committed Mar 20, 2009
1 parent ec6520e commit 41285e5
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 24 deletions.
30 changes: 30 additions & 0 deletions 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
33 changes: 9 additions & 24 deletions ipydbg.py
Expand Up @@ -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

Expand Down Expand Up @@ -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:
Expand Down Expand Up @@ -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,
Expand All @@ -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]()
Expand All @@ -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)
Expand Down

0 comments on commit 41285e5

Please sign in to comment.