aboutsummaryrefslogtreecommitdiff
path: root/lldb/utils/lui/commandwin.py
diff options
context:
space:
mode:
authorKate Stone <katherine.stone@apple.com>2016-09-06 20:57:50 +0000
committerKate Stone <katherine.stone@apple.com>2016-09-06 20:57:50 +0000
commitb9c1b51e45b845debb76d8658edabca70ca56079 (patch)
treedfcb5a13ef2b014202340f47036da383eaee74aa /lldb/utils/lui/commandwin.py
parentd5aa73376966339caad04013510626ec2e42c760 (diff)
downloadllvm-b9c1b51e45b845debb76d8658edabca70ca56079.zip
llvm-b9c1b51e45b845debb76d8658edabca70ca56079.tar.gz
llvm-b9c1b51e45b845debb76d8658edabca70ca56079.tar.bz2
*** This commit represents a complete reformatting of the LLDB source code
*** to conform to clang-format’s LLVM style. This kind of mass change has *** two obvious implications: Firstly, merging this particular commit into a downstream fork may be a huge effort. Alternatively, it may be worth merging all changes up to this commit, performing the same reformatting operation locally, and then discarding the merge for this particular commit. The commands used to accomplish this reformatting were as follows (with current working directory as the root of the repository): find . \( -iname "*.c" -or -iname "*.cpp" -or -iname "*.h" -or -iname "*.mm" \) -exec clang-format -i {} + find . -iname "*.py" -exec autopep8 --in-place --aggressive --aggressive {} + ; The version of clang-format used was 3.9.0, and autopep8 was 1.2.4. Secondly, “blame” style tools will generally point to this commit instead of a meaningful prior commit. There are alternatives available that will attempt to look through this change and find the appropriate prior commit. YMMV. llvm-svn: 280751
Diffstat (limited to 'lldb/utils/lui/commandwin.py')
-rw-r--r--lldb/utils/lui/commandwin.py222
1 files changed, 116 insertions, 106 deletions
diff --git a/lldb/utils/lui/commandwin.py b/lldb/utils/lui/commandwin.py
index 2eb2082..f778d73 100644
--- a/lldb/utils/lui/commandwin.py
+++ b/lldb/utils/lui/commandwin.py
@@ -1,9 +1,9 @@
##===-- commandwin.py ----------------------------------------*- Python -*-===##
##
-## The LLVM Compiler Infrastructure
+# The LLVM Compiler Infrastructure
##
-## This file is distributed under the University of Illinois Open Source
-## License. See LICENSE.TXT for details.
+# This file is distributed under the University of Illinois Open Source
+# License. See LICENSE.TXT for details.
##
##===----------------------------------------------------------------------===##
@@ -12,110 +12,120 @@ import curses
import lldb
from itertools import islice
+
class History(object):
- def __init__(self):
- self.data = {}
- self.pos = 0
- self.tempEntry = ''
-
- def previous(self, curr):
- if self.pos == len(self.data):
- self.tempEntry = curr
-
- if self.pos < 0:
- return ''
- if self.pos == 0:
- self.pos -= 1
- return ''
- if self.pos > 0:
- self.pos -= 1
- return self.data[self.pos]
-
- def next(self):
- if self.pos < len(self.data):
- self.pos += 1
-
- if self.pos < len(self.data):
- return self.data[self.pos]
- elif self.tempEntry != '':
- return self.tempEntry
- else:
- return ''
-
- def add(self, c):
- self.tempEntry = ''
- self.pos = len(self.data)
- if self.pos == 0 or self.data[self.pos-1] != c:
- self.data[self.pos] = c
- self.pos += 1
+
+ def __init__(self):
+ self.data = {}
+ self.pos = 0
+ self.tempEntry = ''
+
+ def previous(self, curr):
+ if self.pos == len(self.data):
+ self.tempEntry = curr
+
+ if self.pos < 0:
+ return ''
+ if self.pos == 0:
+ self.pos -= 1
+ return ''
+ if self.pos > 0:
+ self.pos -= 1
+ return self.data[self.pos]
+
+ def next(self):
+ if self.pos < len(self.data):
+ self.pos += 1
+
+ if self.pos < len(self.data):
+ return self.data[self.pos]
+ elif self.tempEntry != '':
+ return self.tempEntry
+ else:
+ return ''
+
+ def add(self, c):
+ self.tempEntry = ''
+ self.pos = len(self.data)
+ if self.pos == 0 or self.data[self.pos - 1] != c:
+ self.data[self.pos] = c
+ self.pos += 1
+
class CommandWin(cui.TitledWin):
- def __init__(self, driver, x, y, w, h):
- super(CommandWin, self).__init__(x, y, w, h, "Commands")
- self.command = ""
- self.data = ""
- driver.setSize(w, h)
-
- self.win.scrollok(1)
-
- self.driver = driver
- self.history = History()
-
- def enterCallback(content):
- self.handleCommand(content)
- def tabCompleteCallback(content):
- self.data = content
- matches = lldb.SBStringList()
- commandinterpreter = self.getCommandInterpreter()
- commandinterpreter.HandleCompletion(self.data, self.el.index, 0, -1, matches)
- if matches.GetSize() == 2:
- self.el.content += matches.GetStringAtIndex(0)
- self.el.index = len(self.el.content)
- self.el.draw()
- else:
- self.win.move(self.el.starty, self.el.startx)
- self.win.scroll(1)
- self.win.addstr("Available Completions:")
+
+ def __init__(self, driver, x, y, w, h):
+ super(CommandWin, self).__init__(x, y, w, h, "Commands")
+ self.command = ""
+ self.data = ""
+ driver.setSize(w, h)
+
+ self.win.scrollok(1)
+
+ self.driver = driver
+ self.history = History()
+
+ def enterCallback(content):
+ self.handleCommand(content)
+
+ def tabCompleteCallback(content):
+ self.data = content
+ matches = lldb.SBStringList()
+ commandinterpreter = self.getCommandInterpreter()
+ commandinterpreter.HandleCompletion(
+ self.data, self.el.index, 0, -1, matches)
+ if matches.GetSize() == 2:
+ self.el.content += matches.GetStringAtIndex(0)
+ self.el.index = len(self.el.content)
+ self.el.draw()
+ else:
+ self.win.move(self.el.starty, self.el.startx)
+ self.win.scroll(1)
+ self.win.addstr("Available Completions:")
+ self.win.scroll(1)
+ for m in islice(matches, 1, None):
+ self.win.addstr(self.win.getyx()[0], 0, m)
+ self.win.scroll(1)
+ self.el.draw()
+
+ self.startline = self.win.getmaxyx()[0] - 2
+
+ self.el = cui.CursesEditLine(
+ self.win,
+ self.history,
+ enterCallback,
+ tabCompleteCallback)
+ self.el.prompt = self.driver.getPrompt()
+ self.el.showPrompt(self.startline, 0)
+
+ def handleCommand(self, cmd):
+ # enter!
+ self.win.scroll(1) # TODO: scroll more for longer commands
+ if cmd == '':
+ cmd = self.history.previous('')
+ elif cmd in ('q', 'quit'):
+ self.driver.terminate()
+ return
+
+ self.history.add(cmd)
+ ret = self.driver.handleCommand(cmd)
+ if ret.Succeeded():
+ out = ret.GetOutput()
+ attr = curses.A_NORMAL
+ else:
+ out = ret.GetError()
+ attr = curses.color_pair(3) # red on black
+ self.win.addstr(self.startline, 0, out + '\n', attr)
self.win.scroll(1)
- for m in islice(matches, 1, None):
- self.win.addstr(self.win.getyx()[0], 0, m)
- self.win.scroll(1)
- self.el.draw()
-
- self.startline = self.win.getmaxyx()[0]-2
-
- self.el = cui.CursesEditLine(self.win, self.history, enterCallback, tabCompleteCallback)
- self.el.prompt = self.driver.getPrompt()
- self.el.showPrompt(self.startline, 0)
-
- def handleCommand(self, cmd):
- # enter!
- self.win.scroll(1) # TODO: scroll more for longer commands
- if cmd == '':
- cmd = self.history.previous('')
- elif cmd in ('q', 'quit'):
- self.driver.terminate()
- return
-
- self.history.add(cmd)
- ret = self.driver.handleCommand(cmd)
- if ret.Succeeded():
- out = ret.GetOutput()
- attr = curses.A_NORMAL
- else:
- out = ret.GetError()
- attr = curses.color_pair(3) # red on black
- self.win.addstr(self.startline, 0, out + '\n', attr)
- self.win.scroll(1)
- self.el.showPrompt(self.startline, 0)
-
- def handleEvent(self, event):
- if isinstance(event, int):
- if event == curses.ascii.EOT and self.el.content == '':
- # When the command is empty, treat CTRL-D as EOF.
- self.driver.terminate()
- return
- self.el.handleEvent(event)
-
- def getCommandInterpreter(self):
- return self.driver.getCommandInterpreter()
+ self.el.showPrompt(self.startline, 0)
+
+ def handleEvent(self, event):
+ if isinstance(event, int):
+ if event == curses.ascii.EOT and self.el.content == '':
+ # When the command is empty, treat CTRL-D as EOF.
+ self.driver.terminate()
+ return
+ self.el.handleEvent(event)
+
+ def getCommandInterpreter(self):
+ return self.driver.getCommandInterpreter()