commit 37b75e9ab17fa380f0b406bc664df1867893c25a
parent 10b50024da5e3871bdcc14e95c28d4f1768662bc
Author: Drew DeVault <sir@cmpwn.com>
Date: Wed, 20 Oct 2021 11:08:50 +0200
cmd/iobus: initial commit
Signed-off-by: Drew DeVault <sir@cmpwn.com>
Diffstat:
1 file changed, 54 insertions(+), 0 deletions(-)
diff --git a/cmd/iobus/main.ha b/cmd/iobus/main.ha
@@ -0,0 +1,54 @@
+use bufio;
+use fmt;
+use io;
+use iobus;
+use os;
+use strings;
+use unix::poll;
+use unix::poll::{event};
+
+export fn main() void = {
+ let bus = iobus::new()!;
+ defer iobus::destroy(bus);
+
+ const pollfd = [
+ poll::pollfd {
+ fd = os::stdin_file,
+ events = event::POLLIN,
+ ...
+ },
+ poll::pollfd {
+ fd = iobus::busfile(bus),
+ events = event::POLLIN,
+ ...
+ },
+ ];
+ fmt::error("> ")!;
+
+ for (true) {
+ let events = poll::poll(pollfd, poll::INDEF)!;
+ if (pollfd[0].revents & event::POLLIN > 0) {
+ if (!readcmd(bus)) {
+ fmt::errorln("exit")!;
+ break;
+ };
+ };
+ if (pollfd[1].revents & event::POLLIN > 0) {
+ void; // TODO
+ };
+ };
+};
+
+fn readcmd(bus: *iobus::bus) bool = {
+ const line = match (bufio::scanline(os::stdin)!) {
+ case line: []u8 =>
+ yield strings::fromutf8(line);
+ case io::EOF =>
+ return false;
+ };
+ defer free(line);
+
+ fmt::errorfln("{}", line)!;
+ fmt::error("> ")!;
+ return true;
+};