summaryrefslogtreecommitdiff
path: root/src/user
diff options
context:
space:
mode:
Diffstat (limited to 'src/user')
-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
-rw-r--r--src/user/include/knob/rand.h8
-rw-r--r--src/user/include/pland/syscall.h7
-rw-r--r--src/user/knob/rand.c19
7 files changed, 70 insertions, 12 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
diff --git a/src/user/include/knob/rand.h b/src/user/include/knob/rand.h
new file mode 100644
index 0000000..46052e2
--- /dev/null
+++ b/src/user/include/knob/rand.h
@@ -0,0 +1,8 @@
+#ifndef RAND_H
+#define RAND_H
+
+#include <stdint.h>
+
+uint32_t gen_rand();
+
+#endif \ No newline at end of file
diff --git a/src/user/include/pland/syscall.h b/src/user/include/pland/syscall.h
index 6870865..fd0b416 100644
--- a/src/user/include/pland/syscall.h
+++ b/src/user/include/pland/syscall.h
@@ -43,7 +43,8 @@ enum _scn {
_SCN_WAIT_ANY_IPC_SENT,
_SCN_FIND_UNREAD_IPC,
_SCN_WAIT_IPC_READ,
- _SCN_IS_TASK_RUNNING
+ _SCN_IS_TASK_RUNNING,
+ _SCN_GET_TIMESTAMP
};
static inline uint32_t _sc0(enum _scn eax) {
@@ -228,4 +229,8 @@ static inline bool _is_task_running(_task_handle_t handle) {
return (bool)_sc1(_SCN_IS_TASK_RUNNING, handle);
}
+static inline uint32_t _get_timestamp() {
+ return _sc0(_SCN_GET_TIMESTAMP);
+}
+
#endif \ No newline at end of file
diff --git a/src/user/knob/rand.c b/src/user/knob/rand.c
new file mode 100644
index 0000000..63648fb
--- /dev/null
+++ b/src/user/knob/rand.c
@@ -0,0 +1,19 @@
+#include <pland/syscall.h>
+#include <pland/pcrt.h>
+
+#include <stdint.h>
+
+static uint32_t r;
+
+static void seed_rand() {
+ r = _get_timestamp();
+}
+
+BEFORE_MAIN(seed_rand)
+
+uint32_t gen_rand() {
+ r ^= r << 13;
+ r ^= r >> 17;
+ r ^= r << 5;
+ return r;
+} \ No newline at end of file