diff options
author | Kate Stone <katherine.stone@apple.com> | 2016-09-06 20:57:50 +0000 |
---|---|---|
committer | Kate Stone <katherine.stone@apple.com> | 2016-09-06 20:57:50 +0000 |
commit | b9c1b51e45b845debb76d8658edabca70ca56079 (patch) | |
tree | dfcb5a13ef2b014202340f47036da383eaee74aa /lldb/third_party/Python/module/pexpect-2.4/ANSI.py | |
parent | d5aa73376966339caad04013510626ec2e42c760 (diff) | |
download | bcm5719-llvm-b9c1b51e45b845debb76d8658edabca70ca56079.tar.gz bcm5719-llvm-b9c1b51e45b845debb76d8658edabca70ca56079.zip |
*** 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/third_party/Python/module/pexpect-2.4/ANSI.py')
-rw-r--r-- | lldb/third_party/Python/module/pexpect-2.4/ANSI.py | 282 |
1 files changed, 159 insertions, 123 deletions
diff --git a/lldb/third_party/Python/module/pexpect-2.4/ANSI.py b/lldb/third_party/Python/module/pexpect-2.4/ANSI.py index 537017e90b2..003bab270e6 100644 --- a/lldb/third_party/Python/module/pexpect-2.4/ANSI.py +++ b/lldb/third_party/Python/module/pexpect-2.4/ANSI.py @@ -13,90 +13,106 @@ import FSM import copy import string -def Emit (fsm): + +def Emit(fsm): screen = fsm.memory[0] screen.write_ch(fsm.input_symbol) -def StartNumber (fsm): - fsm.memory.append (fsm.input_symbol) +def StartNumber(fsm): + + fsm.memory.append(fsm.input_symbol) -def BuildNumber (fsm): + +def BuildNumber(fsm): ns = fsm.memory.pop() ns = ns + fsm.input_symbol - fsm.memory.append (ns) + fsm.memory.append(ns) + -def DoBackOne (fsm): +def DoBackOne(fsm): screen = fsm.memory[0] - screen.cursor_back () + screen.cursor_back() -def DoBack (fsm): + +def DoBack(fsm): count = int(fsm.memory.pop()) screen = fsm.memory[0] - screen.cursor_back (count) + screen.cursor_back(count) + -def DoDownOne (fsm): +def DoDownOne(fsm): screen = fsm.memory[0] - screen.cursor_down () + screen.cursor_down() -def DoDown (fsm): + +def DoDown(fsm): count = int(fsm.memory.pop()) screen = fsm.memory[0] - screen.cursor_down (count) + screen.cursor_down(count) + -def DoForwardOne (fsm): +def DoForwardOne(fsm): screen = fsm.memory[0] - screen.cursor_forward () + screen.cursor_forward() -def DoForward (fsm): + +def DoForward(fsm): count = int(fsm.memory.pop()) screen = fsm.memory[0] - screen.cursor_forward (count) + screen.cursor_forward(count) + -def DoUpReverse (fsm): +def DoUpReverse(fsm): screen = fsm.memory[0] screen.cursor_up_reverse() -def DoUpOne (fsm): + +def DoUpOne(fsm): screen = fsm.memory[0] - screen.cursor_up () + screen.cursor_up() + -def DoUp (fsm): +def DoUp(fsm): count = int(fsm.memory.pop()) screen = fsm.memory[0] - screen.cursor_up (count) + screen.cursor_up(count) -def DoHome (fsm): + +def DoHome(fsm): c = int(fsm.memory.pop()) r = int(fsm.memory.pop()) screen = fsm.memory[0] - screen.cursor_home (r,c) + screen.cursor_home(r, c) + -def DoHomeOrigin (fsm): +def DoHomeOrigin(fsm): c = 1 r = 1 screen = fsm.memory[0] - screen.cursor_home (r,c) + screen.cursor_home(r, c) + -def DoEraseDown (fsm): +def DoEraseDown(fsm): screen = fsm.memory[0] screen.erase_down() -def DoErase (fsm): + +def DoErase(fsm): arg = int(fsm.memory.pop()) screen = fsm.memory[0] @@ -107,12 +123,14 @@ def DoErase (fsm): elif arg == 2: screen.erase_screen() -def DoEraseEndOfLine (fsm): + +def DoEraseEndOfLine(fsm): screen = fsm.memory[0] screen.erase_end_of_line() -def DoEraseLine (fsm): + +def DoEraseLine(fsm): screen = fsm.memory[0] if arg == 0: @@ -122,146 +140,164 @@ def DoEraseLine (fsm): elif arg == 2: screen.erase_line() -def DoEnableScroll (fsm): + +def DoEnableScroll(fsm): screen = fsm.memory[0] screen.scroll_screen() -def DoCursorSave (fsm): + +def DoCursorSave(fsm): screen = fsm.memory[0] screen.cursor_save_attrs() -def DoCursorRestore (fsm): + +def DoCursorRestore(fsm): screen = fsm.memory[0] screen.cursor_restore_attrs() -def DoScrollRegion (fsm): + +def DoScrollRegion(fsm): screen = fsm.memory[0] r2 = int(fsm.memory.pop()) r1 = int(fsm.memory.pop()) - screen.scroll_screen_rows (r1,r2) + screen.scroll_screen_rows(r1, r2) -def DoMode (fsm): + +def DoMode(fsm): screen = fsm.memory[0] - mode = fsm.memory.pop() # Should be 4 + mode = fsm.memory.pop() # Should be 4 # screen.setReplaceMode () -def Log (fsm): + +def Log(fsm): screen = fsm.memory[0] fsm.memory = [screen] - fout = open ('log', 'a') - fout.write (fsm.input_symbol + ',' + fsm.current_state + '\n') + fout = open('log', 'a') + fout.write(fsm.input_symbol + ',' + fsm.current_state + '\n') fout.close() + class term (screen.screen): - """This is a placeholder. + """This is a placeholder. In theory I might want to add other terminal types. """ - def __init__ (self, r=24, c=80): - screen.screen.__init__(self, r,c) + + def __init__(self, r=24, c=80): + screen.screen.__init__(self, r, c) + class ANSI (term): """This class encapsulates a generic terminal. It filters a stream and maintains the state of a screen object. """ - def __init__ (self, r=24,c=80): + def __init__(self, r=24, c=80): - term.__init__(self,r,c) + term.__init__(self, r, c) #self.screen = screen (24,80) - self.state = FSM.FSM ('INIT',[self]) - self.state.set_default_transition (Log, 'INIT') - self.state.add_transition_any ('INIT', Emit, 'INIT') - self.state.add_transition ('\x1b', 'INIT', None, 'ESC') - self.state.add_transition_any ('ESC', Log, 'INIT') - self.state.add_transition ('(', 'ESC', None, 'G0SCS') - self.state.add_transition (')', 'ESC', None, 'G1SCS') - self.state.add_transition_list ('AB012', 'G0SCS', None, 'INIT') - self.state.add_transition_list ('AB012', 'G1SCS', None, 'INIT') - self.state.add_transition ('7', 'ESC', DoCursorSave, 'INIT') - self.state.add_transition ('8', 'ESC', DoCursorRestore, 'INIT') - self.state.add_transition ('M', 'ESC', DoUpReverse, 'INIT') - self.state.add_transition ('>', 'ESC', DoUpReverse, 'INIT') - self.state.add_transition ('<', 'ESC', DoUpReverse, 'INIT') - self.state.add_transition ('=', 'ESC', None, 'INIT') # Selects application keypad. - self.state.add_transition ('#', 'ESC', None, 'GRAPHICS_POUND') - self.state.add_transition_any ('GRAPHICS_POUND', None, 'INIT') - self.state.add_transition ('[', 'ESC', None, 'ELB') + self.state = FSM.FSM('INIT', [self]) + self.state.set_default_transition(Log, 'INIT') + self.state.add_transition_any('INIT', Emit, 'INIT') + self.state.add_transition('\x1b', 'INIT', None, 'ESC') + self.state.add_transition_any('ESC', Log, 'INIT') + self.state.add_transition('(', 'ESC', None, 'G0SCS') + self.state.add_transition(')', 'ESC', None, 'G1SCS') + self.state.add_transition_list('AB012', 'G0SCS', None, 'INIT') + self.state.add_transition_list('AB012', 'G1SCS', None, 'INIT') + self.state.add_transition('7', 'ESC', DoCursorSave, 'INIT') + self.state.add_transition('8', 'ESC', DoCursorRestore, 'INIT') + self.state.add_transition('M', 'ESC', DoUpReverse, 'INIT') + self.state.add_transition('>', 'ESC', DoUpReverse, 'INIT') + self.state.add_transition('<', 'ESC', DoUpReverse, 'INIT') + # Selects application keypad. + self.state.add_transition('=', 'ESC', None, 'INIT') + self.state.add_transition('#', 'ESC', None, 'GRAPHICS_POUND') + self.state.add_transition_any('GRAPHICS_POUND', None, 'INIT') + self.state.add_transition('[', 'ESC', None, 'ELB') # ELB means Escape Left Bracket. That is ^[[ - self.state.add_transition ('H', 'ELB', DoHomeOrigin, 'INIT') - self.state.add_transition ('D', 'ELB', DoBackOne, 'INIT') - self.state.add_transition ('B', 'ELB', DoDownOne, 'INIT') - self.state.add_transition ('C', 'ELB', DoForwardOne, 'INIT') - self.state.add_transition ('A', 'ELB', DoUpOne, 'INIT') - self.state.add_transition ('J', 'ELB', DoEraseDown, 'INIT') - self.state.add_transition ('K', 'ELB', DoEraseEndOfLine, 'INIT') - self.state.add_transition ('r', 'ELB', DoEnableScroll, 'INIT') - self.state.add_transition ('m', 'ELB', None, 'INIT') - self.state.add_transition ('?', 'ELB', None, 'MODECRAP') - self.state.add_transition_list (string.digits, 'ELB', StartNumber, 'NUMBER_1') - self.state.add_transition_list (string.digits, 'NUMBER_1', BuildNumber, 'NUMBER_1') - self.state.add_transition ('D', 'NUMBER_1', DoBack, 'INIT') - self.state.add_transition ('B', 'NUMBER_1', DoDown, 'INIT') - self.state.add_transition ('C', 'NUMBER_1', DoForward, 'INIT') - self.state.add_transition ('A', 'NUMBER_1', DoUp, 'INIT') - self.state.add_transition ('J', 'NUMBER_1', DoErase, 'INIT') - self.state.add_transition ('K', 'NUMBER_1', DoEraseLine, 'INIT') - self.state.add_transition ('l', 'NUMBER_1', DoMode, 'INIT') - ### It gets worse... the 'm' code can have infinite number of - ### number;number;number before it. I've never seen more than two, - ### but the specs say it's allowed. crap! - self.state.add_transition ('m', 'NUMBER_1', None, 'INIT') - ### LED control. Same problem as 'm' code. - self.state.add_transition ('q', 'NUMBER_1', None, 'INIT') - + self.state.add_transition('H', 'ELB', DoHomeOrigin, 'INIT') + self.state.add_transition('D', 'ELB', DoBackOne, 'INIT') + self.state.add_transition('B', 'ELB', DoDownOne, 'INIT') + self.state.add_transition('C', 'ELB', DoForwardOne, 'INIT') + self.state.add_transition('A', 'ELB', DoUpOne, 'INIT') + self.state.add_transition('J', 'ELB', DoEraseDown, 'INIT') + self.state.add_transition('K', 'ELB', DoEraseEndOfLine, 'INIT') + self.state.add_transition('r', 'ELB', DoEnableScroll, 'INIT') + self.state.add_transition('m', 'ELB', None, 'INIT') + self.state.add_transition('?', 'ELB', None, 'MODECRAP') + self.state.add_transition_list( + string.digits, 'ELB', StartNumber, 'NUMBER_1') + self.state.add_transition_list( + string.digits, 'NUMBER_1', BuildNumber, 'NUMBER_1') + self.state.add_transition('D', 'NUMBER_1', DoBack, 'INIT') + self.state.add_transition('B', 'NUMBER_1', DoDown, 'INIT') + self.state.add_transition('C', 'NUMBER_1', DoForward, 'INIT') + self.state.add_transition('A', 'NUMBER_1', DoUp, 'INIT') + self.state.add_transition('J', 'NUMBER_1', DoErase, 'INIT') + self.state.add_transition('K', 'NUMBER_1', DoEraseLine, 'INIT') + self.state.add_transition('l', 'NUMBER_1', DoMode, 'INIT') + # It gets worse... the 'm' code can have infinite number of + # number;number;number before it. I've never seen more than two, + # but the specs say it's allowed. crap! + self.state.add_transition('m', 'NUMBER_1', None, 'INIT') + # LED control. Same problem as 'm' code. + self.state.add_transition('q', 'NUMBER_1', None, 'INIT') + # \E[?47h appears to be "switch to alternate screen" # \E[?47l restores alternate screen... I think. - self.state.add_transition_list (string.digits, 'MODECRAP', StartNumber, 'MODECRAP_NUM') - self.state.add_transition_list (string.digits, 'MODECRAP_NUM', BuildNumber, 'MODECRAP_NUM') - self.state.add_transition ('l', 'MODECRAP_NUM', None, 'INIT') - self.state.add_transition ('h', 'MODECRAP_NUM', None, 'INIT') - -#RM Reset Mode Esc [ Ps l none - self.state.add_transition (';', 'NUMBER_1', None, 'SEMICOLON') - self.state.add_transition_any ('SEMICOLON', Log, 'INIT') - self.state.add_transition_list (string.digits, 'SEMICOLON', StartNumber, 'NUMBER_2') - self.state.add_transition_list (string.digits, 'NUMBER_2', BuildNumber, 'NUMBER_2') - self.state.add_transition_any ('NUMBER_2', Log, 'INIT') - self.state.add_transition ('H', 'NUMBER_2', DoHome, 'INIT') - self.state.add_transition ('f', 'NUMBER_2', DoHome, 'INIT') - self.state.add_transition ('r', 'NUMBER_2', DoScrollRegion, 'INIT') - ### It gets worse... the 'm' code can have infinite number of - ### number;number;number before it. I've never seen more than two, - ### but the specs say it's allowed. crap! - self.state.add_transition ('m', 'NUMBER_2', None, 'INIT') - ### LED control. Same problem as 'm' code. - self.state.add_transition ('q', 'NUMBER_2', None, 'INIT') - - def process (self, c): + self.state.add_transition_list( + string.digits, 'MODECRAP', StartNumber, 'MODECRAP_NUM') + self.state.add_transition_list( + string.digits, + 'MODECRAP_NUM', + BuildNumber, + 'MODECRAP_NUM') + self.state.add_transition('l', 'MODECRAP_NUM', None, 'INIT') + self.state.add_transition('h', 'MODECRAP_NUM', None, 'INIT') + +# RM Reset Mode Esc [ Ps l none + self.state.add_transition(';', 'NUMBER_1', None, 'SEMICOLON') + self.state.add_transition_any('SEMICOLON', Log, 'INIT') + self.state.add_transition_list( + string.digits, 'SEMICOLON', StartNumber, 'NUMBER_2') + self.state.add_transition_list( + string.digits, 'NUMBER_2', BuildNumber, 'NUMBER_2') + self.state.add_transition_any('NUMBER_2', Log, 'INIT') + self.state.add_transition('H', 'NUMBER_2', DoHome, 'INIT') + self.state.add_transition('f', 'NUMBER_2', DoHome, 'INIT') + self.state.add_transition('r', 'NUMBER_2', DoScrollRegion, 'INIT') + # It gets worse... the 'm' code can have infinite number of + # number;number;number before it. I've never seen more than two, + # but the specs say it's allowed. crap! + self.state.add_transition('m', 'NUMBER_2', None, 'INIT') + # LED control. Same problem as 'm' code. + self.state.add_transition('q', 'NUMBER_2', None, 'INIT') + + def process(self, c): self.state.process(c) - def process_list (self, l): + def process_list(self, l): self.write(l) - def write (self, s): + def write(self, s): for c in s: self.process(c) - def flush (self): + def flush(self): pass - def write_ch (self, ch): - + def write_ch(self, ch): """This puts a character at the current cursor position. cursor position if moved forward with wrap-around, but no scrolling is done if the cursor hits the lower-right corner of the screen. """ @@ -270,7 +306,7 @@ class ANSI (term): ch = ch[0] if ch == '\r': - # self.crlf() + # self.crlf() return if ch == '\n': self.crlf() @@ -281,8 +317,8 @@ class ANSI (term): return if ch not in string.printable: - fout = open ('log', 'a') - fout.write ('Nonprint: ' + str(ord(ch)) + '\n') + fout = open('log', 'a') + fout.write('Nonprint: ' + str(ord(ch)) + '\n') fout.close() return self.put_abs(self.cur_r, self.cur_c, ch) @@ -292,10 +328,10 @@ class ANSI (term): if old_c == self.cur_c: self.cursor_down() if old_r != self.cur_r: - self.cursor_home (self.cur_r, 1) + self.cursor_home(self.cur_r, 1) else: - self.scroll_up () - self.cursor_home (self.cur_r, 1) + self.scroll_up() + self.cursor_home(self.cur_r, 1) self.erase_line() # def test (self): @@ -329,6 +365,6 @@ class ANSI (term): # self.write_ch (c) # print str(self) # -#if __name__ == '__main__': +# if __name__ == '__main__': # t = ANSI(6,65) # t.test() |