From d7d97c9f6ece8d00f3e4fc0904d5ae840d96d03f Mon Sep 17 00:00:00 2001 From: seem Date: Fri, 25 Dec 2020 16:50:57 +0200 Subject: [PATCH] Basic window to trim buffer --- editor.py | 19 ++++++++++++++++++- 1 file changed, 18 insertions(+), 1 deletion(-) diff --git a/editor.py b/editor.py index 3df6bc4..42f7da8 100644 --- a/editor.py +++ b/editor.py @@ -1,6 +1,21 @@ import argparse import curses import sys +from dataclasses import dataclass + + +@dataclass +class Window: + n_lines: int + n_cols: int + line: int = 0 + col: int = 0 + + def trim(self, buffer): + return [ + string[self.col : self.col + self.n_cols] + for string in buffer[self.line : self.line + self.n_lines] + ] def main(stdscr): @@ -11,9 +26,11 @@ def main(stdscr): with open(args.filename) as f: buffer = f.readlines() + window = Window(curses.LINES - 1, curses.COLS - 1) + while True: stdscr.erase() - for line, string in enumerate(buffer): + for line, string in enumerate(window.trim(buffer)): stdscr.addstr(line, 0, string) k = stdscr.getkey()