2022-03-14 07:21:55 +00:00
|
|
|
#!/usr/bin/python
|
2022-03-15 15:37:38 +00:00
|
|
|
from core import colors, cursor, mode
|
2022-03-14 07:21:55 +00:00
|
|
|
import os
|
|
|
|
import curses
|
2022-03-15 15:37:38 +00:00
|
|
|
import argparse
|
2022-03-14 07:21:55 +00:00
|
|
|
|
|
|
|
|
|
|
|
def start_screen(stdscr):
|
|
|
|
# Get window height and width
|
|
|
|
height, width = stdscr.getmaxyx()
|
|
|
|
|
|
|
|
# Startup text
|
|
|
|
title = "λ Lambda"
|
|
|
|
subtext = [
|
2022-03-15 15:37:38 +00:00
|
|
|
"Next generation hackable text editor for nerds",
|
2022-03-14 07:21:55 +00:00
|
|
|
"",
|
|
|
|
"Type :h to open the README.md document",
|
|
|
|
"Type :o <file> to open a file and edit",
|
|
|
|
"Type :q or <C-c> to quit lambda"
|
|
|
|
]
|
|
|
|
|
|
|
|
# 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)
|
|
|
|
|
|
|
|
|
2022-03-15 15:37:38 +00:00
|
|
|
def start(stdscr, file):
|
2022-03-14 07:21:55 +00:00
|
|
|
# Initialise data before starting
|
2022-03-15 15:37:38 +00:00
|
|
|
data = {
|
|
|
|
"cursor_y": 0,
|
|
|
|
"cursor_x": 0,
|
|
|
|
"height": 0,
|
|
|
|
"width": 0,
|
|
|
|
"mode": "normal",
|
|
|
|
"icon": "λ",
|
|
|
|
"file": file,
|
|
|
|
"statusbar_theme": "filled"
|
|
|
|
}
|
2022-03-14 07:21:55 +00:00
|
|
|
|
|
|
|
# Initialise colors
|
|
|
|
colors.init_colors()
|
|
|
|
|
|
|
|
# Change the cursor shape
|
|
|
|
cursor.cursor_mode("block")
|
|
|
|
|
2022-03-15 15:37:38 +00:00
|
|
|
# Start the screen
|
|
|
|
start_screen(stdscr)
|
|
|
|
|
2022-03-14 07:21:55 +00:00
|
|
|
# Main loop
|
|
|
|
while True:
|
|
|
|
# Get the height and width of the screen
|
2022-03-15 15:37:38 +00:00
|
|
|
data["height"], data["width"] = stdscr.getmaxyx()
|
2022-03-14 07:21:55 +00:00
|
|
|
|
2022-03-15 15:37:38 +00:00
|
|
|
# Activate the next mode
|
|
|
|
data = mode.activate(stdscr, data)
|
2022-03-14 07:21:55 +00:00
|
|
|
|
|
|
|
# Refresh and clear the screen
|
|
|
|
stdscr.refresh()
|
|
|
|
stdscr.clear()
|
|
|
|
|
|
|
|
|
|
|
|
def main():
|
2022-03-15 15:37:38 +00:00
|
|
|
parser = argparse.ArgumentParser(description="Process some integers.")
|
|
|
|
parser.add_argument("file", metavar="file", type=str, nargs="?",
|
|
|
|
help="File to open")
|
|
|
|
|
|
|
|
args = parser.parse_args()
|
|
|
|
# Check the file name
|
|
|
|
if args.file:
|
|
|
|
file = args.file
|
|
|
|
|
|
|
|
else:
|
|
|
|
file = "[No Name]"
|
|
|
|
|
2022-03-14 07:21:55 +00:00
|
|
|
# Change the escape delay to 25ms
|
|
|
|
# Fixes an issue where esc takes too long to press
|
|
|
|
os.environ.setdefault("ESCDELAY", "25")
|
|
|
|
|
|
|
|
# Initialise the screen
|
2022-03-15 15:37:38 +00:00
|
|
|
curses.wrapper(start, file)
|
2022-03-14 07:21:55 +00:00
|
|
|
|
|
|
|
|
|
|
|
if __name__ == "__main__":
|
|
|
|
main()
|