Begin to read in files at startup
This commit is contained in:
parent
88f7ab0e8d
commit
2eccabeaa5
1
.gitignore
vendored
1
.gitignore
vendored
@ -1 +1,2 @@
|
|||||||
/target
|
/target
|
||||||
|
.idea
|
||||||
|
@ -0,0 +1,9 @@
|
|||||||
|
import curses
|
||||||
|
|
||||||
|
|
||||||
|
def write_buffer(stdscr, data):
|
||||||
|
count = 0
|
||||||
|
for line in data["buffer_list"]:
|
||||||
|
str_line = "".join(line)
|
||||||
|
stdscr.addstr(count, len(data["info_bar"][0]), str_line + (" " * (len(line) - 1)), curses.color_pair(1))
|
||||||
|
count += 1
|
4
core/files.py
Normal file
4
core/files.py
Normal file
@ -0,0 +1,4 @@
|
|||||||
|
def open_file(file):
|
||||||
|
with open(file) as f:
|
||||||
|
lines = f.readlines()
|
||||||
|
return lines
|
@ -9,7 +9,7 @@ def themes(data):
|
|||||||
# Add spaces before each part
|
# Add spaces before each part
|
||||||
icon = f" {data['icon']}"
|
icon = f" {data['icon']}"
|
||||||
mode = f" {data['mode'].upper()}"
|
mode = f" {data['mode'].upper()}"
|
||||||
file = f" {data['file']}"
|
file = f" {data['buffer_name']}"
|
||||||
|
|
||||||
else:
|
else:
|
||||||
# The theme colors
|
# The theme colors
|
||||||
@ -18,7 +18,7 @@ def themes(data):
|
|||||||
# Add spaces on either end
|
# Add spaces on either end
|
||||||
icon = f" {data['icon']} "
|
icon = f" {data['icon']} "
|
||||||
mode = f" {data['mode'].upper()} "
|
mode = f" {data['mode'].upper()} "
|
||||||
file = f" {data['file']} "
|
file = f" {data['buffer_name']} "
|
||||||
|
|
||||||
return colors, icon, mode, file
|
return colors, icon, mode, file
|
||||||
|
|
||||||
|
@ -1,11 +1,11 @@
|
|||||||
from sys import exit
|
from sys import exit
|
||||||
from core import cursor
|
|
||||||
import curses
|
import curses
|
||||||
|
|
||||||
|
|
||||||
def goodbye(stdscr, data):
|
def goodbye(stdscr, data):
|
||||||
# The prompt message
|
# The prompt message
|
||||||
prompt = "Really quit lambda? (y or n): "
|
saved = "All changes are saved."
|
||||||
|
prompt = "Really quit? (y or n): "
|
||||||
|
|
||||||
# Clear the bottom line
|
# Clear the bottom line
|
||||||
stdscr.addstr(data["height"] - 1, 0, " " * (data["width"] - 1), curses.color_pair(1))
|
stdscr.addstr(data["height"] - 1, 0, " " * (data["width"] - 1), curses.color_pair(1))
|
||||||
|
94
lambda
94
lambda
@ -1,93 +1,3 @@
|
|||||||
#!/usr/bin/python
|
#!/bin/sh
|
||||||
from core import colors, cursor, mode
|
|
||||||
import os
|
|
||||||
import curses
|
|
||||||
import argparse
|
|
||||||
|
|
||||||
|
python3 ./lambda.py $@
|
||||||
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 <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)
|
|
||||||
|
|
||||||
|
|
||||||
def start(stdscr, file):
|
|
||||||
# Initialise data before starting
|
|
||||||
data = {
|
|
||||||
"cursor_y": 0,
|
|
||||||
"cursor_x": 0,
|
|
||||||
"height": 0,
|
|
||||||
"width": 0,
|
|
||||||
"mode": "normal",
|
|
||||||
"icon": "λ",
|
|
||||||
"file": file,
|
|
||||||
"statusbar_theme": "filled"
|
|
||||||
}
|
|
||||||
|
|
||||||
# Initialise colors
|
|
||||||
colors.init_colors()
|
|
||||||
|
|
||||||
# Change the cursor shape
|
|
||||||
cursor.cursor_mode("block")
|
|
||||||
|
|
||||||
# Start the screen
|
|
||||||
start_screen(stdscr)
|
|
||||||
|
|
||||||
# Main loop
|
|
||||||
while True:
|
|
||||||
# Get the height and width of the screen
|
|
||||||
data["height"], data["width"] = stdscr.getmaxyx()
|
|
||||||
|
|
||||||
# Activate the next mode
|
|
||||||
data = mode.activate(stdscr, data)
|
|
||||||
|
|
||||||
# Refresh and clear the screen
|
|
||||||
stdscr.refresh()
|
|
||||||
stdscr.clear()
|
|
||||||
|
|
||||||
|
|
||||||
def main():
|
|
||||||
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]"
|
|
||||||
|
|
||||||
# Change the escape delay to 25ms
|
|
||||||
# Fixes an issue where esc takes too long to press
|
|
||||||
os.environ.setdefault("ESCDELAY", "25")
|
|
||||||
|
|
||||||
# Initialise the screen
|
|
||||||
curses.wrapper(start, file)
|
|
||||||
|
|
||||||
|
|
||||||
if __name__ == "__main__":
|
|
||||||
main()
|
|
||||||
|
104
lambda.py
Executable file
104
lambda.py
Executable file
@ -0,0 +1,104 @@
|
|||||||
|
from core import colors, cursor, mode, files, buffer
|
||||||
|
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 <file> to open a file and edit",
|
||||||
|
"Type :q or <C-c> 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 = {
|
||||||
|
"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]":
|
||||||
|
start_screen(stdscr)
|
||||||
|
|
||||||
|
# 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():
|
||||||
|
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 if a file name has been inputted
|
||||||
|
if args.file:
|
||||||
|
buffer_name = args.file
|
||||||
|
buffer_list = files.open_file(buffer_name)
|
||||||
|
|
||||||
|
# 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:
|
||||||
|
buffer_name = "[No Name]"
|
||||||
|
buffer_list = [[""]]
|
||||||
|
|
||||||
|
# Change the escape delay to 25ms
|
||||||
|
# Fixes an issue where esc takes too long to press
|
||||||
|
os.environ.setdefault("ESCDELAY", "25")
|
||||||
|
|
||||||
|
# Initialise the screen
|
||||||
|
curses.wrapper(start, buffer_name, buffer_list)
|
||||||
|
|
||||||
|
|
||||||
|
if __name__ == "__main__":
|
||||||
|
main()
|
@ -22,6 +22,11 @@ def execute(data, key):
|
|||||||
# Exit normal mode and enter insert mode
|
# Exit normal mode and enter insert mode
|
||||||
data["mode"] = "insert"
|
data["mode"] = "insert"
|
||||||
|
|
||||||
|
elif key == ord("I"):
|
||||||
|
# Exit normal mode and enter insert mode
|
||||||
|
data["cursor_x"] += 1
|
||||||
|
data["mode"] = "insert"
|
||||||
|
|
||||||
elif key in (ord(":"), ord(";")):
|
elif key in (ord(":"), ord(";")):
|
||||||
# Exit normal mode and enter command mode
|
# Exit normal mode and enter command mode
|
||||||
data["mode"] = "command"
|
data["mode"] = "command"
|
||||||
|
Loading…
Reference in New Issue
Block a user