2022-03-17 18:46:04 +00:00
|
|
|
from core import colors, cursor, mode, files, buffer, welcome
|
2022-03-15 22:12:52 +00:00
|
|
|
import os
|
|
|
|
import curses
|
|
|
|
import argparse
|
|
|
|
|
|
|
|
|
|
|
|
def start(stdscr, buffer_name, buffer_list):
|
|
|
|
# Initialise data before starting
|
|
|
|
data = {
|
|
|
|
"cursor_y": 0,
|
|
|
|
"cursor_x": 0,
|
|
|
|
"height": 0,
|
|
|
|
"width": 0,
|
|
|
|
"mode": "normal",
|
|
|
|
"icon": "λ",
|
|
|
|
"info_bar": [" "],
|
|
|
|
"buffer_name": buffer_name,
|
|
|
|
"buffer_list": buffer_list,
|
|
|
|
"statusbar_theme": "filled"
|
|
|
|
}
|
|
|
|
|
|
|
|
# Initialise colors
|
|
|
|
colors.init_colors()
|
|
|
|
|
|
|
|
# Change the cursor shape
|
|
|
|
cursor.cursor_mode("block")
|
|
|
|
|
|
|
|
# Start the screen
|
|
|
|
if data["buffer_name"] == "[No Name]":
|
2022-03-17 18:46:04 +00:00
|
|
|
welcome.start_screen(stdscr)
|
2022-03-15 22:12:52 +00:00
|
|
|
|
|
|
|
# Main loop
|
|
|
|
while True:
|
|
|
|
# Get the height and width of the screen
|
|
|
|
data["height"], data["width"] = stdscr.getmaxyx()
|
|
|
|
|
|
|
|
# Write the buffer to the screen
|
|
|
|
buffer.write_buffer(stdscr, data)
|
|
|
|
|
|
|
|
# Activate the next mode
|
|
|
|
data = mode.activate(stdscr, data)
|
|
|
|
|
|
|
|
# Refresh and clear the screen
|
|
|
|
stdscr.refresh()
|
|
|
|
stdscr.clear()
|
|
|
|
|
|
|
|
|
|
|
|
def main():
|
2022-03-17 18:46:04 +00:00
|
|
|
# Arguments
|
2022-03-16 17:23:37 +00:00
|
|
|
parser = argparse.ArgumentParser(description="Next generation hackable text editor for nerds.")
|
2022-03-15 22:12:52 +00:00
|
|
|
parser.add_argument("file", metavar="file", type=str, nargs="?",
|
2022-03-16 17:23:37 +00:00
|
|
|
help="The name of a file for lambda to open")
|
2022-03-15 22:12:52 +00:00
|
|
|
|
2022-03-17 18:46:04 +00:00
|
|
|
# Collect the arguments
|
2022-03-15 22:12:52 +00:00
|
|
|
args = parser.parse_args()
|
2022-03-17 18:46:04 +00:00
|
|
|
|
|
|
|
# Check if a file name has actually been inputted
|
2022-03-15 22:12:52 +00:00
|
|
|
if args.file:
|
2022-03-17 18:46:04 +00:00
|
|
|
# Set the buffer name
|
|
|
|
buffer_name = os.path.basename(args.file)
|
2022-03-15 22:12:52 +00:00
|
|
|
|
2022-03-16 17:23:37 +00:00
|
|
|
# Only if the file exists
|
|
|
|
if os.path.exists(args.file):
|
|
|
|
# Load the file into the buffer
|
2022-03-17 18:46:04 +00:00
|
|
|
buffer_list = files.open_file(args.file)
|
2022-03-16 17:23:37 +00:00
|
|
|
|
|
|
|
# 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:
|
2022-03-17 18:46:04 +00:00
|
|
|
# New file being created, no content
|
2022-03-16 17:23:37 +00:00
|
|
|
buffer_list = [[""]]
|
2022-03-15 22:12:52 +00:00
|
|
|
|
|
|
|
else:
|
2022-03-17 18:46:04 +00:00
|
|
|
# Buffer has no name
|
2022-03-15 22:12:52 +00:00
|
|
|
buffer_name = "[No Name]"
|
2022-03-17 18:46:04 +00:00
|
|
|
|
|
|
|
# Buffer has no value
|
2022-03-15 22:12:52 +00:00
|
|
|
buffer_list = [[""]]
|
|
|
|
|
|
|
|
# Change the escape delay to 25ms
|
2022-03-17 18:46:04 +00:00
|
|
|
# Fixes an issue where esc takes way too long to press
|
2022-03-15 22:12:52 +00:00
|
|
|
os.environ.setdefault("ESCDELAY", "25")
|
|
|
|
|
|
|
|
# Initialise the screen
|
|
|
|
curses.wrapper(start, buffer_name, buffer_list)
|
|
|
|
|
|
|
|
|
|
|
|
if __name__ == "__main__":
|
|
|
|
main()
|