commit 905650984a0a7221922e40d5dd2702ad8aab4a5e
parent 8ceb9e41bed207252e7f1d2e6f717e43f0e11e47
Author: Byron Torres <b@torresjrjr.com>
Date: Tue, 22 Nov 2022 00:53:21 +0000
add buffer.ha
Diffstat:
3 files changed, 30 insertions(+), 15 deletions(-)
diff --git a/Makefile b/Makefile
@@ -2,7 +2,8 @@ HARE=hare
HAREFLAGS=
source=\
- main.ha
+ main.ha \
+ buffer.ha \
all: ed
diff --git a/buffer.ha b/buffer.ha
@@ -0,0 +1,12 @@
+type buffer = struct {
+ filename: (void | str),
+ lines: []line,
+ trash: []line,
+ cursor: size,
+};
+
+type line = struct {
+ text: str,
+ mark: rune,
+ globalmark: bool,
+};
diff --git a/main.ha b/main.ha
@@ -4,11 +4,13 @@ use getopt;
use io;
use os;
-let prompt: str = "";
-
-let surpress: bool = false;
-
-type filename = (str | void);
+type session = struct {
+ buffer: buffer,
+ helpmode: bool,
+ suppressmode: bool,
+ promptmode: bool,
+ prompt: str,
+};
export fn main() void = {
const help: [_]getopt::help = [
@@ -20,13 +22,16 @@ export fn main() void = {
const cmd = getopt::parse(os::args, help...);
defer getopt::finish(&cmd);
+ const sesh = session{ ... };
+
for (let i = 0z; i < len(cmd.opts); i += 1) {
const opt = cmd.opts[i];
switch (opt.0) {
case 'p' =>
- prompt = opt.1;
+ sesh.prompt = opt.1;
+ sesh.promptmode = true;
case 's' =>
- surpress = true;
+ sesh.suppressmode = true;
};
};
@@ -34,22 +39,19 @@ export fn main() void = {
exit_usage(help);
};
- let fname: filename = switch (len(cmd.args) == 1) {
- case false =>
- void;
- case true =>
- switch (cmd.args[0]) {
+ sesh.buffer.filename = if (len(cmd.args) == 1) {
+ yield switch (cmd.args[0]) {
case "-" =>
fmt::fatal("Invalid filename '-'");
case "" =>
fmt::fatal("Invalid filename ''");
case =>
- cmd.args[0];
+ yield cmd.args[0];
};
};
for (true) :repl {
- fmt::error(prompt)!;
+ fmt::error(sesh.prompt)!;
const rawline = match (bufio::scanline(os::stdin)) {
case let rawline: []u8 =>