Rev 4346 | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed
Rev 4346 | Rev 4348 | ||
---|---|---|---|
Line 37... | Line 37... | ||
37 | #include <genarch/srln/srln.h> |
37 | #include <genarch/srln/srln.h> |
38 | #include <console/chardev.h> |
38 | #include <console/chardev.h> |
39 | #include <console/console.h> |
39 | #include <console/console.h> |
40 | #include <proc/thread.h> |
40 | #include <proc/thread.h> |
41 | #include <arch.h> |
41 | #include <arch.h> |
- | 42 | #include <string.h> |
|
42 | 43 | ||
43 | static indev_t srlnout; |
- | |
44 | - | ||
45 | indev_operations_t srlnout_ops = { |
44 | static indev_operations_t srln_raw_ops = { |
46 | .poll = NULL |
45 | .poll = NULL |
47 | }; |
46 | }; |
48 | 47 | ||
49 | static void ksrln(void *arg) |
48 | static void ksrln(void *arg) |
50 | { |
49 | { |
51 | indev_t *in = (indev_t *) arg; |
50 | srln_instance_t *instance = (srln_instance_t *) arg; |
52 | bool cr = false; |
51 | bool cr = false; |
- | 52 | uint32_t escape = 0; |
|
53 | 53 | ||
54 | while (true) { |
54 | while (true) { |
- | 55 | wchar_t ch = indev_pop_character(&instance->raw); |
|
- | 56 | ||
- | 57 | /* ANSI escape sequence processing */ |
|
- | 58 | if (escape != 0) { |
|
- | 59 | escape <<= 8; |
|
- | 60 | escape |= ch & 0xff; |
|
- | 61 | ||
- | 62 | if ((escape == 0x1b4f) || (escape == 0x1b5b) || (escape == 0x1b5b33)) |
|
- | 63 | continue; |
|
- | 64 | ||
55 | uint8_t ch = _getc(in); |
65 | switch (escape) { |
- | 66 | case 0x1b4f46: |
|
- | 67 | case 0x1b5b46: |
|
- | 68 | ch = U_END_ARROW; |
|
- | 69 | escape = 0; |
|
- | 70 | break; |
|
- | 71 | case 0x1b4f48: |
|
- | 72 | case 0x1b5b48: |
|
- | 73 | ch = U_HOME_ARROW; |
|
- | 74 | escape = 0; |
|
- | 75 | break; |
|
- | 76 | case 0x1b5b41: |
|
- | 77 | ch = U_UP_ARROW; |
|
- | 78 | escape = 0; |
|
- | 79 | break; |
|
- | 80 | case 0x1b5b42: |
|
- | 81 | ch = U_DOWN_ARROW; |
|
- | 82 | escape = 0; |
|
- | 83 | break; |
|
- | 84 | case 0x1b5b43: |
|
- | 85 | ch = U_RIGHT_ARROW; |
|
- | 86 | escape = 0; |
|
- | 87 | break; |
|
- | 88 | case 0x1b5b44: |
|
- | 89 | ch = U_LEFT_ARROW; |
|
- | 90 | escape = 0; |
|
- | 91 | break; |
|
- | 92 | case 0x1b5b337e: |
|
- | 93 | ch = U_DELETE; |
|
- | 94 | escape = 0; |
|
- | 95 | break; |
|
- | 96 | default: |
|
- | 97 | escape = 0; |
|
- | 98 | } |
|
- | 99 | } |
|
- | 100 | ||
- | 101 | if (ch == 0x1b) { |
|
- | 102 | escape = ch & 0xff; |
|
- | 103 | continue; |
|
- | 104 | } |
|
56 | 105 | ||
- | 106 | /* Replace carriage return with line feed |
|
- | 107 | and suppress any following line feed */ |
|
57 | if ((ch == '\n') && (cr)) { |
108 | if ((ch == '\n') && (cr)) { |
58 | cr = false; |
109 | cr = false; |
59 | continue; |
110 | continue; |
60 | } |
111 | } |
61 | 112 | ||
Line 63... | Line 114... | ||
63 | ch = '\n'; |
114 | ch = '\n'; |
64 | cr = true; |
115 | cr = true; |
65 | } else |
116 | } else |
66 | cr = false; |
117 | cr = false; |
67 | 118 | ||
- | 119 | /* Backspace */ |
|
68 | if (ch == 0x7f) |
120 | if (ch == 0x7f) |
69 | ch = '\b'; |
121 | ch = '\b'; |
70 | 122 | ||
71 | indev_push_character(stdin, ch); |
123 | indev_push_character(instance->sink, ch); |
72 | } |
124 | } |
73 | } |
125 | } |
74 | 126 | ||
75 | void srln_init(indev_t *devin) |
127 | srln_instance_t *srln_init(void) |
76 | { |
128 | { |
- | 129 | srln_instance_t *instance |
|
77 | indev_initialize("srln", &srlnout, &srlnout_ops); |
130 | = malloc(sizeof(srln_instance_t), FRAME_ATOMIC); |
- | 131 | if (instance) { |
|
78 | thread_t *thread |
132 | instance->thread |
79 | = thread_create(ksrln, devin, TASK, 0, "ksrln", false); |
133 | = thread_create(ksrln, (void *) instance, TASK, 0, "ksrln", false); |
80 | 134 | ||
81 | if (thread) { |
135 | if (!instance->thread) { |
82 | stdin = &srlnout; |
136 | free(instance); |
- | 137 | return NULL; |
|
- | 138 | } |
|
- | 139 | ||
83 | thread_ready(thread); |
140 | instance->sink = NULL; |
- | 141 | indev_initialize("srln", &instance->raw, &srln_raw_ops); |
|
84 | } |
142 | } |
- | 143 | ||
- | 144 | return instance; |
|
- | 145 | } |
|
- | 146 | ||
- | 147 | indev_t *srln_wire(srln_instance_t *instance, indev_t *sink) |
|
- | 148 | { |
|
- | 149 | ASSERT(instance); |
|
- | 150 | ASSERT(sink); |
|
- | 151 | ||
- | 152 | instance->sink = sink; |
|
- | 153 | thread_ready(instance->thread); |
|
- | 154 | ||
- | 155 | return &instance->raw; |
|
85 | } |
156 | } |
86 | 157 | ||
87 | /** @} |
158 | /** @} |
88 | */ |
159 | */ |