summaryrefslogtreecommitdiffstats
path: root/src/device/screen.c
diff options
context:
space:
mode:
authorGravatar Ramūnas Mažeikis <ramunasnezinomas@gmail.com> 2019-05-27 15:44:38 +0300
committerGravatar Ramūnas Mažeikis <ramunasnezinomas@gmail.com> 2019-05-27 15:44:38 +0300
commite37b3eacefef04258a6dc6e8714da249d2ff9c1d (patch)
tree53367df66a33f88015da5926e4f15b9867681da8 /src/device/screen.c
parent755680ca7246b232c45e3b519e9d8a95ea97375f (diff)
downloadusurpation-e37b3eacefef04258a6dc6e8714da249d2ff9c1d.tar.gz
usurpation-e37b3eacefef04258a6dc6e8714da249d2ff9c1d.tar.bz2
usurpation-e37b3eacefef04258a6dc6e8714da249d2ff9c1d.zip
Screen: More implementation details.
Only a single function is a stub now --- the actual drawing. Signed-off-by: Ramūnas Mažeikis <ramunasnezinomas@gmail.com>
Diffstat (limited to 'src/device/screen.c')
-rwxr-xr-xsrc/device/screen.c62
1 files changed, 37 insertions, 25 deletions
diff --git a/src/device/screen.c b/src/device/screen.c
index 6ad9a87..ac42076 100755
--- a/src/device/screen.c
+++ b/src/device/screen.c
@@ -1,10 +1,45 @@
#include <time.h>
#include <stdlib.h>
+#include <string.h>
#include "screen.h"
void draw_lines(struct display_status *status);
void update_lines(struct display_status *status);
-char * get_line(struct display_status *status, size_t rline);
+void init_msg(char *msg, size_t size);
+
+void display_status_init(struct display_status *status, char *msg)
+{
+ status->delta = 2; /* Currently default */
+ init_msg(msg, strlen(msg));
+ status->message = msg;
+ status->line_cursor = 0;
+ status->last_scroll_time = time(NULL);
+ update_lines(status);
+}
+
+/**
+ * Turns all whitespace into literal spaces to save screen real-estate.
+ */
+void init_msg(char *msg, size_t size)
+{
+ size_t i;
+
+ for (i = 0; i < size; i++) {
+ switch (msg[i]) {
+ case '\n':
+ case '\t':
+ case '\r':
+ msg[i] = ' ';
+ break;
+ case '\0':
+ goto end;
+ default:
+ break;
+ }
+ }
+end:
+ return;
+}
void display_update_scroll(struct display_status *status)
{
@@ -19,34 +54,11 @@ void display_update_scroll(struct display_status *status)
void draw_lines(struct display_status *status)
{
-
+ /* TODO */
}
void update_lines(struct display_status *status)
{
status->first_line = get_line(status, status->line_cursor);
status->second_line = get_line(status, status->line_cursor + 1);
-}
-
-/**
- * Returns a pointer to the first charachter of requested line. If line does not
- * exist --- a null is returned.
- */
-char * get_line(struct display_status *status, size_t rline)
-{
- size_t i;
- size_t line_idx = 0;
-
- for (i = 0; i < status->message_len; i++) {
- if (rline == line_idx) {
- return status->message + i;
- }
- if (status->message[i] == '\0') {
- line_idx++;
- }
- }
- /* The fact that we are here means that end of the message was reached.
- * In that case --- return null;
- */
- return NULL;
} \ No newline at end of file