lambda-calc-1/repl/main.c

135 lines
4.5 KiB
C

#include <assert.h>
#include <debug.h>
#include "main.h"
void repl_main(void)
{
ENTER;
TODO;
// if we're actually connected to a terminal:
// set terminal options.
// otherwise, open the file we're pretending is a terminal.
// create input string
// which is an actual string that the history object has a reference to?
// create history:
// I think this is a list of strings?
// create terminal tokenizer
// create terminal buffer:
// which keeps track of what characters we want where (not nessarily \\
the entire height of the terminal, but certianly the entire width) \\
characters can have foreground color (and maybe boldness?).
// has a insert column and line. handles word-wrap.
// keeps track of what's on the screen and only edits as nessisary.
// starts with assuming we're only editing one line (full width), but \\
if the expression line gets too long or printing error messages \\
might push us beyond that, then --even if we cleared-- we would \\
need to consider the new editing height.
// this terminal buffer also keeps track of where the cursor should \\
be vs. where it is and will update that apprioately as well.
// loop:
// read next token
// somehow also check if the terminal resized. If it did:
// tell the terminal buffer.
// internally this will completely reset what's live.
// match token.kind:
// (almost) every case clears and redraws what we want the buffer \\
to contain.
// case up, down:
// selects history index?
// which selects the string we're editing?
// case left, right:
// just move cursor position, no clear needed.
// case 'a-zA-Z0-9', etc.:
// insert the letter into the string
// create parsing tokenizer
// parse the string
// all statements and expressions keep references to the \\
tokens.
// tell the statement to color tokens
// the tokenizer keeps references to all tokens too.
// clear the buffer
// set buffer insert position to 0, 0.
// maybe the prompt + line is longer than the terminal width.
// some maybe we word-wrap?
// draw the prompt line (either green or red)
// iterate through tokenizer's tokens:
// each token knows how many whitespace characters were \\
read since the previous one.
// print their text into the buffer with the token's color.
// the buffer will handle word-wrapping.
// some tokens don't have an expression or statement that \\
owns them.
// some part of the input text may not be part of a \\
token? like a comment?
// I think comments will need to be considered \\
tokens that the parser doesn't pick up. That way \\
it at least appears in the output line.
// case delete, backspace:
// remove the letter at location
// run through basically the same parsing logic as inserting \\
a character
// case enter:
// push a newline
// if line is not empty:
// evaluate statement
// which might print a value
// into the terminal buffer? or straight out?
// I think straight out.
// terminal buffer.clear(true-reset = True):
// true reset will clear what's "live" and the buffer, \\
and set the height back to 1.
// new string line
// new history entry
// redraw prompt.
// update buffer:
// compare (buffer of what we want vs. what's live)
TODO;
EXIT;
}