diff --git a/README.md b/README.md index c6319fe..71f400f 100644 --- a/README.md +++ b/README.md @@ -118,5 +118,6 @@ c) expandtabs() and packtabs() with a second argument for tabsize (not for pye, **1.11** Minor fixes - Change the way a marked area is highlighted from reverse to a different background color. That works well for black chars on yellow background (code 43). For white chars on black background, the setting for background color in the function hilite() has to be changed, e.g. to blue (code 44). -- Save to a temporary file first, and rename it to the target name when successfully written. - +- Save file to a temporary file first, and rename it to the target name when successfully written. +- Lazy screen update: defer screen update, until all chars from the keyboard are processed. +- Use os.unlink() instead of os.remove(), because remove is not suported by unix micropython diff --git a/pe.py b/pe.py index 1a1f6b9..4671a49 100644 --- a/pe.py +++ b/pe.py @@ -91,7 +91,7 @@ def cursor(self, onoff): self.wr(b"\x1b[?25h" if onoff else b"\x1b[?25l") def hilite(self, mode): if mode == 1: - self.wr(b"\x1b[1m") + self.wr(b"\x1b[1;47m") elif mode == 2: self.wr(b"\x1b[43m") else: @@ -345,7 +345,7 @@ def delete_lines(self, yank): self.cur_line = lrange[0] self.mark = None def handle_edit_key(self, key): - from os import rename, remove + from os import rename, unlink l = self.content[self.cur_line] if key == 0x0a: self.mark = None @@ -486,7 +486,7 @@ def handle_edit_key(self, key): f.write(self.packtabs(l) + '\n') else: f.write(l + '\n') - try: remove(fname) + try: unlink(fname) except: pass rename("tmpfile.pye", fname) self.changed = ' ' diff --git a/pemin.py b/pemin.py index 52da4ae..1bbd95d 100644 --- a/pemin.py +++ b/pemin.py @@ -65,7 +65,7 @@ def cursor(self, onoff): self.wr(b"\x1b[?25h" if onoff else b"\x1b[?25l") def hilite(self, mode): if mode == 1: - self.wr(b"\x1b[1m") + self.wr(b"\x1b[1;47m") elif mode == 2: self.wr(b"\x1b[43m") else: @@ -267,7 +267,7 @@ def delete_lines(self, yank): self.cur_line = lrange[0] self.mark = None def handle_edit_key(self, key): - from os import rename, remove + from os import rename, unlink l = self.content[self.cur_line] if key == 0x0a: self.mark = None @@ -352,7 +352,7 @@ def handle_edit_key(self, key): with open("tmpfile.pye", "w") as f: for l in self.content[lrange[0]:lrange[1]]: f.write(l + '\n') - try: remove(fname) + try: unlink(fname) except: pass rename("tmpfile.pye", fname) self.changed = ' ' diff --git a/pye.py b/pye.py index cec64c3..92f6cc6 100644 --- a/pye.py +++ b/pye.py @@ -165,7 +165,7 @@ def __init__(self, tab_size, undo_limit): #endif #ifdef LINUX if sys.platform in ("linux", "darwin"): - + def wr(self,s): if isinstance(s, str): s = bytes(s, "utf-8") @@ -266,7 +266,7 @@ def cursor(self, onoff): def hilite(self, mode): if mode == 1: ## used for the status line - self.wr(b"\x1b[1m") + self.wr(b"\x1b[1;47m") elif mode == 2: ## used for the marked area self.wr(b"\x1b[43m") else: ## plain text @@ -556,7 +556,7 @@ def delete_lines(self, yank): self.mark = None ## unset line mark def handle_edit_key(self, key): ## keys which change content - from os import rename, remove + from os import rename, unlink l = self.content[self.cur_line] if key == KEY_ENTER: self.mark = None @@ -707,7 +707,7 @@ def handle_edit_key(self, key): ## keys which change content else: #endif f.write(l + '\n') - try: remove(fname) + try: unlink(fname) except: pass rename("tmpfile.pye", fname) self.changed = ' ' ## clear change flag diff --git a/pye2.py b/pye2.py index 8fa6740..848139d 100644 --- a/pye2.py +++ b/pye2.py @@ -240,9 +240,9 @@ def wr(self, s): def rd(self): while True: - try: + try: return sys.stdin.read(1).encode() - except: + except: pass def not_pending(self): @@ -385,7 +385,7 @@ def line_range(self): ## if self.mark == None: ## return (self.cur_line, self.cur_line + 1) ## else: - return ((self.mark, self.cur_line + 1) if self.mark < self.cur_line else + return ((self.mark, self.cur_line + 1) if self.mark < self.cur_line else (self.cur_line, self.mark + 1)) def line_edit(self, prompt, default): ## simple one: only 4 fcts @@ -548,7 +548,7 @@ def delete_lines(self, yank): self.mark = None ## unset line mark def handle_edit_key(self, key): ## keys which change content - from os import rename, remove + from os import rename, unlink l = self.content[self.cur_line] jut = self.col - len(l) ## <0: before text end, =0 at text end, >0 beyond text end if key == KEY_ENTER: @@ -557,7 +557,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 -#ifndef BASIC +#ifndef BASIC 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 @@ -625,7 +625,7 @@ def handle_edit_key(self, key): ## keys which change content self.content[self.cur_line] = l[:self.col - ni] + l[self.col:] self.col -= ni else: - self.col -= min(ni, jut) + self.col -= min(ni, jut) #ifndef BASIC elif key == KEY_REPLC: count = 0 @@ -708,7 +708,7 @@ def handle_edit_key(self, key): ## keys which change content else: #endif f.write(l + '\n') - try: remove(fname) + try: unlink(fname) except: pass rename("tmpfile.pye", fname) self.changed = ' ' ## clear change flag