summaryrefslogtreecommitdiff
path: root/src/user/include/libterm
diff options
context:
space:
mode:
Diffstat (limited to 'src/user/include/libterm')
-rw-r--r--src/user/include/libterm/command.h68
-rw-r--r--src/user/include/libterm/readline.h10
-rw-r--r--src/user/include/libterm/terminal.h35
3 files changed, 113 insertions, 0 deletions
diff --git a/src/user/include/libterm/command.h b/src/user/include/libterm/command.h
new file mode 100644
index 0000000..7587306
--- /dev/null
+++ b/src/user/include/libterm/command.h
@@ -0,0 +1,68 @@
+#ifndef LIBTERM_COMMAND_H
+#define LIBTERM_COMMAND_H
+
+#include <libterm/terminal.h>
+
+#include <knob/ipc.h>
+
+#include <keypack.h>
+
+#include <stdbool.h>
+#include <stdint.h>
+
+//set to stdio task by default
+extern _task_handle_t term_task;
+
+struct terminal_command {
+ enum {
+ SET_DIMENSIONS,
+ GET_DIMENSIONS,
+ PAINT,
+ CLEAR,
+ SET_COLOR,
+ SET_CURSOR,
+ CURSOR_LEFT,
+ CURSOR_RIGHT,
+ CURSOR_UP,
+ CURSOR_DOWN,
+ ADD_CHAR,
+ ADD_SN,
+ ADD_SN_NO_WORDWRAP,
+ GET_KEY
+ } kind;
+
+ union {
+ struct {
+ uint32_t y;
+ uint32_t x;
+ } as_coords;
+ struct {
+ uint8_t fg;
+ uint8_t bg;
+ } as_color;
+ char as_char;
+ uint32_t as_uint;
+ };
+} __attribute__ ((__packed__));
+
+union terminal_response {
+ struct {
+ uint32_t y;
+ uint32_t x;
+ } as_coords;
+ struct key_packet as_key;
+} __attribute__ ((__packed__));
+
+//returns false if terminal has died
+static inline bool try_send_command(struct terminal_command *cmd) {
+ return try_send_ipc(term_task, cmd, sizeof(struct terminal_command))
+ == sizeof(struct terminal_command);
+}
+
+//returns false if terminal has died
+static inline bool try_get_response(union terminal_response *rs) {
+ return try_read_ipc(term_task, rs, sizeof(union terminal_response))
+ == sizeof(union terminal_response);
+}
+
+#endif \ No newline at end of file
diff --git a/src/user/include/libterm/readline.h b/src/user/include/libterm/readline.h
new file mode 100644
index 0000000..b1d5b0a
--- /dev/null
+++ b/src/user/include/libterm/readline.h
@@ -0,0 +1,10 @@
+#ifndef LIBTERM_READLINE_H
+#define LIBTERM_READLINE_H
+
+#include <stdint.h>
+
+//returns length of string without null terminator
+//max_length doesn't include null terminator
+uint32_t read_line(char *sz, uint32_t max_length, const char *prompt);
+
+#endif \ No newline at end of file
diff --git a/src/user/include/libterm/terminal.h b/src/user/include/libterm/terminal.h
new file mode 100644
index 0000000..19bd517
--- /dev/null
+++ b/src/user/include/libterm/terminal.h
@@ -0,0 +1,35 @@
+#ifndef LIBTERM_TERMINAL_H
+#define LIBTERM_TERMINAL_H
+
+#include <pland/syscall.h>
+
+#include <stdarg.h>
+#include <stdint.h>
+
+void term_set_dimensions(uint32_t width, uint32_t height);
+void term_get_dimensions(uint32_t *width, uint32_t *height);
+
+void term_paint();
+void term_clear();
+
+void term_set_color(uint8_t fg, uint8_t bg);
+void term_set_cursor(uint32_t new_y, uint32_t new_x);
+
+void term_cursor_left();
+void term_cursor_right();
+void term_cursor_up();
+void term_cursor_down();
+
+void term_add_char(char ch);
+void term_add_sn_no_ww(const char *s, uint32_t n);
+void term_add_sz_no_ww(const char *sz);
+void term_add_sz(const char *sz);
+
+void term_addf_no_ww_v(const char *fmt, va_list args);
+void term_addf_no_ww(const char *fmt, ...);
+void term_addf_v(const char *fmt, va_list args);
+void term_addf(const char *fmt, ...);
+
+struct key_packet term_get_key_blocking();
+
+#endif \ No newline at end of file