Changeset d31c3ea in mainline
- Timestamp:
- 2024-10-01T11:13:28Z (3 months ago)
- Branches:
- master
- Children:
- 6907f26
- Parents:
- 357d9dd
- git-author:
- Jiri Svoboda <jiri@…> (2024-09-30 19:13:18)
- git-committer:
- Jiri Svoboda <jiri@…> (2024-10-01 11:13:28)
- Location:
- uspace
- Files:
-
- 6 edited
Legend:
- Unmodified
- Added
- Removed
-
uspace/lib/vt/include/vt/vt100.h
r357d9dd rd31c3ea 71 71 } sgr_command_t; 72 72 73 typedef void (*vt100_putuchar_t)(void *, char32_t ch); 74 typedef void (*vt100_control_puts_t)(void *, const char *str); 75 typedef void (*vt100_flush_t)(void *); 73 typedef struct { 74 void (*putuchar)(void *, char32_t); 75 void (*control_puts)(void *, const char *); 76 void (*flush)(void *); 77 } vt100_cb_t; 76 78 79 /** VT100 instance */ 77 80 typedef struct { 81 /** Number of columns */ 78 82 sysarg_t cols; 83 /** Number of rows */ 79 84 sysarg_t rows; 80 85 86 /** Current column */ 81 87 sysarg_t cur_col; 88 /** Current row */ 82 89 sysarg_t cur_row; 90 /** Current attributes */ 83 91 char_attrs_t cur_attrs; 84 92 93 /** Enable RGB color */ 85 94 bool enable_rgb; 86 95 96 /** Callback functions */ 97 vt100_cb_t *cb; 98 /** Argument to callback functions */ 87 99 void *arg; 88 vt100_putuchar_t putuchar;89 vt100_control_puts_t control_puts;90 vt100_flush_t flush;91 100 } vt100_t; 92 101 … … 94 103 95 104 extern vt100_t *vt100_create(void *, sysarg_t, sysarg_t, 96 vt100_ putuchar_t, vt100_control_puts_t, vt100_flush_t);105 vt100_cb_t *); 97 106 extern void vt100_destroy(vt100_t *); 98 107 -
uspace/lib/vt/src/vt100.c
r357d9dd rd31c3ea 51 51 void vt100_cls(vt100_t *state) 52 52 { 53 state->c ontrol_puts(state->arg, "\033[2J");53 state->cb->control_puts(state->arg, "\033[2J"); 54 54 } 55 55 … … 60 60 61 61 snprintf(control, MAX_CONTROL, "\033[%um", mode); 62 state->c ontrol_puts(state->arg, control);62 state->cb->control_puts(state->arg, control); 63 63 } 64 64 … … 71 71 snprintf(control, MAX_CONTROL, "\033[%u;%u;%u;%u;%um", 72 72 a1, a2, a3, a4, a5); 73 state->c ontrol_puts(state->arg, control);73 state->cb->control_puts(state->arg, control); 74 74 } 75 75 … … 80 80 snprintf(control, MAX_CONTROL, "\033[%" PRIun ";%" PRIun "f", 81 81 row + 1, col + 1); 82 state->c ontrol_puts(state->arg, control);82 state->cb->control_puts(state->arg, control); 83 83 } 84 84 … … 147 147 } 148 148 149 vt100_t *vt100_create(void *arg, sysarg_t cols, sysarg_t rows, 150 vt100_putuchar_t putuchar_fn, vt100_control_puts_t control_puts_fn, 151 vt100_flush_t flush_fn) 149 vt100_t *vt100_create(void *arg, sysarg_t cols, sysarg_t rows, vt100_cb_t *cb) 152 150 { 153 151 vt100_t *state = malloc(sizeof(vt100_t)); … … 155 153 return NULL; 156 154 155 state->cb = cb; 157 156 state->arg = arg; 158 state->putuchar = putuchar_fn;159 state->control_puts = control_puts_fn;160 state->flush = flush_fn;161 157 162 158 state->cols = cols; … … 217 213 { 218 214 if (visible) 219 state->c ontrol_puts(state->arg, "\033[?25h");215 state->cb->control_puts(state->arg, "\033[?25h"); 220 216 else 221 state->c ontrol_puts(state->arg, "\033[?25l");217 state->cb->control_puts(state->arg, "\033[?25l"); 222 218 } 223 219 224 220 void vt100_putuchar(vt100_t *state, char32_t ch) 225 221 { 226 state-> putuchar(state->arg, ch == 0 ? ' ' : ch);222 state->cb->putuchar(state->arg, ch == 0 ? ' ' : ch); 227 223 state->cur_col++; 228 224 … … 235 231 void vt100_flush(vt100_t *state) 236 232 { 237 state-> flush(state->arg);233 state->cb->flush(state->arg); 238 234 } 239 235 -
uspace/srv/hid/output/ctl/serial.c
r357d9dd rd31c3ea 44 44 #define SERIAL_COLS 80 45 45 #define SERIAL_ROWS 24 46 47 static serial_putuchar_t serial_putuchar_fn; 48 static serial_control_puts_t serial_control_puts_fn; 49 static serial_flush_t serial_flush_fn; 50 51 static void serial_vt_putuchar(void *, char32_t); 52 static void serial_vt_control_puts(void *, const char *); 53 static void serial_vt_flush(void *); 54 55 static vt100_cb_t serial_vt_cb = { 56 .putuchar = serial_vt_putuchar, 57 .control_puts = serial_vt_control_puts, 58 .flush = serial_vt_flush 59 }; 46 60 47 61 /** Draw the character at the specified position. … … 124 138 }; 125 139 126 errno_t serial_init( vt100_putuchar_t putuchar_fn,127 vt100_control_puts_t control_puts_fn, vt100_flush_t flush_fn)140 errno_t serial_init(serial_putuchar_t putuchar_fn, 141 serial_control_puts_t control_puts_fn, serial_flush_t flush_fn) 128 142 { 129 143 char_attrs_t attrs; 130 vt100_t *vt100 = 131 vt100_create(NULL, SERIAL_COLS, SERIAL_ROWS, putuchar_fn, 132 control_puts_fn, flush_fn); 144 vt100_t *vt100; 145 146 serial_putuchar_fn = putuchar_fn; 147 serial_control_puts_fn = control_puts_fn; 148 serial_flush_fn = flush_fn; 149 150 vt100 = vt100_create(NULL, SERIAL_COLS, SERIAL_ROWS, &serial_vt_cb); 133 151 if (vt100 == NULL) 134 152 return ENOMEM; … … 150 168 } 151 169 170 static void serial_vt_putuchar(void *arg, char32_t c) 171 { 172 (void)arg; 173 serial_putuchar_fn(c); 174 } 175 176 static void serial_vt_control_puts(void *arg, const char *str) 177 { 178 (void)arg; 179 serial_control_puts_fn(str); 180 } 181 182 static void serial_vt_flush(void *arg) 183 { 184 (void)arg; 185 serial_flush_fn(); 186 } 187 152 188 /** @} 153 189 */ -
uspace/srv/hid/output/ctl/serial.h
r357d9dd rd31c3ea 38 38 #include <vt/vt100.h> 39 39 40 extern errno_t serial_init(vt100_putuchar_t, vt100_control_puts_t, vt100_flush_t); 40 typedef void (*serial_putuchar_t)(char32_t); 41 typedef void (*serial_control_puts_t)(const char *); 42 typedef void (*serial_flush_t)(void); 43 44 extern errno_t serial_init(serial_putuchar_t, serial_control_puts_t, 45 serial_flush_t); 41 46 42 47 #endif -
uspace/srv/hid/output/port/chardev.c
r357d9dd rd31c3ea 65 65 static FIBRIL_CONDVAR_INITIALIZE(discovery_cv); 66 66 67 static void chardev_flush(void *arg)67 static void chardev_flush(void) 68 68 { 69 69 size_t nwr; 70 71 (void)arg;72 70 73 71 if (chardev_bused == 0) … … 83 81 { 84 82 if (chardev_bused == chardev_buf_size) 85 chardev_flush( NULL);83 chardev_flush(); 86 84 chardev_buf[chardev_bused++] = (uint8_t) ch; 87 85 } 88 86 89 static void chardev_putuchar( void *arg,char32_t ch)87 static void chardev_putuchar(char32_t ch) 90 88 { 91 89 char buf[STR_BOUNDS(1)]; … … 94 92 errno_t rc; 95 93 96 (void)arg;97 98 94 off = 0; 99 95 rc = chr_encode(ch, buf, &off, sizeof(buf)); … … 105 101 } 106 102 107 static void chardev_control_puts( void *arg,const char *str)103 static void chardev_control_puts(const char *str) 108 104 { 109 105 const char *p; … … 111 107 p = str; 112 108 while (*p != '\0') 113 chardev_putuchar( arg,*p++);109 chardev_putuchar(*p++); 114 110 } 115 111 -
uspace/srv/hid/remcons/remcons.c
r357d9dd rd31c3ea 121 121 }; 122 122 123 static void remcons_vt_putchar(void *, char32_t); 124 static void remcons_vt_cputs(void *, const char *); 125 static void remcons_vt_flush(void *); 126 127 static vt100_cb_t remcons_vt_cb = { 128 .putuchar = remcons_vt_putchar, 129 .control_puts = remcons_vt_cputs, 130 .flush = remcons_vt_flush 131 }; 132 123 133 static void remcons_new_conn(tcp_listener_t *lst, tcp_conn_t *conn); 124 134 … … 568 578 remcons->curs_visible = true; 569 579 570 remcons->vt = vt100_create((void *)remcons, 80, 25, 571 remcons_vt_putchar, remcons_vt_cputs, remcons_vt_flush); 580 remcons->vt = vt100_create((void *)remcons, 80, 25, &remcons_vt_cb); 572 581 assert(remcons->vt != NULL); // XXX 573 582 remcons->vt->enable_rgb = remcons->enable_rgb;
Note:
See TracChangeset
for help on using the changeset viewer.