Skip to content

Commit

Permalink
Fixed non-supported remove() call in unix micropython
Browse files Browse the repository at this point in the history
  • Loading branch information
robert-hh committed Dec 2, 2015
1 parent 29fb9e0 commit 6514950
Show file tree
Hide file tree
Showing 5 changed files with 20 additions and 19 deletions.
5 changes: 3 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
6 changes: 3 additions & 3 deletions pe.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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 = ' '
Expand Down
6 changes: 3 additions & 3 deletions pemin.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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 = ' '
Expand Down
8 changes: 4 additions & 4 deletions pye.py
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
14 changes: 7 additions & 7 deletions pye2.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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:
Expand All @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit 6514950

Please sign in to comment.