summaryrefslogtreecommitdiff
path: root/src/user/highway
diff options
context:
space:
mode:
authorBenji Dial <benji6283@gmail.com>2021-02-16 22:26:47 -0500
committerBenji Dial <benji6283@gmail.com>2021-02-16 22:26:47 -0500
commitab4e1cfc8c587e4144d847bbd41307eff03130b2 (patch)
tree4e5502422977c747f3e65633ede26b73d9556ca1 /src/user/highway
parent2de07a2abea4081ebab6d80729e5665ba862c74c (diff)
downloadportland-os-ab4e1cfc8c587e4144d847bbd41307eff03130b2.tar.gz
rtc timestamp, knob rand, random terminal color
Diffstat (limited to 'src/user/highway')
-rw-r--r--src/user/highway/line.c20
-rw-r--r--src/user/highway/main.c6
-rw-r--r--src/user/highway/vars.c21
-rw-r--r--src/user/highway/vars.h1
4 files changed, 37 insertions, 11 deletions
diff --git a/src/user/highway/line.c b/src/user/highway/line.c
index cefdf92..5d1e543 100644
--- a/src/user/highway/line.c
+++ b/src/user/highway/line.c
@@ -17,12 +17,12 @@ static inline uint8_t hex_to_int(char ch) {
}
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)
+ const struct no_null_sn *color = get_var((struct no_null_sn){.data = "_color", .length = 6});
+ //fgbg
+ if (color)
term_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])
+ (hex_to_int(color->data[0]) << 4) | hex_to_int(color->data[1]),
+ (hex_to_int(color->data[2]) << 4) | hex_to_int(color->data[3])
);
}
@@ -100,13 +100,19 @@ void run_line(const char *original_line) {
term_clear();
term_paint();
}
+ else if (blockequ(line, "color", 6)) {
+ new_color();
+ ensure_color();
+ term_paint();
+ }
else if (blockequ(line, "help", 5)) {
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"
+ " color\t\t\t" "new color scheme\n"
+ " clear\t\t\t" "clear the screen\n"
" vars\t\t\t" "dump variables\n"
+ " echo STRING\t" "print STRING\n"
" quit\t\t\t" "exit highway\n"
" help\t\t\t" "show this\n");
term_paint();
diff --git a/src/user/highway/main.c b/src/user/highway/main.c
index c9ceee2..59586c1 100644
--- a/src/user/highway/main.c
+++ b/src/user/highway/main.c
@@ -5,12 +5,10 @@
#include "cmds.h"
#include "line.h"
+#include "vars.h"
void main(const char *arg) {
-//syslogf(" this task: 0x%2h", this_task);
-//syslogf(" stdio task: 0x%2h", stdio_task);
-//syslogf("calling task: 0x%2h", calling_task);
-
+ new_color();
source(*arg ? arg : "user/default.rc");
ensure_color();
diff --git a/src/user/highway/vars.c b/src/user/highway/vars.c
index 82062c4..ed9fa3a 100644
--- a/src/user/highway/vars.c
+++ b/src/user/highway/vars.c
@@ -3,6 +3,7 @@
#include <knob/format.h>
#include <knob/block.h>
#include <knob/heap.h>
+#include <knob/rand.h>
#include <pland/pcrt.h>
@@ -80,4 +81,24 @@ void dump_vars() {
term_addf_no_ww("$%ns$\t= %ns\n", node->name.length, node->name.data, node->value.length, node->value.data);
term_paint();
}
+}
+
+static const char hex_digits[] = "0123456789abcdef";
+static char color[] = {'1', '0', '.', '.'};
+
+static const struct no_null_sn color_name = {
+ .data = "_color",
+ .length = 6
+};
+
+static const struct no_null_sn color_value = {
+ .data = color,
+ .length = 4
+};
+
+void new_color() {
+ const uint8_t bg = gen_rand() % 0x30 + 0x38;
+ color[2] = hex_digits[bg >> 4];
+ color[3] = hex_digits[bg & 0xf];
+ set_var(color_name, color_value);
} \ No newline at end of file
diff --git a/src/user/highway/vars.h b/src/user/highway/vars.h
index fc4d197..eca58d4 100644
--- a/src/user/highway/vars.h
+++ b/src/user/highway/vars.h
@@ -13,5 +13,6 @@ const struct no_null_sn *get_var(struct no_null_sn name) __attribute__ ((pure));
void del_var(struct no_null_sn name);
void dump_vars();
+void new_color();
#endif \ No newline at end of file