comit
tfw you have an issue only 1 person ever had thats what happende while i was trying to commit
This commit is contained in:
parent
fbfa0257a7
commit
3a08831141
4 changed files with 36 additions and 17 deletions
|
@ -1,6 +1,6 @@
|
|||
### Generating a file
|
||||
|
||||
1. `head -c 8 </dev/zero >myfile`
|
||||
1. `head -c 32 </dev/zero >myfile`
|
||||
2. `head -c 16M </dev/random >>myfile`
|
||||
|
||||
You can repeat the second command to grow the file
|
||||
|
|
1
file.txt
Normal file
1
file.txt
Normal file
|
@ -0,0 +1 @@
|
|||
hello world
|
|
@ -4,6 +4,7 @@ from termios import tcgetattr, tcsetattr, TCSADRAIN
|
|||
from tty import setcbreak
|
||||
from fcntl import fcntl, F_GETFL, F_SETFL
|
||||
|
||||
from notepad import Shard
|
||||
from keys import *
|
||||
|
||||
def wrapper(f: callable, *args: any):
|
||||
|
@ -19,7 +20,6 @@ def wrapper(f: callable, *args: any):
|
|||
except KeyboardInterrupt:
|
||||
cprint('2J')
|
||||
move(0, 0)
|
||||
pass
|
||||
finally:
|
||||
fcntl(fd, F_SETFL, old_fl)
|
||||
tcsetattr(fd, TCSADRAIN, old_tc)
|
||||
|
@ -76,7 +76,7 @@ def nl(y: int, x: int) -> tuple[int]:
|
|||
return (y + 1, 0)
|
||||
|
||||
|
||||
def move_back(y: int, x: int, line_pos: int, cur_line: int, lines: list[str], ncols: int) -> tuple[int]:
|
||||
def move_back(y: int, x: int, line_pos: int, cur_line: int, lines: list[str], ncols: int) -> tuple[int] | None:
|
||||
if x != 0:
|
||||
line_pos -= 1
|
||||
x -= 1
|
||||
|
@ -87,7 +87,7 @@ def move_back(y: int, x: int, line_pos: int, cur_line: int, lines: list[str], nc
|
|||
x = line_pos % ncols
|
||||
y -= 1
|
||||
else:
|
||||
rprint(KEY_BELL)
|
||||
return None
|
||||
|
||||
return (y, x, line_pos, cur_line)
|
||||
|
||||
|
@ -112,13 +112,12 @@ def move_forward(y: int, x: int, line_pos: int, cur_line: int, lines: list[str],
|
|||
return (y, x, line_pos, cur_line)
|
||||
|
||||
|
||||
def main():
|
||||
def main(lines: list[str]):
|
||||
terminal_size = None
|
||||
|
||||
y = 0
|
||||
x = 0
|
||||
|
||||
lines = ['']
|
||||
cur_line = 0
|
||||
line_pos = 0
|
||||
|
||||
|
@ -160,11 +159,15 @@ def main():
|
|||
line_pos = len(lines[cur_line])
|
||||
x = line_pos % terminal_size.columns
|
||||
y -= 1"""
|
||||
y, x, line_pos, cur_line = move_back(y, x, line_pos, cur_line, lines, terminal_size.columns)
|
||||
move(y, x)
|
||||
rprint(' ')
|
||||
move(y, x)
|
||||
lines[cur_line] = remove_str(lines[cur_line], line_pos)
|
||||
mv = move_back(y, x, line_pos, cur_line, lines, terminal_size.columns)
|
||||
if mv is None:
|
||||
rprint(KEY_BELL)
|
||||
else:
|
||||
y, x, line_pos, cur_line = mv
|
||||
move(y, x)
|
||||
rprint(' ')
|
||||
move(y, x)
|
||||
lines[cur_line] = remove_str(lines[cur_line], line_pos)
|
||||
elif key == KEY_ENTER:
|
||||
y, x = nl(y, x)
|
||||
|
||||
|
@ -173,21 +176,36 @@ def main():
|
|||
if len(lines) == cur_line:
|
||||
lines.append('')
|
||||
elif 31 < ord(key) < 127: # keystroke
|
||||
lines[cur_line] = insert_str(lines[cur_line], key, line_pos)
|
||||
line_pos += 1
|
||||
x += 1
|
||||
|
||||
if x - 1 == terminal_size.columns:
|
||||
y, x = nl(y, x)
|
||||
|
||||
rprint(key)
|
||||
lines[cur_line] = insert_str(lines[cur_line], key, line_pos)
|
||||
#rprint(key)
|
||||
|
||||
y, x = refresh(line_pos, cur_line, lines, terminal_size.columns) # TODO make this not needed
|
||||
|
||||
if __name__ == "__main__":
|
||||
wrapper(main)
|
||||
exists = True
|
||||
|
||||
try:
|
||||
lines = open('file.txt', 'r').read().split('\n')
|
||||
except FileNotFoundError:
|
||||
lines = ['close this and create file.txt to save this']
|
||||
exists = False
|
||||
|
||||
wrapper(main, lines)
|
||||
|
||||
if exists:
|
||||
with open('file.txt', 'w') as file:
|
||||
file.writelines(lines)
|
||||
|
||||
|
||||
"""OLD CODE
|
||||
|
||||
|
||||
exit()
|
||||
|
||||
def main(screen: curses.window):
|
||||
curses.use_default_colors()
|
||||
|
@ -305,4 +323,4 @@ try:
|
|||
except EOFError:
|
||||
print("oops, looks like the file wont fit this")
|
||||
|
||||
shard.close()
|
||||
shard.close()"""
|
|
@ -5,7 +5,7 @@ from time import time
|
|||
|
||||
@dataclass
|
||||
class Shard:
|
||||
size: int
|
||||
size: int # total size, excluding this 8 byte var and last entry
|
||||
file: BufferedRandom
|
||||
file_size: int
|
||||
|
Loading…
Reference in a new issue