* colorful nested (^^gdb) prompt
@ 2012-01-18 18:44 Matt Rice
2012-01-19 21:32 ` Tom Tromey
0 siblings, 1 reply; 2+ messages in thread
From: Matt Rice @ 2012-01-18 18:44 UTC (permalink / raw)
To: gdb-patches
[-- Attachment #1: Type: text/plain, Size: 407 bytes --]
attached is the script mentioned here:
http://sourceware.org/ml/gdb-patches/2012-01/msg00619.html
mostly pulled out of
git://gitorious.org/misc-gdb-stuff/misc-gdb-stuff.git
into a single script since I haven't settled on a manner of easily and flexibly
doing explicit loading from .gdbinit (rather than relying on auto-loading).
doesn't work with tui (not sure why, haven't looked), and requires curses.
[-- Attachment #2: nested-prompt.py --]
[-- Type: text/x-python, Size: 2680 bytes --]
def go():
prompt_nest=""
if os.environ.has_key('GDB_PROMPT_NEST'):
prompt_nest = os.environ['GDB_PROMPT_NEST']
# note this is backwards from git's usage of ^
gdb.execute("set environment GDB_PROMPT_NEST " + prompt_nest + '^')
nesting_colors = ("blue", "green", "red", "yellow")
prompt_color = nesting_colors[len(prompt_nest) % len(nesting_colors)]
prompt_list = [('(', 'normal'),
(prompt_nest, 'normal'),
(first_prompt, prompt_color),
(') ', 'normal')]
# pick one of the following 2 lines...
gdb.prompt_hook = setup_gaudy_prompt(prompt_list, term_colors())
#gdb.prompt_hook = setup_gaudy_prompt(prompt_list, no_colors)
import types
import gdb
def ignore_escape_sequence(string):
return "\001" + string + "\002"
the_very_first_prompt = None
def first_prompt(current):
global the_very_first_prompt
if (the_very_first_prompt != None):
return the_very_first_prompt
x = current
y = x.find('(')
if (y != -1):
x = x[y + 1 : len(x)]
y = x.rfind(')')
if (y != -1):
x = x[0:y]
the_very_first_prompt = x
return the_very_first_prompt
# FIXME fgcolor,color,term_colors are platform specific.
def fgcolor(COLOR):
return color("setaf", COLOR)
def color(string, COLOR):
return ignore_escape_sequence(tparm(tigetstr(string), COLOR))
from curses import *
# accepts an option term, term = None is getenv("TERM").
def term_colors(term = None):
# under gdb sys.stdout doesn't implement fileno()
# use normal stdout fileno?
setupterm(term, 1);
return {
'black' : fgcolor(COLOR_BLACK),
'red' : fgcolor(COLOR_RED),
'green' : fgcolor(COLOR_GREEN),
'yellow' : fgcolor(COLOR_YELLOW),
'blue' : fgcolor(COLOR_BLUE),
'magenta' : fgcolor(COLOR_MAGENTA),
'cyan' : fgcolor(COLOR_CYAN),
'white' : fgcolor(COLOR_WHITE),
'normal' : ignore_escape_sequence(tigetstr("sgr0")),
}
no_colors = {
'black' : "",
'red' : "",
'green' : "",
'yellow' : "",
'blue' : "",
'magenta' : "",
'cyan' : "",
'white' : "",
'normal' : "",
}
def string_for_prompt_element(current, e):
if e[0].__class__ == types.FunctionType:
return e[0](current)
else:
return e[0]
def prompt_recursive(current, alist, colors_dict):
ret = ""
for e in alist:
if e.__class__ == list:
ret += prompt_recursive(current, e, colors_dict)
else:
x = string_for_prompt_element(current, e)
if (x == None):
return ""
ret += colors_dict[e[1]] + x + colors_dict['normal']
return ret
def setup_gaudy_prompt(prompt_stuff, colors_stuff):
return lambda current: prompt_recursive(current, prompt_stuff, colors_stuff)
go()
^ permalink raw reply [flat|nested] 2+ messages in thread
* Re: colorful nested (^^gdb) prompt
2012-01-18 18:44 colorful nested (^^gdb) prompt Matt Rice
@ 2012-01-19 21:32 ` Tom Tromey
0 siblings, 0 replies; 2+ messages in thread
From: Tom Tromey @ 2012-01-19 21:32 UTC (permalink / raw)
To: Matt Rice; +Cc: gdb-patches
>>>>> "Matt" == Matt Rice <ratmice@gmail.com> writes:
Matt> attached is the script mentioned here:
Matt> http://sourceware.org/ml/gdb-patches/2012-01/msg00619.html
Thanks.
I expect it could be done with a new backslash escape with the
extended-prompt stuff...
Tom
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2012-01-19 21:07 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2012-01-18 18:44 colorful nested (^^gdb) prompt Matt Rice
2012-01-19 21:32 ` Tom Tromey
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).