Skip to content

Commit 515c8de

Browse files
committed
Small fix in cursor left;last single file version
1 parent ed312da commit 515c8de

File tree

10 files changed

+345
-265
lines changed

10 files changed

+345
-265
lines changed

Pyboard Editor.doc

512 Bytes
Binary file not shown.

Pyboard Editor.pdf

186 Bytes
Binary file not shown.

README.md

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -121,7 +121,7 @@ c) expandtabs() and packtabs() with a second argument for tabsize (not for pye,
121121
- Lazy screen update: defer screen update, until all chars from the keyboard are processed. Not provided for WiPY, even if needed there most. WiPy has no way to tell if more chars are waiting in the input or at least a read with timeout.
122122

123123
**1.12** Bracket Match and Minor changes
124-
- Ctrl-K causes the cursor set to the matching bracket, if any. Pretty raw, not elegant.
124+
- Ctrl-K causes the cursor set to the matching bracket, if any. Pretty raw, not elegant.
125125
Brackets in comments and strings are counting as well.
126126
- On Copy the mark will be cleared, since it is assumed that the just copied lines will not be overwritten.
127127
- High level try/except catching internal errors (mostly coding errors)
@@ -133,6 +133,13 @@ Brackets in comments and strings are counting as well.
133133
- Squeezing a few lines out of the source code
134134

135135
**1.12c** Speed up pasting again
136-
- Speeded up pasting again. Slowing down pasting was caused by a in-function import statement.
137-
- Squeezing another few lines out of the source code by combining two functions, which were anyhow called one after the other, resulting in a enourmous long function handling the keyboard input.
136+
- Speed up pasting again. Slowing down pasting was caused by a in-function import statement in V1.11.
137+
- Squeezing another few lines out of the source code by combining two functions, which were
138+
anyhow called one after the other, resulting in a enormous long function handling the keyboard input.
139+
140+
**1.12d** Split undo of Indent/Un-Indent
141+
- Split undo for Indent and Un-Indent
142+
- Fixed a minor inconvenience when going left at the line start (sqeezed too much in v1.12b)
143+
- Move a few lines around, such that keys which are more probable for fast repeats are checked for earlier.
144+
- Some editorial changes
138145

pe.py

Lines changed: 47 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ class Editor:
1616
b"\x03" : 0x11,
1717
b"\r" : 0x0a,
1818
b"\x7f" : 0x08,
19-
b"\x1b[3~": 0xfffc,
19+
b"\x1b[3~": 0x7f,
2020
b"\x1b[Z" : 0x15,
2121
b"\x11" : 0x11,
2222
b"\n" : 0x0a,
@@ -42,22 +42,26 @@ class Editor:
4242
b"\x1b[1;5H": 0x14,
4343
b"\x1b[1;5F": 0x02,
4444
b"\x1b[3;5~": 0x18,
45-
b"\x0b" : 0xfffe,
45+
b"\x0b" : 0xfffd,
4646
}
47+
yank_buffer = []
48+
find_pattern = ""
49+
replc_pattern = ""
50+
height = 24
51+
width = 80
52+
scrbuf = []
4753
def __init__(self, tab_size, undo_limit):
4854
self.top_line = self.cur_line = self.row = self.col = self.margin = 0
4955
self.tab_size = tab_size
5056
self.changed = " "
51-
self.message = self.find_pattern = self.fname = ""
57+
self.message = self.fname = ""
5258
self.content = [""]
5359
self.undo = []
5460
self.undo_limit = max(undo_limit, 0)
5561
self.undo_zero = 0
5662
self.case = "n"
5763
self.autoindent = "y"
58-
self.yank_buffer = []
5964
self.mark = None
60-
self.replc_pattern = ""
6165
self.write_tabs = "n"
6266
if sys.platform == "pyboard":
6367
def wr(self,s):
@@ -211,7 +215,7 @@ def line_edit(self, prompt, default):
211215
if (len(res) > 0):
212216
res = res[:len(res)-1]
213217
self.wr('\b \b')
214-
elif key == 0xfffc:
218+
elif key == 0x7f:
215219
self.wr('\b \b' * len(res))
216220
res = ''
217221
elif 0x20 <= key < 0xfff0:
@@ -271,7 +275,7 @@ def handle_edit_keys(self, key):
271275
elif key == 0x1f:
272276
if self.col == 0 and self.cur_line > 0:
273277
self.cur_line -= 1
274-
self.col = len(l)
278+
self.col = len(self.content[self.cur_line])
275279
if self.cur_line < self.top_line:
276280
self.scroll_up(1)
277281
else:
@@ -284,6 +288,29 @@ def handle_edit_keys(self, key):
284288
self.scroll_down(1)
285289
else:
286290
self.col += 1
291+
elif key == 0x7f:
292+
if self.mark != None:
293+
self.delete_lines(False)
294+
elif self.col < len(l):
295+
self.undo_add(self.cur_line, [l], 0x7f)
296+
self.content[self.cur_line] = l[:self.col] + l[self.col + 1:]
297+
elif (self.cur_line + 1) < self.total_lines:
298+
self.undo_add(self.cur_line, [l, self.content[self.cur_line + 1]], 0)
299+
self.content[self.cur_line] = l + self.content.pop(self.cur_line + 1)
300+
self.total_lines -= 1
301+
elif key == 0x08:
302+
if self.mark != None:
303+
self.delete_lines(False)
304+
elif self.col > 0:
305+
self.undo_add(self.cur_line, [l], 0x08)
306+
self.content[self.cur_line] = l[:self.col - 1] + l[self.col:]
307+
self.col -= 1
308+
elif self.cur_line > 0:
309+
self.undo_add(self.cur_line - 1, [self.content[self.cur_line - 1], l], 0)
310+
self.col = len(self.content[self.cur_line - 1])
311+
self.content[self.cur_line - 1] += self.content.pop(self.cur_line)
312+
self.cur_line -= 1
313+
self.total_lines -= 1
287314
elif 0x20 <= key < 0xfff0:
288315
self.mark = None
289316
self.undo_add(self.cur_line, [l], 0x20 if key == 0x20 else 0x41)
@@ -344,7 +371,7 @@ def handle_edit_keys(self, key):
344371
elif key == 0x02:
345372
self.cur_line = self.total_lines - 1
346373
self.row = self.height - 1
347-
elif key == 0xfffe:
374+
elif key == 0xfffd:
348375
if self.col < len(l):
349376
opening = "([{<"
350377
closing = ")]}>"
@@ -385,29 +412,6 @@ def handle_edit_keys(self, key):
385412
pos = len(self.content[i - 1]) - 1
386413
elif key == 0x0c:
387414
self.mark = self.cur_line if self.mark == None else None
388-
elif key == 0xfffc:
389-
if self.mark != None:
390-
self.delete_lines(False)
391-
elif self.col < len(l):
392-
self.undo_add(self.cur_line, [l], 0xfffc)
393-
self.content[self.cur_line] = l[:self.col] + l[self.col + 1:]
394-
elif (self.cur_line + 1) < self.total_lines:
395-
self.undo_add(self.cur_line, [l, self.content[self.cur_line + 1]], 0)
396-
self.content[self.cur_line] = l + self.content.pop(self.cur_line + 1)
397-
self.total_lines -= 1
398-
elif key == 0x08:
399-
if self.mark != None:
400-
self.delete_lines(False)
401-
elif self.col > 0:
402-
self.undo_add(self.cur_line, [l], 0x08)
403-
self.content[self.cur_line] = l[:self.col - 1] + l[self.col:]
404-
self.col -= 1
405-
elif self.cur_line > 0:
406-
self.undo_add(self.cur_line - 1, [self.content[self.cur_line - 1], l], 0)
407-
self.col = len(self.content[self.cur_line - 1])
408-
self.content[self.cur_line - 1] += self.content.pop(self.cur_line)
409-
self.cur_line -= 1
410-
self.total_lines -= 1
411415
elif key == 0x0a:
412416
self.mark = None
413417
self.undo_add(self.cur_line, [l], 0, 2)
@@ -425,7 +429,7 @@ def handle_edit_keys(self, key):
425429
elif key == 0x09:
426430
if self.mark != None:
427431
lrange = self.line_range()
428-
self.undo_add(lrange[0], self.content[lrange[0]:lrange[1]], 0xffff, lrange[1] - lrange[0])
432+
self.undo_add(lrange[0], self.content[lrange[0]:lrange[1]], 0xfffe, lrange[1] - lrange[0])
429433
for i in range(lrange[0],lrange[1]):
430434
if len(self.content[i]) > 0:
431435
self.content[i] = ' ' * (self.tab_size - self.spaces(self.content[i]) % self.tab_size) + self.content[i]
@@ -489,7 +493,11 @@ def handle_edit_keys(self, key):
489493
(content, self.message) = self.get_file(fname)
490494
if content:
491495
self.undo_add(self.cur_line, None, 0, -len(content))
492-
self.content[self.cur_line:self.cur_line] = content
496+
if self.content == [""]:
497+
self.content = content
498+
if not self.fname: self.fname = fname
499+
else:
500+
self.content[self.cur_line:self.cur_line] = content
493501
self.total_lines = len(self.content)
494502
elif key == 0x18:
495503
if self.mark != None:
@@ -523,7 +531,7 @@ def handle_edit_keys(self, key):
523531
elif key == 0x1a:
524532
if len(self.undo) > 0:
525533
action = self.undo.pop(-1)
526-
if action[3] != 0xffff:
534+
if action[3] != 0xfffe:
527535
self.cur_line = action[0]
528536
self.col = action[4]
529537
if action[1] >= 0:
@@ -533,6 +541,8 @@ def handle_edit_keys(self, key):
533541
self.content += action[2]
534542
else:
535543
del self.content[action[0]:action[0] - action[1]]
544+
if self.content == []:
545+
self.content = [""]
536546
self.total_lines = len(self.content)
537547
self.changed = ' ' if len(self.undo) == self.undo_zero else '*'
538548
self.mark = None
@@ -590,16 +600,16 @@ def get_file(self, fname):
590600
content[i] = expandtabs(content[i].rstrip('\r\n\t '))
591601
return (content, "")
592602
def put_file(self, fname, start, stop):
593-
from os import rename, unlink
603+
import os
594604
with open("tmpfile.pye", "w") as f:
595605
for l in self.content[start:stop]:
596606
if self.write_tabs == 'y':
597607
f.write(self.packtabs(l) + '\n')
598608
else:
599609
f.write(l + '\n')
600-
try: unlink(fname)
610+
try: os.unlink(fname)
601611
except: pass
602-
rename("tmpfile.pye", fname)
612+
os.rename("tmpfile.pye", fname)
603613
def expandtabs(s):
604614
from _io import StringIO
605615
if '\t' in s:

0 commit comments

Comments
 (0)