Rev 4092 | Go to most recent revision | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed
Rev 4092 | Rev 4223 | ||
---|---|---|---|
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 | static indev_t srlnout; |
44 | 45 | ||
45 | indev_operations_t srlnout_ops = { |
46 | indev_operations_t srlnout_ops = { |
46 | .poll = NULL |
47 | .poll = NULL |
Line 48... | Line 49... | ||
48 | 49 | ||
49 | static void ksrln(void *arg) |
50 | static void ksrln(void *arg) |
50 | { |
51 | { |
51 | indev_t *in = (indev_t *) arg; |
52 | indev_t *in = (indev_t *) arg; |
52 | bool cr = false; |
53 | bool cr = false; |
- | 54 | uint32_t escape = 0; |
|
53 | 55 | ||
54 | while (true) { |
56 | while (true) { |
55 | uint8_t ch = _getc(in); |
57 | wchar_t ch = _getc(in); |
56 | 58 | ||
- | 59 | /* ANSI escape sequence processing */ |
|
- | 60 | if (escape != 0) { |
|
- | 61 | escape <<= 8; |
|
- | 62 | escape |= ch & 0xff; |
|
- | 63 | ||
- | 64 | if ((escape == 0x1b4f) || (escape == 0x1b5b) || (escape == 0x1b5b33)) |
|
- | 65 | continue; |
|
- | 66 | ||
- | 67 | switch (escape) { |
|
- | 68 | case 0x1b4f46: |
|
- | 69 | case 0x1b5b46: |
|
- | 70 | ch = U_END_ARROW; |
|
- | 71 | escape = 0; |
|
- | 72 | break; |
|
- | 73 | case 0x1b4f48: |
|
- | 74 | case 0x1b5b48: |
|
- | 75 | ch = U_HOME_ARROW; |
|
- | 76 | escape = 0; |
|
- | 77 | break; |
|
- | 78 | case 0x1b5b41: |
|
- | 79 | ch = U_UP_ARROW; |
|
- | 80 | escape = 0; |
|
- | 81 | break; |
|
- | 82 | case 0x1b5b42: |
|
- | 83 | ch = U_DOWN_ARROW; |
|
- | 84 | escape = 0; |
|
- | 85 | break; |
|
- | 86 | case 0x1b5b43: |
|
- | 87 | ch = U_RIGHT_ARROW; |
|
- | 88 | escape = 0; |
|
- | 89 | break; |
|
- | 90 | case 0x1b5b44: |
|
- | 91 | ch = U_LEFT_ARROW; |
|
- | 92 | escape = 0; |
|
- | 93 | break; |
|
- | 94 | case 0x1b5b337e: |
|
- | 95 | ch = U_DELETE; |
|
- | 96 | escape = 0; |
|
- | 97 | break; |
|
- | 98 | default: |
|
- | 99 | escape = 0; |
|
- | 100 | } |
|
- | 101 | } |
|
- | 102 | ||
- | 103 | if (ch == 0x1b) { |
|
- | 104 | escape = ch & 0xff; |
|
- | 105 | continue; |
|
- | 106 | } |
|
- | 107 | ||
- | 108 | /* Replace carriage return with line feed |
|
- | 109 | and suppress any following line feed */ |
|
57 | if ((ch == '\n') && (cr)) { |
110 | if ((ch == '\n') && (cr)) { |
58 | cr = false; |
111 | cr = false; |
59 | continue; |
112 | continue; |
60 | } |
113 | } |
61 | 114 | ||
Line 63... | Line 116... | ||
63 | ch = '\n'; |
116 | ch = '\n'; |
64 | cr = true; |
117 | cr = true; |
65 | } else |
118 | } else |
66 | cr = false; |
119 | cr = false; |
67 | 120 | ||
- | 121 | /* Backspace */ |
|
68 | if (ch == 0x7f) |
122 | if (ch == 0x7f) |
69 | ch = '\b'; |
123 | ch = '\b'; |
70 | 124 | ||
71 | indev_push_character(stdin, ch); |
125 | indev_push_character(stdin, ch); |
72 | } |
126 | } |