Last active
March 18, 2018 15:08
-
-
Save s-c-p/dab69d745359548d58d02ce58c1d79c0 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import shutil | |
import inspect | |
prompt = lambda: input('debug>>> ') | |
disp_width = shutil.get_terminal_size().columns | |
def words_gen(lst, chunk): | |
ans = list() | |
while True: | |
try: | |
nxt = lst.pop(0) | |
except IndexError: | |
if ans: | |
yield ans | |
raise StopIteration | |
else: | |
ans.append(nxt) | |
if len(ans) == chunk: | |
yield ans | |
ans = [] | |
else: | |
continue | |
return | |
def _pp(attr_list): | |
if not attr_list: | |
return "" | |
slen = lambda w: len(w)+2 | |
cell_size = max(list(map(slen, attr_list))) | |
cell_count = disp_width//cell_size | |
for words in words_gen(attr_list, cell_count): | |
words = list(words) | |
word = words.pop(0) | |
ans = format(word, f"<{cell_size}s") | |
for word in words: | |
ans += format(word, f"<{cell_size}s") | |
print(ans) | |
return "printed something" | |
def show(cntxt_dcn): | |
keys = list(cntxt_dcn.keys()) | |
magic = list() | |
others = list() | |
for x in keys: | |
if x.startswith('__') and x.endswith('__'): | |
magic.append(x) | |
else: | |
others.append(x) | |
if _pp(magic) + _pp(others): | |
print('Whose value do you want to see?') | |
k = prompt() | |
else: | |
k = -1 | |
try: | |
cntxt_dcn[k] | |
except KeyError: | |
pass | |
else: | |
print('value of `%s` is--' % k) | |
print(cntxt_dcn[k]) | |
_ = input('Press [Enter] to continue') | |
print('_'*disp_width) | |
return | |
def db(): | |
dbFrame = inspect.currentframe() | |
fnFrame = dbFrame.f_back | |
fnIntel = inspect.getframeinfo(fnFrame) | |
file_ = fnIntel.filename | |
fnName = fnIntel.function | |
locals_ = fnFrame.f_locals | |
globals_ = fnFrame.f_globals | |
currLine = fnFrame.f_lineno | |
while True: | |
print("file: %s\nline: #%d\nfunction: %s()" % (file_, currLine, fnName)) | |
print("What would you like to see?") | |
print('[l]ocals, [g]lobals or [q]uit') | |
ch = prompt() | |
if ch == 'l': | |
show(locals_) | |
elif ch == 'g': | |
show(globals_) | |
elif ch == 'q': | |
break | |
return | |
use vimrunner for CLI | |
use websockets+elm for browser based GUI |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment