[Lldb-commits] [lldb] r192765 - Add a ListWin to cui to show scrollabled lists
Ben Langmuir
ben.langmuir at intel.com
Tue Oct 15 19:00:21 PDT 2013
Author: benlangmuir
Date: Tue Oct 15 21:00:21 2013
New Revision: 192765
URL: http://llvm.org/viewvc/llvm-project?rev=192765&view=rev
Log:
Add a ListWin to cui to show scrollabled lists
Author: Paul Redmond <paul.redmond at intel.com>
Modified:
lldb/trunk/utils/lui/breakwin.py
lldb/trunk/utils/lui/cui.py
lldb/trunk/utils/lui/sandbox.py
lldb/trunk/utils/lui/statuswin.py
Modified: lldb/trunk/utils/lui/breakwin.py
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/utils/lui/breakwin.py?rev=192765&r1=192764&r2=192765&view=diff
==============================================================================
--- lldb/trunk/utils/lui/breakwin.py (original)
+++ lldb/trunk/utils/lui/breakwin.py Tue Oct 15 21:00:21 2013
@@ -11,27 +11,40 @@ import cui
import curses
import lldb, lldbutil
-class BreakWin(cui.TitledWin):
+class BreakWin(cui.ListWin):
def __init__(self, driver, x, y, w, h):
- super(BreakWin, self).__init__(x, y, w, h, 'Breakpoints')
- self.win.scrollok(1)
- super(BreakWin, self).draw()
+ super(BreakWin, self).__init__(x, y, w, h)
self.driver = driver
+ self.update()
def handleEvent(self, event):
if isinstance(event, lldb.SBEvent):
if lldb.SBBreakpoint.EventIsBreakpointEvent(event):
self.update()
+ if isinstance(event, int):
+ if event == ord('d'):
+ self.deleteSelected()
+ super(BreakWin, self).handleEvent(event)
+
+ def deleteSelected(self):
+ if self.getSelected() == -1:
+ return
+ target = self.driver.getTarget()
+ if not target.IsValid():
+ return
+ bp = target.GetBreakpointAtIndex(self.getSelected())
+ target.BreakpointDelete(bp.id)
def update(self):
target = self.driver.getTarget()
if not target.IsValid():
return
- self.win.addstr(0, 0, '')
+ selected = self.getSelected()
+ self.clearItems()
for i in range(0, target.GetNumBreakpoints()):
bp = target.GetBreakpointAtIndex(i)
if bp.IsInternal():
continue
text = lldbutil.get_description(bp)
- self.win.addstr(text)
- self.win.addstr('\n')
+ self.addItem(text)
+ self.setSelected(selected)
Modified: lldb/trunk/utils/lui/cui.py
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/utils/lui/cui.py?rev=192765&r1=192764&r2=192765&view=diff
==============================================================================
--- lldb/trunk/utils/lui/cui.py (original)
+++ lldb/trunk/utils/lui/cui.py Tue Oct 15 21:00:21 2013
@@ -72,6 +72,65 @@ class TitledWin(CursesWin):
self.title_win.draw()
self.win.noutrefresh()
+class ListWin(CursesWin):
+ def __init__(self, x, y, w, h):
+ super(ListWin, self).__init__(x, y, w, h)
+ self.items = []
+ self.selected = 0
+ self.first_drawn = 0
+
+ def draw(self):
+ h, w = self.win.getmaxyx()
+ if self.selected < self.first_drawn:
+ self.first_drawn = self.selected
+ if self.selected >= self.first_drawn + h:
+ self.first_drawn = self.selected - h + 1
+
+ self.win.clear()
+
+ begin = self.first_drawn
+ end = begin + h
+ for i, item in enumerate(self.items[begin:end]):
+ text = item
+ if i + begin == self.selected:
+ attr = curses.A_REVERSE
+ text = '{0:{width}}'.format(text, width=w-1)
+ else:
+ attr = curses.A_NORMAL
+ self.win.addstr(i, 0, text, attr)
+ self.win.noutrefresh()
+
+ def getSelected(self):
+ if self.items:
+ return self.selected
+ return -1
+
+ def setSelected(self, selected):
+ self.selected = selected
+ if self.selected < 0:
+ self.selected = 0
+ elif self.selected >= len(self.items):
+ self.selected = len(self.items) - 1
+
+ def handleEvent(self, event):
+ if isinstance(event, int):
+ if len(self.items) > 0:
+ if event == curses.KEY_UP:
+ self.setSelected(self.selected - 1)
+ if event == curses.KEY_DOWN:
+ self.setSelected(self.selected + 1)
+ if event == curses.ascii.NL:
+ self.handleSelect(self.selected)
+
+ def addItem(self, item):
+ self.items.append(item)
+
+ def clearItems(self):
+ self.items = []
+
+ def handleSelect(self, index):
+ return
+
class InputHandler(threading.Thread):
def __init__(self, screen, queue):
super(InputHandler, self).__init__()
Modified: lldb/trunk/utils/lui/sandbox.py
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/utils/lui/sandbox.py?rev=192765&r1=192764&r2=192765&view=diff
==============================================================================
--- lldb/trunk/utils/lui/sandbox.py (original)
+++ lldb/trunk/utils/lui/sandbox.py Tue Oct 15 21:00:21 2013
@@ -31,28 +31,33 @@ class SandboxUI(cui.CursesUI):
h2 = height / 2
self.wins = []
+ #self.wins.append(cui.TitledWin(w2, h2, w2, h2, "Test Window 4"))
+ list_win = cui.ListWin(w2, h2, w2, h2)
+ for i in range(0, 40):
+ list_win.addItem('Item %s' % i)
+ self.wins.append(list_win)
self.wins.append(cui.TitledWin( 0, 0, w2, h2, "Test Window 1"))
self.wins.append(cui.TitledWin(w2, 0, w2, h2, "Test Window 2"))
self.wins.append(cui.TitledWin( 0, h2, w2, h2, "Test Window 3"))
- self.wins.append(cui.TitledWin(w2, h2, w2, h2, "Test Window 4"))
- def callback(s, content):
- self.wins[0].win.scroll(1)
- self.wins[0].win.addstr(10, 0, '%s: %s' % (s, content))
- self.wins[0].win.scroll(1)
- self.el.showPrompt(10, 0)
+ #def callback(s, content):
+ # self.wins[0].win.scroll(1)
+ # self.wins[0].win.addstr(10, 0, '%s: %s' % (s, content))
+ # self.wins[0].win.scroll(1)
+ # self.el.showPrompt(10, 0)
- self.wins[0].win.scrollok(1)
- self.el = cui.CursesEditLine(self.wins[0].win, None,
- lambda c: callback('got', c), lambda c: callback('tab', c))
- self.el.prompt = '>>> '
- self.el.showPrompt(10, 0)
+ #self.wins[0].win.scrollok(1)
+ #self.el = cui.CursesEditLine(self.wins[0].win, None,
+ # lambda c: callback('got', c), lambda c: callback('tab', c))
+ #self.el.prompt = '>>> '
+ #self.el.showPrompt(10, 0)
def handleEvent(self, event):
if isinstance(event, int):
if event == ord('q'):
sys.exit(0)
- self.el.handleEvent(event)
+ #self.el.handleEvent(event)
+ super(SandboxUI, self).handleEvent(event)
def main(screen):
global event_queue
Modified: lldb/trunk/utils/lui/statuswin.py
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/utils/lui/statuswin.py?rev=192765&r1=192764&r2=192765&view=diff
==============================================================================
--- lldb/trunk/utils/lui/statuswin.py (original)
+++ lldb/trunk/utils/lui/statuswin.py Tue Oct 15 21:00:21 2013
@@ -18,10 +18,13 @@ class StatusWin(cui.TextWin):
self.keys = [#('F1', 'Help', curses.KEY_F1),
('F3', 'Cycle-focus', curses.KEY_F3),
('F10', 'Quit', curses.KEY_F10)]
- text = ''
+
+ def draw(self):
+ self.win.addstr(0, 0, '')
for key in self.keys:
- text = text + '{0} {1} '.format(key[0], key[1])
- self.setText(text)
+ self.win.addstr('{0}'.format(key[0]), curses.A_REVERSE)
+ self.win.addstr(' {0} '.format(key[1]), curses.A_NORMAL)
+ super(StatusWin, self).draw()
def handleEvent(self, event):
if isinstance(event, int):
More information about the lldb-commits
mailing list