summaryrefslogtreecommitdiff
path: root/src/user/include/libterm/command.h
blob: 75873064f23a1b573291f5e65d62dfcff6274f9d (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
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