summaryrefslogtreecommitdiff
path: root/src/user/highway/line.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/user/highway/line.c')
-rw-r--r--src/user/highway/line.c85
1 files changed, 55 insertions, 30 deletions
diff --git a/src/user/highway/line.c b/src/user/highway/line.c
index c8e5c60..bf171e5 100644
--- a/src/user/highway/line.c
+++ b/src/user/highway/line.c
@@ -1,19 +1,37 @@
-#include <pland/pcrt.h>
+#include <terminal/terminal.h>
+
#include <knob/block.h>
#include <knob/task.h>
-#include <knob/user.h>
+
+#include <pland/pcrt.h>
+
#include "cmds.h"
+#include "term.h"
#include "vars.h"
#define LINE_SIZE 4096
static char line[LINE_SIZE];
+static inline uint8_t hex_to_int(char ch) {
+ return ch - (ch <= '9' ? '0' : 'a' - 10);
+}
+
+void ensure_color() {
+ const struct no_null_sn *fg = get_var((struct no_null_sn){.data = "_color_fg", .length = 9});
+ const struct no_null_sn *bg = get_var((struct no_null_sn){.data = "_color_bg", .length = 9});
+ if (fg && bg)
+ set_color(
+ (hex_to_int(fg->data[0]) << 4) | hex_to_int(fg->data[1]),
+ (hex_to_int(bg->data[0]) << 4) | hex_to_int(bg->data[1])
+ );
+}
+
static void line_replace(const char *from) {
const char *fi = from;
char *ti = line;
while (*fi) {
if (ti == line + LINE_SIZE) {
- tell_user_sz("Line too long.\n");
+ term_add_sz("Line too long.\n");
line[0] = '\0';
return;
}
@@ -27,12 +45,15 @@ static void line_replace(const char *from) {
const char *var_end = var_start;
while (*var_end != '$')
if (!*var_end++) {
- tell_user_sz("Unterminated variable name.\n");
+ if (var_end - fi > 10)
+ term_addf("Unterminated variable at\"%10s...\".\n", fi);
+ else
+ term_addf("Unterminated variable at \"%s\".\n", fi);
line[0] = '\0';
return;
}
if (ti + (var_end - var_start) >= line + LINE_SIZE) {
- tell_user_sz("Line too long.\n");
+ term_add_sz("Line too long.\n");
line[0] = '\0';
return;
}
@@ -59,46 +80,50 @@ void run_line(const char *original_line) {
;
if (blockequ(line, "source ", 7))
source(space + 1);
- else if (blockequ(line, "set ", 4))
+ else if (blockequ(line, "set ", 4)) {
set(space + 1);
+ ensure_color();
+ }
else if (blockequ(line, "echo ", 5)) {
- tell_user_sz(space + 1);
- tell_user_sz("\n");
+ term_add_sz(space + 1);
+ term_add_char('\n');
}
else if (blockequ(line, "vars", 5))
dump_vars();
- else if (blockequ(line, "quit", 5))
+ else if (blockequ(line, "quit", 5)) {
+ del_term(active_term);
__pcrt_quit();
+ }
else if (blockequ(line, "clear", 6))
- _clear_screen();
+ clear_term();
else if (blockequ(line, "help", 5))
- tell_user_sz("Highway is a command shell for Portland OS. It includes variables and a couple\n"
- "of pseudo-commands. Variables are addressed by surrounding with \"$\". The\n"
- "following list shows each of the pseudo-commands.\n\n"
- " source FILE run each command in FILE\n"
- " clear clear the screen\n"
- " echo STRING print STRING\n"
- " set VAR VALUE set $VAR$ to VALUE\n"
- " vars dump variables\n"
- " quit exit highway\n"
- " help show this\n");
- else if (!try_run_command_blocking(line)) {
- struct no_null_sn arg = {
- .data = "_path",
- .length = 5
- };
- const struct no_null_sn *path = get_var(arg);
+ term_add_sz("Highway is a command shell for Portland OS. It includes variable support and a couple of pseudo-commands. Variables are addressed by surrounding with \"$\". The following list shows each of the pseudo-commands.\n\n"
+ " source FILE\t" "run each command in FILE\n"
+ " clear\t\t\t" "clear the screen\n"
+ " echo STRING\t" "print STRING\n"
+ " set VAR VALUE\t" "set $VAR$ to VALUE\n"
+ " vars\t\t\t" "dump variables\n"
+ " quit\t\t\t" "exit highway\n"
+ " help\t\t\t" "show this\n");
+ else if (!try_run_command_blocking(line, stdio_task)) {
+ const struct no_null_sn *path = get_var((struct no_null_sn){.data = "_path", .length = 5});
if (!path->length) {
- tell_user_sz("Could not run command.\n");
+ term_add_sz("Could not run command.\n");
return;
}
for (uint16_t to_i = LINE_SIZE - 1; to_i >= path->length; --to_i)
line[to_i] = line[to_i - path->length];
blockcpy(line, path->data, path->length);
- if (!try_run_command_blocking(line)) {
- tell_user_sz("Could not run command.\n");
+ if (!try_run_command_blocking(line, stdio_task)) {
+ term_add_sz("Could not run command.\n");
return;
}
+ else {
+ ensure_color();
+ if (active_term->cursor_x)
+ term_newline();
+ }
}
- _set_color(0x07);
+ else
+ ensure_color();
} \ No newline at end of file