From 698f796a484aa7bf9a3e3f4ac5950817af542e1d Mon Sep 17 00:00:00 2001 From: Robert HH Date: Sun, 1 Nov 2015 18:54:40 +0100 Subject: [PATCH] Shortened KEYMAP to savev space for WiPy; Tabbify by Tab/Backtab on col 1 (full version) --- pe.py | 49 ++++++++++++++++++++++++++++----------------- pemin.py | 51 ++++++++++++++-------------------------------- pye.py | 61 ++++++++++++++++++++++++++++++++++++-------------------- wipye.py | 51 ++++++++++++++-------------------------------- 4 files changed, 100 insertions(+), 112 deletions(-) diff --git a/pe.py b/pe.py index eb51ea9..612eff7 100644 --- a/pe.py +++ b/pe.py @@ -14,12 +14,14 @@ class Editor: b"\x1b[5~": 0x17, b"\x1b[6~": 0x19, b"\x11" : 0x03, - b"\x03" : 0x03, b"\r" : 0x0a, - b"\n" : 0x0a, b"\x7f" : 0x08, - b"\x08" : 0x08, b"\x1b[3~": 0x1f, + b"\x1b[Z" : 0x15, + b"\x1b[3;5~": 0x18, + b"\x03" : 0x03, + b"\n" : 0x0a, + b"\x08" : 0x08, b"\x13" : 0x13, b"\x06" : 0x06, b"\x0e" : 0x0e, @@ -28,12 +30,10 @@ class Editor: b"\x1a" : 0x1a, b"\x09" : 0x09, b"\x15" : 0x15, - b"\x1b[Z" : 0x15, + b"\x12" : 0x12, b"\x18" : 0x18, - b"\x1b[3;5~": 0x18, b"\x16" : 0x16, b"\x04" : 0x04, - b"\x12" : 0x12, b"\x1b[M" : 0x1b, b"\x01" : 0x01, b"\x14" : 0x02, @@ -57,10 +57,10 @@ def __init__(self, tab_size, undo_limit): self.content = [""] self.undo = [] self.undo_limit = max(undo_limit, 0) - self.yank_buffer = [] - self.lastkey = 0 self.case = "n" self.autoindent = "y" + self.yank_buffer = [] + self.lastkey = 0 self.replc_pattern = "" self.write_tabs = "n" if sys.platform == "pyboard": @@ -164,7 +164,7 @@ def get_input(self): return 0x1c else: return 0x1b - elif input[0] >= 0x20: + elif len(input) == 1: return input[0] def display_window(self): self.cur_line = min(self.total_lines - 1, max(self.cur_line, 0)) @@ -280,8 +280,7 @@ def handle_cursor_keys(self, key): self.cursor_down() self.col = 0 elif key == 0x10: - ns = self.spaces(self.content[self.cur_line]) - self.col = ns if self.col != ns else 0 + self.col = self.spaces(self.content[self.cur_line]) if self.col == 0 else 0 elif key == 0x11: self.col = len(self.content[self.cur_line]) elif key == 0x17: @@ -356,7 +355,7 @@ def handle_edit_key(self, key): ni = 0 if self.autoindent == "y": ni = min(self.spaces(l), self.col) - r = self.content[self.cur_line].partition("\x23")[0].rstrip() + r = l.partition("\x23")[0].rstrip() if r and r[-1] == ':' and self.col >= len(r): ni += self.tab_size self.cur_line += 1 @@ -390,15 +389,29 @@ def handle_edit_key(self, key): self.changed = '*' elif key == 0x09: self.undo_add(self.cur_line, [l], key) - ni = self.tab_size - self.col % self.tab_size - self.content[self.cur_line] = l[:self.col] + ' ' * ni + l[self.col:] - self.col += ni + if False: pass + else: + ns = self.spaces(l) + if self.col == 0 and self.col != ns: + self.content[self.cur_line] = ' ' * (self.tab_size - ns % self.tab_size) + l + self.cursor_down() + else: + ni = self.tab_size - self.col % self.tab_size + self.content[self.cur_line] = l[:self.col] + ' ' * ni + l[self.col:] + self.col += ni self.changed = '*' elif key == 0x15: self.undo_add(self.cur_line, [l], key) - ni = min((self.col - 1) % self.tab_size + 1, self.spaces(l, self.col)) - self.content[self.cur_line] = l[:self.col - ni] + l[self.col:] - self.col -= ni + if False: pass + else: + ns = self.spaces(l) + if self.col == 0 and ns > 0: + self.content[self.cur_line] = l[(ns - 1) % self.tab_size + 1:] + self.cursor_down() + else: + ni = min((self.col - 1) % self.tab_size + 1, self.spaces(l, self.col)) + self.content[self.cur_line] = l[:self.col - ni] + l[self.col:] + self.col -= ni self.changed = '*' elif key == 0x12: count = 0 diff --git a/pemin.py b/pemin.py index e574c14..e2a867d 100644 --- a/pemin.py +++ b/pemin.py @@ -14,33 +14,11 @@ class Editor: b"\x1b[5~": 0x17, b"\x1b[6~": 0x19, b"\x11" : 0x03, - b"\x03" : 0x03, b"\r" : 0x0a, - b"\n" : 0x0a, b"\x7f" : 0x08, - b"\x08" : 0x08, b"\x1b[3~": 0x1f, - b"\x13" : 0x13, - b"\x06" : 0x06, - b"\x0e" : 0x0e, - b"\x07" : 0x07, - b"\x05" : 0x05, - b"\x1a" : 0x1a, - b"\x09" : 0x09, - b"\x15" : 0x15, b"\x1b[Z" : 0x15, - b"\x18" : 0x18, b"\x1b[3;5~": 0x18, - b"\x16" : 0x16, - b"\x04" : 0x04, - b"\x12" : 0x12, - b"\x1b[M" : 0x1b, - b"\x01" : 0x01, - b"\x14" : 0x02, - b"\x02" : 0x14, - b"\x1b[1;5H": 0x02, - b"\x1b[1;5F": 0x14, - b"\x0f" : 0x1e, } def __init__(self, tab_size, undo_limit): self.top_line = 0 @@ -57,10 +35,10 @@ def __init__(self, tab_size, undo_limit): self.content = [""] self.undo = [] self.undo_limit = max(undo_limit, 0) - self.yank_buffer = [] - self.lastkey = 0 self.case = "n" self.autoindent = "y" + self.yank_buffer = [] + self.lastkey = 0 if sys.platform == "pyboard": @staticmethod def wr(s): @@ -146,7 +124,7 @@ def get_input(self): c = self.KEYMAP[input] if c != 0x1b: return c - elif input[0] >= 0x20: + elif len(input) == 1: return input[0] def display_window(self): self.cur_line = min(self.total_lines - 1, max(self.cur_line, 0)) @@ -260,8 +238,7 @@ def handle_cursor_keys(self, key): self.cursor_down() self.col = 0 elif key == 0x10: - ns = self.spaces(self.content[self.cur_line]) - self.col = ns if self.col != ns else 0 + self.col = self.spaces(self.content[self.cur_line]) if self.col == 0 else 0 elif key == 0x11: self.col = len(self.content[self.cur_line]) elif key == 0x17: @@ -303,7 +280,7 @@ def handle_edit_key(self, key): ni = 0 if self.autoindent == "y": ni = min(self.spaces(l), self.col) - r = self.content[self.cur_line].partition("\x23")[0].rstrip() + r = l.partition("\x23")[0].rstrip() if r and r[-1] == ':' and self.col >= len(r): ni += self.tab_size self.cur_line += 1 @@ -330,15 +307,19 @@ def handle_edit_key(self, key): self.changed = '*' elif key == 0x09: self.undo_add(self.cur_line, [l], key) - ni = self.tab_size - self.col % self.tab_size - self.content[self.cur_line] = l[:self.col] + ' ' * ni + l[self.col:] - self.col += ni + if False: pass + else: + ni = self.tab_size - self.col % self.tab_size + self.content[self.cur_line] = l[:self.col] + ' ' * ni + l[self.col:] + self.col += ni self.changed = '*' elif key == 0x15: self.undo_add(self.cur_line, [l], key) - ni = min((self.col - 1) % self.tab_size + 1, self.spaces(l, self.col)) - self.content[self.cur_line] = l[:self.col - ni] + l[self.col:] - self.col -= ni + if False: pass + else: + ni = min((self.col - 1) % self.tab_size + 1, self.spaces(l, self.col)) + self.content[self.cur_line] = l[:self.col - ni] + l[self.col:] + self.col -= ni self.changed = '*' elif key == 0x18: self.undo_add(self.cur_line, [l], 0, 0) @@ -397,8 +378,6 @@ def handle_edit_key(self, key): self.total_lines = len(self.content) if len(self.undo) == 0: self.changed = self.sticky_c - elif key < 0x20: - self.message = "Sorry, command not supported" elif key >= 0x20: self.undo_add(self.cur_line, [l], 0x20 if key == 0x20 else 0x41) self.content[self.cur_line] = l[:self.col] + chr(key) + l[self.col:] diff --git a/pye.py b/pye.py index aea1035..7c9b840 100644 --- a/pye.py +++ b/pye.py @@ -104,12 +104,16 @@ class Editor: b"\x1b[5~": KEY_PGUP, b"\x1b[6~": KEY_PGDN, b"\x11" : KEY_QUIT, ## Ctrl-Q - b"\x03" : KEY_QUIT, ## Ctrl-C b"\r" : KEY_ENTER, - b"\n" : KEY_ENTER, b"\x7f" : KEY_BACKSPACE, ## Ctrl-? (127) - b"\x08" : KEY_BACKSPACE, b"\x1b[3~": KEY_DELETE, + b"\x1b[Z" : KEY_BACKTAB, ## Shift Tab + b"\x1b[3;5~": KEY_YANK, ## Ctrl-Del +#ifndef BASIC +## keys mapped onto themselves + b"\x03" : KEY_QUIT, ## Ctrl-C + b"\n" : KEY_ENTER, + b"\x08" : KEY_BACKSPACE, b"\x13" : KEY_WRITE, ## Ctrl-S b"\x06" : KEY_FIND, ## Ctrl-F b"\x0e" : KEY_FIND_AGAIN, ## Ctrl-N @@ -118,12 +122,11 @@ class Editor: b"\x1a" : KEY_UNDO, ## Ctrl-Z b"\x09" : KEY_TAB, b"\x15" : KEY_BACKTAB, ## Ctrl-U - b"\x1b[Z" : KEY_BACKTAB, ## Shift Tab + b"\x12" : KEY_REPLC, ## Ctrl-R b"\x18" : KEY_YANK, ## Ctrl-X - b"\x1b[3;5~": KEY_YANK, ## Ctrl-Del b"\x16" : KEY_ZAP, ## Ctrl-V b"\x04" : KEY_DUP, ## Ctrl-D - b"\x12" : KEY_REPLC, ## Ctrl-R +## b"\x1b[M" : KEY_MOUSE, b"\x01" : KEY_TOGGLE, ## Ctrl-A b"\x14" : KEY_FIRST, ## Ctrl-T @@ -131,6 +134,7 @@ class Editor: b"\x1b[1;5H": KEY_FIRST, b"\x1b[1;5F": KEY_LAST, b"\x0f" : KEY_GET, ## Ctrl-O +#endif } def __init__(self, tab_size, undo_limit): @@ -148,10 +152,10 @@ def __init__(self, tab_size, undo_limit): self.content = [""] self.undo = [] self.undo_limit = max(undo_limit, 0) - self.yank_buffer = [] - self.lastkey = 0 self.case = "n" self.autoindent = "y" + self.yank_buffer = [] + self.lastkey = 0 #ifndef BASIC self.replc_pattern = "" self.write_tabs = "n" @@ -348,7 +352,7 @@ def get_input(self): ## read from interface/keyboard one byte each and match ag else: return KEY_MOUSE ## do nothing but set the cursor #endif - elif input[0] >= 0x20: ## but only if no Ctrl-Char + elif len(input) == 1: ## but only if a single char return input[0] def display_window(self): ## Update window and status line @@ -478,8 +482,7 @@ def handle_cursor_keys(self, key): ## keys which move, sanity checks later self.cursor_down() self.col = 0 elif key == KEY_HOME: - ns = self.spaces(self.content[self.cur_line]) - self.col = ns if self.col != ns else 0 + self.col = self.spaces(self.content[self.cur_line]) if self.col == 0 else 0 elif key == KEY_END: self.col = len(self.content[self.cur_line]) elif key == KEY_PGUP: @@ -558,7 +561,7 @@ def handle_edit_key(self, key): ## keys which change content ni = 0 if self.autoindent == "y": ## Autoindent ni = min(self.spaces(l), self.col) ## query indentation - r = self.content[self.cur_line].partition("\x23")[0].rstrip() ## \x23 == # + r = l.partition("\x23")[0].rstrip() ## \x23 == # if r and r[-1] == ':' and self.col >= len(r): ## look for : as the last non-space before comment ni += self.tab_size self.cur_line += 1 @@ -594,15 +597,33 @@ def handle_edit_key(self, key): ## keys which change content self.changed = '*' elif key == KEY_TAB: self.undo_add(self.cur_line, [l], key) - ni = self.tab_size - self.col % self.tab_size ## determine spaces to add - self.content[self.cur_line] = l[:self.col] + ' ' * ni + l[self.col:] - self.col += ni + if False: pass +#ifndef BASIC + else: + ns = self.spaces(l) + if self.col == 0 and self.col != ns: + self.content[self.cur_line] = ' ' * (self.tab_size - ns % self.tab_size) + l + self.cursor_down() +#endif + else: + ni = self.tab_size - self.col % self.tab_size ## determine spaces to add + self.content[self.cur_line] = l[:self.col] + ' ' * ni + l[self.col:] + self.col += ni self.changed = '*' elif key == KEY_BACKTAB: self.undo_add(self.cur_line, [l], key) - ni = min((self.col - 1) % self.tab_size + 1, self.spaces(l, self.col)) ## determine spaces to drop - self.content[self.cur_line] = l[:self.col - ni] + l[self.col:] - self.col -= ni + if False: pass +#ifndef BASIC + else: + ns = self.spaces(l) + if self.col == 0 and ns > 0: + self.content[self.cur_line] = l[(ns - 1) % self.tab_size + 1:] + self.cursor_down() +#endif + else: + ni = min((self.col - 1) % self.tab_size + 1, self.spaces(l, self.col)) ## determine spaces to drop + self.content[self.cur_line] = l[:self.col - ni] + l[self.col:] + self.col -= ni self.changed = '*' #ifndef BASIC elif key == KEY_REPLC: @@ -706,10 +727,6 @@ def handle_edit_key(self, key): ## keys which change content self.total_lines = len(self.content) ## brute force if len(self.undo) == 0: ## test changed flag self.changed = self.sticky_c -#ifdef BASIC - elif key < 0x20: - self.message = "Sorry, command not supported" -#endif elif key >= 0x20: ## character to be added self.undo_add(self.cur_line, [l], 0x20 if key == 0x20 else 0x41) self.content[self.cur_line] = l[:self.col] + chr(key) + l[self.col:] diff --git a/wipye.py b/wipye.py index 6323e39..efbfed2 100644 --- a/wipye.py +++ b/wipye.py @@ -14,33 +14,11 @@ class Editor: b"\x1b[5~": 0x17, b"\x1b[6~": 0x19, b"\x11" : 0x03, - b"\x03" : 0x03, b"\r" : 0x0a, - b"\n" : 0x0a, b"\x7f" : 0x08, - b"\x08" : 0x08, b"\x1b[3~": 0x1f, - b"\x13" : 0x13, - b"\x06" : 0x06, - b"\x0e" : 0x0e, - b"\x07" : 0x07, - b"\x05" : 0x05, - b"\x1a" : 0x1a, - b"\x09" : 0x09, - b"\x15" : 0x15, b"\x1b[Z" : 0x15, - b"\x18" : 0x18, b"\x1b[3;5~": 0x18, - b"\x16" : 0x16, - b"\x04" : 0x04, - b"\x12" : 0x12, - b"\x1b[M" : 0x1b, - b"\x01" : 0x01, - b"\x14" : 0x02, - b"\x02" : 0x14, - b"\x1b[1;5H": 0x02, - b"\x1b[1;5F": 0x14, - b"\x0f" : 0x1e, } def __init__(self, tab_size, undo_limit): self.top_line = 0 @@ -57,10 +35,10 @@ def __init__(self, tab_size, undo_limit): self.content = [""] self.undo = [] self.undo_limit = max(undo_limit, 0) - self.yank_buffer = [] - self.lastkey = 0 self.case = "n" self.autoindent = "y" + self.yank_buffer = [] + self.lastkey = 0 if sys.platform == "WiPy": @staticmethod def wr(s): @@ -152,7 +130,7 @@ def get_input(self): c = self.KEYMAP[input] if c != 0x1b: return c - elif input[0] >= 0x20: + elif len(input) == 1: return input[0] def display_window(self): self.cur_line = min(self.total_lines - 1, max(self.cur_line, 0)) @@ -266,8 +244,7 @@ def handle_cursor_keys(self, key): self.cursor_down() self.col = 0 elif key == 0x10: - ns = self.spaces(self.content[self.cur_line]) - self.col = ns if self.col != ns else 0 + self.col = self.spaces(self.content[self.cur_line]) if self.col == 0 else 0 elif key == 0x11: self.col = len(self.content[self.cur_line]) elif key == 0x17: @@ -309,7 +286,7 @@ def handle_edit_key(self, key): ni = 0 if self.autoindent == "y": ni = min(self.spaces(l), self.col) - r = self.content[self.cur_line].partition("\x23")[0].rstrip() + r = l.partition("\x23")[0].rstrip() if r and r[-1] == ':' and self.col >= len(r): ni += self.tab_size self.cur_line += 1 @@ -336,15 +313,19 @@ def handle_edit_key(self, key): self.changed = '*' elif key == 0x09: self.undo_add(self.cur_line, [l], key) - ni = self.tab_size - self.col % self.tab_size - self.content[self.cur_line] = l[:self.col] + ' ' * ni + l[self.col:] - self.col += ni + if False: pass + else: + ni = self.tab_size - self.col % self.tab_size + self.content[self.cur_line] = l[:self.col] + ' ' * ni + l[self.col:] + self.col += ni self.changed = '*' elif key == 0x15: self.undo_add(self.cur_line, [l], key) - ni = min((self.col - 1) % self.tab_size + 1, self.spaces(l, self.col)) - self.content[self.cur_line] = l[:self.col - ni] + l[self.col:] - self.col -= ni + if False: pass + else: + ni = min((self.col - 1) % self.tab_size + 1, self.spaces(l, self.col)) + self.content[self.cur_line] = l[:self.col - ni] + l[self.col:] + self.col -= ni self.changed = '*' elif key == 0x18: self.undo_add(self.cur_line, [l], 0, 0) @@ -403,8 +384,6 @@ def handle_edit_key(self, key): self.total_lines = len(self.content) if len(self.undo) == 0: self.changed = self.sticky_c - elif key < 0x20: - self.message = "Sorry, command not supported" elif key >= 0x20: self.undo_add(self.cur_line, [l], 0x20 if key == 0x20 else 0x41) self.content[self.cur_line] = l[:self.col] + chr(key) + l[self.col:]