diff --git a/core/__pycache__/cursor.cpython-310.pyc b/core/__pycache__/cursor.cpython-310.pyc index e726a47..751bcf6 100644 Binary files a/core/__pycache__/cursor.cpython-310.pyc and b/core/__pycache__/cursor.cpython-310.pyc differ diff --git a/core/__pycache__/files.cpython-310.pyc b/core/__pycache__/files.cpython-310.pyc index b996193..b7fd14a 100644 Binary files a/core/__pycache__/files.cpython-310.pyc and b/core/__pycache__/files.cpython-310.pyc differ diff --git a/core/__pycache__/welcome.cpython-310.pyc b/core/__pycache__/welcome.cpython-310.pyc new file mode 100644 index 0000000..600f4df Binary files /dev/null and b/core/__pycache__/welcome.cpython-310.pyc differ diff --git a/core/cursor.py b/core/cursor.py index c0b6069..09dc967 100644 --- a/core/cursor.py +++ b/core/cursor.py @@ -13,6 +13,12 @@ def cursor_mode(mode): def check_cursor(data): + if data["cursor_y"] == len(data["buffer_list"]): + data["cursor_y"] -= 1 + + elif data["cursor_x"] > len(data["buffer_list"][data["cursor_y"]]): + data["cursor_x"] = len(data["buffer_list"][data["cursor_y"]]) + data["cursor_x"] = max(2, data["cursor_x"]) data["cursor_x"] = min(data["width"] - 1, data["cursor_x"]) data["cursor_y"] = max(0, data["cursor_y"]) diff --git a/core/welcome.py b/core/welcome.py new file mode 100644 index 0000000..e12ae98 --- /dev/null +++ b/core/welcome.py @@ -0,0 +1,29 @@ +import curses + + +def start_screen(stdscr): + # Get window height and width + height, width = stdscr.getmaxyx() + + # Startup text + title = "λ Lambda" + subtext = [ + "Next generation hackable text editor for nerds", + "", + "Type :h to open the README.md document", + "Type :o to open a file and edit", + "Type :q or to quit lambda.py" + ] + + # Centering calculations + start_x_title = int((width // 2) - (len(title) // 2) - len(title) % 2) + start_y = int((height // 2) - 2) + + # Rendering title + stdscr.addstr(start_y, start_x_title, title, curses.color_pair(7) | curses.A_BOLD) + + # Print the subtext + for text in subtext: + start_y += 1 + start_x = int((width // 2) - (len(text) // 2) - len(text) % 2) + stdscr.addstr(start_y, start_x, text) diff --git a/lambda.py b/lambda.py index e6a4a91..3e1f1ed 100755 --- a/lambda.py +++ b/lambda.py @@ -1,37 +1,9 @@ -from core import colors, cursor, mode, files, buffer +from core import colors, cursor, mode, files, buffer, welcome import os import curses import argparse -def start_screen(stdscr): - # Get window height and width - height, width = stdscr.getmaxyx() - - # Startup text - title = "λ Lambda" - subtext = [ - "Next generation hackable text editor for nerds", - "", - "Type :h to open the README.md document", - "Type :o to open a file and edit", - "Type :q or to quit lambda.py" - ] - - # Centering calculations - start_x_title = int((width // 2) - (len(title) // 2) - len(title) % 2) - start_y = int((height // 2) - 2) - - # Rendering title - stdscr.addstr(start_y, start_x_title, title, curses.color_pair(7) | curses.A_BOLD) - - # Print the subtext - for text in subtext: - start_y += 1 - start_x = int((width // 2) - (len(text) // 2) - len(text) % 2) - stdscr.addstr(start_y, start_x, text) - - def start(stdscr, buffer_name, buffer_list): # Initialise data before starting data = { @@ -55,7 +27,7 @@ def start(stdscr, buffer_name, buffer_list): # Start the screen if data["buffer_name"] == "[No Name]": - start_screen(stdscr) + welcome.start_screen(stdscr) # Main loop while True: @@ -74,33 +46,41 @@ def start(stdscr, buffer_name, buffer_list): def main(): + # Arguments parser = argparse.ArgumentParser(description="Next generation hackable text editor for nerds.") parser.add_argument("file", metavar="file", type=str, nargs="?", help="The name of a file for lambda to open") + # Collect the arguments args = parser.parse_args() - # Check if a file name has been inputted + + # Check if a file name has actually been inputted if args.file: - buffer_name = args.file + # Set the buffer name + buffer_name = os.path.basename(args.file) # Only if the file exists if os.path.exists(args.file): # Load the file into the buffer - buffer_list = files.open_file(buffer_name) + buffer_list = files.open_file(args.file) # Convert each line into a list of lists with each element of the sublist representing one character for index, line in enumerate(buffer_list): buffer_list[index] = list(line) else: + # New file being created, no content buffer_list = [[""]] else: + # Buffer has no name buffer_name = "[No Name]" + + # Buffer has no value buffer_list = [[""]] # Change the escape delay to 25ms - # Fixes an issue where esc takes too long to press + # Fixes an issue where esc takes way too long to press os.environ.setdefault("ESCDELAY", "25") # Initialise the screen