Lines Matching full:sh

11 void z_shell_op_cursor_vert_move(const struct shell *sh, int32_t delta)  in z_shell_op_cursor_vert_move()  argument
23 Z_SHELL_VT100_CMD(sh, "\e[%d%c", delta, dir); in z_shell_op_cursor_vert_move()
26 void z_shell_op_cursor_horiz_move(const struct shell *sh, int32_t delta) in z_shell_op_cursor_horiz_move() argument
38 Z_SHELL_VT100_CMD(sh, "\e[%d%c", delta, dir); in z_shell_op_cursor_horiz_move()
44 static inline bool full_line_cmd(const struct shell *sh) in full_line_cmd() argument
46 size_t line_length = sh->ctx->cmd_buff_len + z_shell_strlen(sh->ctx->prompt); in full_line_cmd()
52 return (line_length % sh->ctx->vt100_ctx.cons.terminal_wid == 0U); in full_line_cmd()
56 bool z_shell_cursor_in_empty_line(const struct shell *sh) in z_shell_cursor_in_empty_line() argument
58 return (((sh->ctx->cmd_buff_pos * sh->ctx->cfg.flags.echo) + in z_shell_cursor_in_empty_line()
59 z_shell_strlen(sh->ctx->prompt)) % in z_shell_cursor_in_empty_line()
60 sh->ctx->vt100_ctx.cons.terminal_wid == in z_shell_cursor_in_empty_line()
64 void z_shell_op_cond_next_line(const struct shell *sh) in z_shell_op_cond_next_line() argument
66 if (z_shell_cursor_in_empty_line(sh) || full_line_cmd(sh)) { in z_shell_op_cond_next_line()
67 z_cursor_next_line_move(sh); in z_shell_op_cond_next_line()
71 void z_shell_op_cursor_position_synchronize(const struct shell *sh) in z_shell_op_cursor_position_synchronize() argument
73 struct shell_multiline_cons *cons = &sh->ctx->vt100_ctx.cons; in z_shell_op_cursor_position_synchronize()
76 z_shell_multiline_data_calc(cons, sh->ctx->cmd_buff_pos, in z_shell_op_cursor_position_synchronize()
77 sh->ctx->cmd_buff_len); in z_shell_op_cursor_position_synchronize()
83 if (full_line_cmd(sh)) { in z_shell_op_cursor_position_synchronize()
84 z_cursor_next_line_move(sh); in z_shell_op_cursor_position_synchronize()
88 z_shell_op_cursor_horiz_move(sh, cons->cur_x - in z_shell_op_cursor_position_synchronize()
91 z_shell_op_cursor_vert_move(sh, cons->cur_y_end - cons->cur_y); in z_shell_op_cursor_position_synchronize()
92 z_shell_op_cursor_horiz_move(sh, cons->cur_x - in z_shell_op_cursor_position_synchronize()
97 void z_shell_op_cursor_move(const struct shell *sh, int16_t val) in z_shell_op_cursor_move() argument
99 struct shell_multiline_cons *cons = &sh->ctx->vt100_ctx.cons; in z_shell_op_cursor_move()
100 uint16_t new_pos = sh->ctx->cmd_buff_pos + val; in z_shell_op_cursor_move()
104 z_shell_multiline_data_calc(cons, sh->ctx->cmd_buff_pos, in z_shell_op_cursor_move()
105 sh->ctx->cmd_buff_len); in z_shell_op_cursor_move()
109 &sh->ctx->vt100_ctx.cons, in z_shell_op_cursor_move()
110 sh->ctx->cmd_buff_pos, in z_shell_op_cursor_move()
113 &sh->ctx->vt100_ctx.cons, in z_shell_op_cursor_move()
114 sh->ctx->cmd_buff_pos, in z_shell_op_cursor_move()
117 z_shell_op_cursor_vert_move(sh, -row_span); in z_shell_op_cursor_move()
118 z_shell_op_cursor_horiz_move(sh, col_span); in z_shell_op_cursor_move()
119 sh->ctx->cmd_buff_pos = new_pos; in z_shell_op_cursor_move()
147 void z_shell_op_cursor_word_move(const struct shell *sh, int16_t val) in z_shell_op_cursor_word_move() argument
160 shift = shift_calc(sh->ctx->cmd_buff, in z_shell_op_cursor_word_move()
161 sh->ctx->cmd_buff_pos, in z_shell_op_cursor_word_move()
162 sh->ctx->cmd_buff_len, sign); in z_shell_op_cursor_word_move()
163 z_shell_op_cursor_move(sh, sign * shift); in z_shell_op_cursor_word_move()
167 void z_shell_op_word_remove(const struct shell *sh) in z_shell_op_word_remove() argument
170 if ((sh->ctx->cmd_buff_len == 0) || in z_shell_op_word_remove()
171 (sh->ctx->cmd_buff_pos == 0)) { in z_shell_op_word_remove()
175 char *str = &sh->ctx->cmd_buff[sh->ctx->cmd_buff_pos - 1]; in z_shell_op_word_remove()
176 char *str_start = &sh->ctx->cmd_buff[0]; in z_shell_op_word_remove()
195 sh->ctx->cmd_buff_len - chars_to_delete); in z_shell_op_word_remove()
196 sh->ctx->cmd_buff_len -= chars_to_delete; in z_shell_op_word_remove()
197 sh->ctx->cmd_buff[sh->ctx->cmd_buff_len] = '\0'; in z_shell_op_word_remove()
200 z_shell_op_cursor_move(sh, -chars_to_delete); in z_shell_op_word_remove()
201 z_cursor_save(sh); in z_shell_op_word_remove()
202 z_shell_fprintf(sh, SHELL_NORMAL, "%s", str + 1); in z_shell_op_word_remove()
203 z_clear_eos(sh); in z_shell_op_word_remove()
204 z_cursor_restore(sh); in z_shell_op_word_remove()
207 void z_shell_op_cursor_home_move(const struct shell *sh) in z_shell_op_cursor_home_move() argument
209 z_shell_op_cursor_move(sh, -sh->ctx->cmd_buff_pos); in z_shell_op_cursor_home_move()
212 void z_shell_op_cursor_end_move(const struct shell *sh) in z_shell_op_cursor_end_move() argument
214 z_shell_op_cursor_move(sh, sh->ctx->cmd_buff_len - in z_shell_op_cursor_end_move()
215 sh->ctx->cmd_buff_pos); in z_shell_op_cursor_end_move()
218 void z_shell_op_left_arrow(const struct shell *sh) in z_shell_op_left_arrow() argument
220 if (sh->ctx->cmd_buff_pos > 0) { in z_shell_op_left_arrow()
221 z_shell_op_cursor_move(sh, -1); in z_shell_op_left_arrow()
225 void z_shell_op_right_arrow(const struct shell *sh) in z_shell_op_right_arrow() argument
227 if (sh->ctx->cmd_buff_pos < sh->ctx->cmd_buff_len) { in z_shell_op_right_arrow()
228 z_shell_op_cursor_move(sh, 1); in z_shell_op_right_arrow()
232 static void reprint_from_cursor(const struct shell *sh, uint16_t diff, in reprint_from_cursor() argument
243 z_clear_eos(sh); in reprint_from_cursor()
246 if (z_flag_obscure_get(sh)) { in reprint_from_cursor()
247 int len = strlen(&sh->ctx->cmd_buff[sh->ctx->cmd_buff_pos]); in reprint_from_cursor()
250 z_shell_raw_fprintf(sh->fprintf_ctx, "*"); in reprint_from_cursor()
253 z_shell_fprintf(sh, SHELL_NORMAL, "%s", in reprint_from_cursor()
254 &sh->ctx->cmd_buff[sh->ctx->cmd_buff_pos]); in reprint_from_cursor()
256 sh->ctx->cmd_buff_pos = sh->ctx->cmd_buff_len; in reprint_from_cursor()
258 if (full_line_cmd(sh)) { in reprint_from_cursor()
260 z_cursor_next_line_move(sh); in reprint_from_cursor()
264 z_shell_op_cursor_move(sh, -diff); in reprint_from_cursor()
267 static void data_insert(const struct shell *sh, const char *data, uint16_t len) in data_insert() argument
269 uint16_t after = sh->ctx->cmd_buff_len - sh->ctx->cmd_buff_pos; in data_insert()
270 char *curr_pos = &sh->ctx->cmd_buff[sh->ctx->cmd_buff_pos]; in data_insert()
272 if ((sh->ctx->cmd_buff_len + len) >= CONFIG_SHELL_CMD_BUFF_SIZE) { in data_insert()
278 sh->ctx->cmd_buff_len += len; in data_insert()
279 sh->ctx->cmd_buff[sh->ctx->cmd_buff_len] = '\0'; in data_insert()
281 if (!z_flag_echo_get(sh)) { in data_insert()
282 sh->ctx->cmd_buff_pos += len; in data_insert()
286 reprint_from_cursor(sh, after, false); in data_insert()
289 static void char_replace(const struct shell *sh, char data) in char_replace() argument
291 sh->ctx->cmd_buff[sh->ctx->cmd_buff_pos++] = data; in char_replace()
293 if (!z_flag_echo_get(sh)) { in char_replace()
296 if (z_flag_obscure_get(sh)) { in char_replace()
300 z_shell_raw_fprintf(sh->fprintf_ctx, "%c", data); in char_replace()
301 if (z_shell_cursor_in_empty_line(sh)) { in char_replace()
302 z_cursor_next_line_move(sh); in char_replace()
306 void z_shell_op_char_insert(const struct shell *sh, char data) in z_shell_op_char_insert() argument
308 if (z_flag_insert_mode_get(sh) && in z_shell_op_char_insert()
309 (sh->ctx->cmd_buff_len != sh->ctx->cmd_buff_pos)) { in z_shell_op_char_insert()
310 char_replace(sh, data); in z_shell_op_char_insert()
312 data_insert(sh, &data, 1); in z_shell_op_char_insert()
316 void z_shell_op_char_backspace(const struct shell *sh) in z_shell_op_char_backspace() argument
318 if ((sh->ctx->cmd_buff_len == 0) || in z_shell_op_char_backspace()
319 (sh->ctx->cmd_buff_pos == 0)) { in z_shell_op_char_backspace()
323 z_shell_op_cursor_move(sh, -1); in z_shell_op_char_backspace()
324 z_shell_op_char_delete(sh); in z_shell_op_char_backspace()
327 void z_shell_op_char_delete(const struct shell *sh) in z_shell_op_char_delete() argument
329 uint16_t diff = sh->ctx->cmd_buff_len - sh->ctx->cmd_buff_pos; in z_shell_op_char_delete()
330 char *str = &sh->ctx->cmd_buff[sh->ctx->cmd_buff_pos]; in z_shell_op_char_delete()
337 --sh->ctx->cmd_buff_len; in z_shell_op_char_delete()
338 reprint_from_cursor(sh, --diff, true); in z_shell_op_char_delete()
341 void z_shell_op_delete_from_cursor(const struct shell *sh) in z_shell_op_delete_from_cursor() argument
343 sh->ctx->cmd_buff_len = sh->ctx->cmd_buff_pos; in z_shell_op_delete_from_cursor()
344 sh->ctx->cmd_buff[sh->ctx->cmd_buff_pos] = '\0'; in z_shell_op_delete_from_cursor()
346 z_clear_eos(sh); in z_shell_op_delete_from_cursor()
349 void z_shell_op_completion_insert(const struct shell *sh, in z_shell_op_completion_insert() argument
353 data_insert(sh, compl, compl_len); in z_shell_op_completion_insert()
356 void z_shell_cmd_line_erase(const struct shell *sh) in z_shell_cmd_line_erase() argument
358 z_shell_multiline_data_calc(&sh->ctx->vt100_ctx.cons, in z_shell_cmd_line_erase()
359 sh->ctx->cmd_buff_pos, in z_shell_cmd_line_erase()
360 sh->ctx->cmd_buff_len); in z_shell_cmd_line_erase()
361 z_shell_op_cursor_horiz_move(sh, in z_shell_cmd_line_erase()
362 -(sh->ctx->vt100_ctx.cons.cur_x - 1)); in z_shell_cmd_line_erase()
363 z_shell_op_cursor_vert_move(sh, sh->ctx->vt100_ctx.cons.cur_y - 1); in z_shell_cmd_line_erase()
365 z_clear_eos(sh); in z_shell_cmd_line_erase()
368 static void print_prompt(const struct shell *sh) in print_prompt() argument
370 z_shell_fprintf(sh, SHELL_INFO, "%s", sh->ctx->prompt); in print_prompt()
373 void z_shell_print_cmd(const struct shell *sh) in z_shell_print_cmd() argument
377 int cmd_width = z_shell_strlen(sh->ctx->cmd_buff); in z_shell_print_cmd()
378 int adjust = sh->ctx->vt100_ctx.cons.name_len; in z_shell_print_cmd()
381 while (cmd_width > sh->ctx->vt100_ctx.cons.terminal_wid - adjust) { in z_shell_print_cmd()
382 end_offset += sh->ctx->vt100_ctx.cons.terminal_wid - adjust; in z_shell_print_cmd()
383 ch = sh->ctx->cmd_buff[end_offset]; in z_shell_print_cmd()
384 sh->ctx->cmd_buff[end_offset] = '\0'; in z_shell_print_cmd()
386 z_shell_raw_fprintf(sh->fprintf_ctx, "%s\n", in z_shell_print_cmd()
387 &sh->ctx->cmd_buff[beg_offset]); in z_shell_print_cmd()
389 sh->ctx->cmd_buff[end_offset] = ch; in z_shell_print_cmd()
390 cmd_width -= (sh->ctx->vt100_ctx.cons.terminal_wid - adjust); in z_shell_print_cmd()
395 z_shell_raw_fprintf(sh->fprintf_ctx, "%s", in z_shell_print_cmd()
396 &sh->ctx->cmd_buff[beg_offset]); in z_shell_print_cmd()
400 void z_shell_print_prompt_and_cmd(const struct shell *sh) in z_shell_print_prompt_and_cmd() argument
402 print_prompt(sh); in z_shell_print_prompt_and_cmd()
404 if (z_flag_echo_get(sh)) { in z_shell_print_prompt_and_cmd()
405 z_shell_print_cmd(sh); in z_shell_print_prompt_and_cmd()
406 z_shell_op_cursor_position_synchronize(sh); in z_shell_print_prompt_and_cmd()
410 static void shell_pend_on_txdone(const struct shell *sh) in shell_pend_on_txdone() argument
413 (sh->ctx->state < SHELL_STATE_PANIC_MODE_ACTIVE)) { in shell_pend_on_txdone()
419 &sh->ctx->signals[SHELL_SIGNAL_TXDONE]); in shell_pend_on_txdone()
421 k_poll_signal_reset(&sh->ctx->signals[SHELL_SIGNAL_TXDONE]); in shell_pend_on_txdone()
424 while (!z_flag_tx_rdy_get(sh)) { in shell_pend_on_txdone()
426 z_flag_tx_rdy_set(sh, false); in shell_pend_on_txdone()
430 void z_shell_write(const struct shell *sh, const void *data, in z_shell_write() argument
433 __ASSERT_NO_MSG(sh && data); in z_shell_write()
439 int err = sh->iface->api->write(sh->iface, in z_shell_write()
448 (sh->ctx->state != SHELL_STATE_PANIC_MODE_ACTIVE)) { in z_shell_write()
449 shell_pend_on_txdone(sh); in z_shell_write()
460 static void vt100_bgcolor_set(const struct shell *sh, in vt100_bgcolor_set() argument
472 (sh->ctx->vt100_ctx.col.bgcol == bgcolor)) { in vt100_bgcolor_set()
476 sh->ctx->vt100_ctx.col.bgcol = bgcolor; in vt100_bgcolor_set()
477 Z_SHELL_VT100_CMD(sh, "\e[403%dm", bgcolor); in vt100_bgcolor_set()
480 void z_shell_vt100_color_set(const struct shell *sh, in z_shell_vt100_color_set() argument
491 if (sh->ctx->vt100_ctx.col.col == color) { in z_shell_vt100_color_set()
495 sh->ctx->vt100_ctx.col.col = color; in z_shell_vt100_color_set()
498 Z_SHELL_VT100_CMD(sh, "\e[1;3%dm", color); in z_shell_vt100_color_set()
500 Z_SHELL_VT100_CMD(sh, SHELL_VT100_MODESOFF); in z_shell_vt100_color_set()
504 void z_shell_vt100_colors_restore(const struct shell *sh, in z_shell_vt100_colors_restore() argument
511 z_shell_vt100_color_set(sh, color->col); in z_shell_vt100_colors_restore()
512 vt100_bgcolor_set(sh, color->bgcol); in z_shell_vt100_colors_restore()
515 void z_shell_vfprintf(const struct shell *sh, enum shell_vt100_color color, in z_shell_vfprintf() argument
519 z_flag_use_colors_get(sh) && in z_shell_vfprintf()
520 (color != sh->ctx->vt100_ctx.col.col)) { in z_shell_vfprintf()
523 z_shell_vt100_colors_store(sh, &col); in z_shell_vfprintf()
524 z_shell_vt100_color_set(sh, color); in z_shell_vfprintf()
526 z_shell_fprintf_fmt(sh->fprintf_ctx, fmt, args); in z_shell_vfprintf()
528 z_shell_vt100_colors_restore(sh, &col); in z_shell_vfprintf()
530 z_shell_fprintf_fmt(sh->fprintf_ctx, fmt, args); in z_shell_vfprintf()
534 void z_shell_fprintf(const struct shell *sh, in z_shell_fprintf() argument
538 __ASSERT_NO_MSG(sh); in z_shell_fprintf()
539 __ASSERT_NO_MSG(sh->ctx); in z_shell_fprintf()
540 __ASSERT_NO_MSG(sh->fprintf_ctx); in z_shell_fprintf()
542 __ASSERT(z_flag_sync_mode_get(sh) || !k_is_in_isr(), in z_shell_fprintf()
548 z_shell_vfprintf(sh, color, fmt, args); in z_shell_fprintf()
552 void z_shell_backend_rx_buffer_flush(const struct shell *sh) in z_shell_backend_rx_buffer_flush() argument
554 __ASSERT_NO_MSG(sh); in z_shell_backend_rx_buffer_flush()
562 err = sh->iface->api->read(sh->iface, buf, sizeof(buf), &count); in z_shell_backend_rx_buffer_flush()