Skip to content

Commit

Permalink
Merge pull request #41 from scottchiefbaker/next
Browse files Browse the repository at this point in the history
Add debug k() and kd() options
  • Loading branch information
scottchiefbaker authored Jun 5, 2023
2 parents b3328bf + d62aeac commit cb76737
Showing 1 changed file with 22 additions and 0 deletions.
22 changes: 22 additions & 0 deletions dool
Original file line number Diff line number Diff line change
Expand Up @@ -1506,6 +1506,11 @@ def bgcolor(num):

return ret

def text_color(num, mystr):
ret = "\033[38;5;" + str(num) + "m" + mystr + "\033[0m"

return ret

color = {
'black': fcolor(0),
'white': fcolor(15),
Expand Down Expand Up @@ -2639,6 +2644,23 @@ def find_plugin_file(name, dirs):

return ""

def k(obj, prefix = "DEBUG"):
import inspect

# https://stackoverflow.com/questions/6810999/how-to-determine-file-function-and-line-number
x = inspect.stack()[1]
info = inspect.getframeinfo(x[0])

line_str = "#" + str(info.lineno)
myfile = os.path.basename(__file__)

sys.stdout.write("%s %s @ %s: " % (prefix, text_color(228, myfile), text_color(117,line_str)))
print(obj)

def kd(obj):
k(obj, "DIED")
sys.exit(99)

### Main entrance
if __name__ == '__main__':
try:
Expand Down

0 comments on commit cb76737

Please sign in to comment.