Skip to content

File wsh_shell_io.h

FileList > src > wsh_shell_io.h

Go to the source code of this file

Terminal input/output definitions and interaction buffer API for WshShell. More...

  • #include "wsh_shell_cfg.h"
  • #include "wsh_shell_str.h"

Classes

Type Name
struct WshShellIO_CommandLine_t
Structure representing the current user input interaction state.

Public Types

Type Name
enum WSH_SHELL_PRINT_t
Shell print levels.

Public Functions

Type Name
void WshShellIO_ClearInterBuff (WshShellIO_CommandLine_t * pCommandLine)
Clears the interaction buffer.
void WshShellIO_InsertSymbol (WshShellIO_CommandLine_t * pCommandLine, WshShell_Char_t ch, WshShell_Bool_t starsOrChars)
Inserts a symbol at the current cursor position in the input buffer.
void WshShellIO_PrintInterBuff (WshShellIO_CommandLine_t * pCommandLine)
Prints the current interaction buffer to the terminal.
void WshShellIO_RefreshConsoleFromInterBuff (WshShellIO_CommandLine_t * pCommandLine)
Refreshes the terminal display using the interaction buffer.
void WshShellIO_RemoveLeftSymbol (WshShellIO_CommandLine_t * pCommandLine)
Removes the symbol to the left of the cursor in the input buffer.
void WshShellIO_WriteToInterBuff (WshShellIO_CommandLine_t * pCommandLine, WshShell_Char_t symbol)
Writes a character into the interaction buffer at the cursor position.

Macros

Type Name
define WSH_SHELL_CHAR_CR '\r'
define WSH_SHELL_CHAR_LF '\n'
define WSH_SHELL_COLOR_BLACK [**WSH\_SHELL\_ESC\_SEQ\_START\_STR**](wsh__shell__io_8h.md#define-wsh_shell_esc_seq_start_str) "[30m"
define WSH_SHELL_COLOR_BLUE [**WSH\_SHELL\_ESC\_SEQ\_START\_STR**](wsh__shell__io_8h.md#define-wsh_shell_esc_seq_start_str) "[34m"
define WSH_SHELL_COLOR_CYAN [**WSH\_SHELL\_ESC\_SEQ\_START\_STR**](wsh__shell__io_8h.md#define-wsh_shell_esc_seq_start_str) "[36m"
define WSH_SHELL_COLOR_ERROR WSH\_SHELL\_COLOR\_RED
define WSH_SHELL_COLOR_GREEN [**WSH\_SHELL\_ESC\_SEQ\_START\_STR**](wsh__shell__io_8h.md#define-wsh_shell_esc_seq_start_str) "[32m"
define WSH_SHELL_COLOR_INFO WSH\_SHELL\_COLOR\_WHITE
define WSH_SHELL_COLOR_OK WSH\_SHELL\_COLOR\_GREEN
define WSH_SHELL_COLOR_PURPLE [**WSH\_SHELL\_ESC\_SEQ\_START\_STR**](wsh__shell__io_8h.md#define-wsh_shell_esc_seq_start_str) "[35m"
define WSH_SHELL_COLOR_RED [**WSH\_SHELL\_ESC\_SEQ\_START\_STR**](wsh__shell__io_8h.md#define-wsh_shell_esc_seq_start_str) "[31m"
define WSH_SHELL_COLOR_SYS WSH\_SHELL\_COLOR\_CYAN
define WSH_SHELL_COLOR_WARN WSH\_SHELL\_COLOR\_YELLOW
define WSH_SHELL_COLOR_WHITE [**WSH\_SHELL\_ESC\_SEQ\_START\_STR**](wsh__shell__io_8h.md#define-wsh_shell_esc_seq_start_str) "[37m"
define WSH_SHELL_COLOR_YELLOW [**WSH\_SHELL\_ESC\_SEQ\_START\_STR**](wsh__shell__io_8h.md#define-wsh_shell_esc_seq_start_str) "[33m"
define WSH_SHELL_ECS_CLR_SCREEN [**WSH\_SHELL\_ESC\_SEQ\_START\_STR**](wsh__shell__io_8h.md#define-wsh_shell_esc_seq_start_str) "[1;1H" WSH\_SHELL\_ESC\_SEQ\_START\_STR "[2J"
define WSH_SHELL_ECS_RESET_MODE_BOLD [**WSH\_SHELL\_ESC\_SEQ\_START\_STR**](wsh__shell__io_8h.md#define-wsh_shell_esc_seq_start_str) "[22m"
define WSH_SHELL_ECS_RESET_MODE_ITALIC [**WSH\_SHELL\_ESC\_SEQ\_START\_STR**](wsh__shell__io_8h.md#define-wsh_shell_esc_seq_start_str) "[23m"
define WSH_SHELL_ECS_SET_MODE_BOLD [**WSH\_SHELL\_ESC\_SEQ\_START\_STR**](wsh__shell__io_8h.md#define-wsh_shell_esc_seq_start_str) "[1m"
define WSH_SHELL_ECS_SET_MODE_ITALIC [**WSH\_SHELL\_ESC\_SEQ\_START\_STR**](wsh__shell__io_8h.md#define-wsh_shell_esc_seq_start_str) "[3m"
define WSH_SHELL_END_LINE "\r\n"
define WSH_SHELL_ESC_ARROW_DOWN [**WSH\_SHELL\_ESC\_SEQ\_START\_STR**](wsh__shell__io_8h.md#define-wsh_shell_esc_seq_start_str) "[B"
define WSH_SHELL_ESC_ARROW_LEFT [**WSH\_SHELL\_ESC\_SEQ\_START\_STR**](wsh__shell__io_8h.md#define-wsh_shell_esc_seq_start_str) "[D"
define WSH_SHELL_ESC_ARROW_RIGHT [**WSH\_SHELL\_ESC\_SEQ\_START\_STR**](wsh__shell__io_8h.md#define-wsh_shell_esc_seq_start_str) "[C"
define WSH_SHELL_ESC_ARROW_UP [**WSH\_SHELL\_ESC\_SEQ\_START\_STR**](wsh__shell__io_8h.md#define-wsh_shell_esc_seq_start_str) "[A"
define WSH_SHELL_ESC_CLEAR_RIGHT_FROM_CURS [**WSH\_SHELL\_ESC\_SEQ\_START\_STR**](wsh__shell__io_8h.md#define-wsh_shell_esc_seq_start_str) "[0K"
define WSH_SHELL_ESC_RESET_STYLE [**WSH\_SHELL\_ESC\_SEQ\_START\_STR**](wsh__shell__io_8h.md#define-wsh_shell_esc_seq_start_str) "[0m"
define WSH_SHELL_ESC_RESTORE_CURSOR [**WSH\_SHELL\_ESC\_SEQ\_START\_STR**](wsh__shell__io_8h.md#define-wsh_shell_esc_seq_start_str) "8"
define WSH_SHELL_ESC_SAVE_CURSOR [**WSH\_SHELL\_ESC\_SEQ\_START\_STR**](wsh__shell__io_8h.md#define-wsh_shell_esc_seq_start_str) "7"
define WSH_SHELL_ESC_SEQ_START_CHAR '\033'
define WSH_SHELL_ESC_SEQ_START_STR "\033"
define WSH_SHELL_PRINT_ERR (_f_, ...)
define WSH_SHELL_PRINT_INFO (_f_, ...)
define WSH_SHELL_PRINT_LEVEL (_level_, _f_, ...) /* multi line expression */
Generic macro for printing messages with a specific level.
define WSH_SHELL_PRINT_SYS (_f_, ...)
define WSH_SHELL_PRINT_WARN (_f_, ...)
define WSH_SHELL_SYM_BACKSPACE '\b'
define WSH_SHELL_SYM_DELETE 0x7f
define WSH_SHELL_SYM_EXIT 0x04
define WSH_SHELL_SYM_SOUND 0x07
define WSH_SHELL_SYM_TAB '\t'

Detailed Description

This header provides: * Common control characters (e.g. backspace, delete, tab). * ANSI escape sequences for terminal control (cursor movement, screen clearing, text style). * Colorized print macros for various log levels (system/info/warning/error). * PS1 and newline formatting helpers. * I/O buffer structure and utility functions for handling user input.

These utilities support consistent terminal behavior and shell interaction flow.

Author:

Whoosh Embedded Team

Copyright:

Copyright (c) 2024

Public Types Documentation

enum WSH_SHELL_PRINT_t

Shell print levels.

1
2
3
4
5
6
enum WSH_SHELL_PRINT_t {
    WSH_SHELL_PRINT_SYS,
    WSH_SHELL_PRINT_INFO,
    WSH_SHELL_PRINT_WARN,
    WSH_SHELL_PRINT_ERR
};

Defines the available message levels for shell output. Used to select which type of message (system, info, warning, error, ...) should be printed when calling WSH_SHELL_PRINT_LEVEL().


Public Functions Documentation

function WshShellIO_ClearInterBuff

Clears the interaction buffer.

1
2
3
void WshShellIO_ClearInterBuff (
    WshShellIO_CommandLine_t * pCommandLine
) 

Resets buffer contents, cursor position, and line length.

Parameters:

  • pCommandLine Pointer to the interaction buffer.

function WshShellIO_InsertSymbol

Inserts a symbol at the current cursor position in the input buffer.

1
2
3
4
5
void WshShellIO_InsertSymbol (
    WshShellIO_CommandLine_t * pCommandLine,
    WshShell_Char_t ch,
    WshShell_Bool_t starsOrChars
) 

This function handles character insertion into the interaction buffer: * If the cursor is in the middle of the line (not at the end), it shifts existing characters to the right to make space for the new symbol. * The character is then written into the buffer at the cursor position using WshShellIO_WriteToInterBuff. * The terminal is updated to reflect the insertion, printing either the actual symbol or an asterisk (*) if starsOrChars is true (used for password masking).

Cursor position and buffer length are updated internally. Asserts that pCommandLine is valid and that CursorPos >= 1 before printing.

Parameters:

  • pCommandLine Pointer to the interaction buffer.
  • ch The symbol to insert.
  • starsOrChars If true, prints * instead of the actual character.

function WshShellIO_PrintInterBuff

Prints the current interaction buffer to the terminal.

1
2
3
void WshShellIO_PrintInterBuff (
    WshShellIO_CommandLine_t * pCommandLine
) 

Parameters:

  • pCommandLine Pointer to the interaction buffer.

function WshShellIO_RefreshConsoleFromInterBuff

Refreshes the terminal display using the interaction buffer.

1
2
3
void WshShellIO_RefreshConsoleFromInterBuff (
    WshShellIO_CommandLine_t * pCommandLine
) 

Clears the current line and reprints buffer contents.

Parameters:

  • pCommandLine Pointer to the interaction buffer.

function WshShellIO_RemoveLeftSymbol

Removes the symbol to the left of the cursor in the input buffer.

1
2
3
void WshShellIO_RemoveLeftSymbol (
    WshShellIO_CommandLine_t * pCommandLine
) 

This function handles backspace-like behavior: * If the cursor is not at the beginning of the line, it removes the symbol to the left of the cursor, shifts the rest of the line left, and updates both the buffer and terminal display. * If the cursor is beyond the line length (unexpected), only moves the cursor one position left.

Also updates the internal buffer length and uses ANSI escape sequences to visually update the terminal.

Parameters:

  • pCommandLine Pointer to the interaction buffer.

function WshShellIO_WriteToInterBuff

Writes a character into the interaction buffer at the cursor position.

1
2
3
4
void WshShellIO_WriteToInterBuff (
    WshShellIO_CommandLine_t * pCommandLine,
    WshShell_Char_t symbol
) 

Increments cursor and line length accordingly.

Parameters:

  • pCommandLine Pointer to the interaction buffer.
  • symbol Character to write.

Macro Definition Documentation

define WSH_SHELL_CHAR_CR

#define WSH_SHELL_CHAR_CR `'\r'`

Carriage return


define WSH_SHELL_CHAR_LF

#define WSH_SHELL_CHAR_LF `'\n'`

Line feed


define WSH_SHELL_COLOR_BLACK

#define WSH_SHELL_COLOR_BLACK `WSH_SHELL_ESC_SEQ_START_STR "[30m"`

define WSH_SHELL_COLOR_BLUE

#define WSH_SHELL_COLOR_BLUE `WSH_SHELL_ESC_SEQ_START_STR "[34m"`

define WSH_SHELL_COLOR_CYAN

#define WSH_SHELL_COLOR_CYAN `WSH_SHELL_ESC_SEQ_START_STR "[36m"`

define WSH_SHELL_COLOR_ERROR

#define WSH_SHELL_COLOR_ERROR `WSH_SHELL_COLOR_RED`

define WSH_SHELL_COLOR_GREEN

#define WSH_SHELL_COLOR_GREEN `WSH_SHELL_ESC_SEQ_START_STR "[32m"`

define WSH_SHELL_COLOR_INFO

#define WSH_SHELL_COLOR_INFO `WSH_SHELL_COLOR_WHITE`

define WSH_SHELL_COLOR_OK

#define WSH_SHELL_COLOR_OK `WSH_SHELL_COLOR_GREEN`

define WSH_SHELL_COLOR_PURPLE

#define WSH_SHELL_COLOR_PURPLE `WSH_SHELL_ESC_SEQ_START_STR "[35m"`

define WSH_SHELL_COLOR_RED

#define WSH_SHELL_COLOR_RED `WSH_SHELL_ESC_SEQ_START_STR "[31m"`

define WSH_SHELL_COLOR_SYS

#define WSH_SHELL_COLOR_SYS `WSH_SHELL_COLOR_CYAN`

define WSH_SHELL_COLOR_WARN

#define WSH_SHELL_COLOR_WARN `WSH_SHELL_COLOR_YELLOW`

define WSH_SHELL_COLOR_WHITE

#define WSH_SHELL_COLOR_WHITE `WSH_SHELL_ESC_SEQ_START_STR "[37m"`

define WSH_SHELL_COLOR_YELLOW

#define WSH_SHELL_COLOR_YELLOW `WSH_SHELL_ESC_SEQ_START_STR "[33m"`

define WSH_SHELL_ECS_CLR_SCREEN

#define WSH_SHELL_ECS_CLR_SCREEN `WSH_SHELL_ESC_SEQ_START_STR "[1;1H" WSH_SHELL_ESC_SEQ_START_STR "[2J"`

define WSH_SHELL_ECS_RESET_MODE_BOLD

#define WSH_SHELL_ECS_RESET_MODE_BOLD `WSH_SHELL_ESC_SEQ_START_STR "[22m"`

define WSH_SHELL_ECS_RESET_MODE_ITALIC

#define WSH_SHELL_ECS_RESET_MODE_ITALIC `WSH_SHELL_ESC_SEQ_START_STR "[23m"`

define WSH_SHELL_ECS_SET_MODE_BOLD

#define WSH_SHELL_ECS_SET_MODE_BOLD `WSH_SHELL_ESC_SEQ_START_STR "[1m"`

define WSH_SHELL_ECS_SET_MODE_ITALIC

#define WSH_SHELL_ECS_SET_MODE_ITALIC `WSH_SHELL_ESC_SEQ_START_STR "[3m"`

define WSH_SHELL_END_LINE

#define WSH_SHELL_END_LINE `"\r\n"`

End-of-line string


define WSH_SHELL_ESC_ARROW_DOWN

#define WSH_SHELL_ESC_ARROW_DOWN `WSH_SHELL_ESC_SEQ_START_STR "[B"`

define WSH_SHELL_ESC_ARROW_LEFT

#define WSH_SHELL_ESC_ARROW_LEFT `WSH_SHELL_ESC_SEQ_START_STR "[D"`

define WSH_SHELL_ESC_ARROW_RIGHT

#define WSH_SHELL_ESC_ARROW_RIGHT `WSH_SHELL_ESC_SEQ_START_STR "[C"`

define WSH_SHELL_ESC_ARROW_UP

#define WSH_SHELL_ESC_ARROW_UP `WSH_SHELL_ESC_SEQ_START_STR "[A"`

define WSH_SHELL_ESC_CLEAR_RIGHT_FROM_CURS

#define WSH_SHELL_ESC_CLEAR_RIGHT_FROM_CURS `WSH_SHELL_ESC_SEQ_START_STR "[0K"`

define WSH_SHELL_ESC_RESET_STYLE

#define WSH_SHELL_ESC_RESET_STYLE `WSH_SHELL_ESC_SEQ_START_STR "[0m"`

define WSH_SHELL_ESC_RESTORE_CURSOR

#define WSH_SHELL_ESC_RESTORE_CURSOR `WSH_SHELL_ESC_SEQ_START_STR "8"`

define WSH_SHELL_ESC_SAVE_CURSOR

#define WSH_SHELL_ESC_SAVE_CURSOR `WSH_SHELL_ESC_SEQ_START_STR "7"`

define WSH_SHELL_ESC_SEQ_START_CHAR

#define WSH_SHELL_ESC_SEQ_START_CHAR `'\033'`

Escape character (0x1B)


define WSH_SHELL_ESC_SEQ_START_STR

#define WSH_SHELL_ESC_SEQ_START_STR `"\033"`

Escape character as string


define WSH_SHELL_PRINT_ERR

1
2
3
4
#define WSH_SHELL_PRINT_ERR (
    _f_,
    ...
) 

define WSH_SHELL_PRINT_INFO

1
2
3
4
#define WSH_SHELL_PRINT_INFO (
    _f_,
    ...
) 

define WSH_SHELL_PRINT_LEVEL

Generic macro for printing messages with a specific level.

1
2
3
4
5
#define WSH_SHELL_PRINT_LEVEL (
    _level_,
    _f_,
    ...
) `/* multi line expression */`

Each specific print macro (e.g. WSH_SHELL_PRINT_ERR) can be disabled at compile time using corresponding flags (WSH_SHELL_PRINT_*_ENABLE).

Parameters:

  • <em>level</em> Print level (one of WSH_SHELL_PRINT_t).
  • <em>f</em> Format string (compatible with printf).
  • ... Additional arguments for the format string.
1
2
3
// Example usage:
WSH_SHELL_PRINT_LEVEL(WSH_SHELL_PRINT_INFO, "Initialization complete\n");
WSH_SHELL_PRINT_LEVEL(WSH_SHELL_PRINT_ERR, "Failed to open file: %s\n", filename);

define WSH_SHELL_PRINT_SYS

1
2
3
4
#define WSH_SHELL_PRINT_SYS (
    _f_,
    ...
) 

define WSH_SHELL_PRINT_WARN

1
2
3
4
#define WSH_SHELL_PRINT_WARN (
    _f_,
    ...
) 

define WSH_SHELL_SYM_BACKSPACE

#define WSH_SHELL_SYM_BACKSPACE `'\b'`

Backspace character


define WSH_SHELL_SYM_DELETE

#define WSH_SHELL_SYM_DELETE `0x7f`

Delete (DEL) character


define WSH_SHELL_SYM_EXIT

#define WSH_SHELL_SYM_EXIT `0x04`

Ctrl + D (EOF signal)


define WSH_SHELL_SYM_SOUND

#define WSH_SHELL_SYM_SOUND `0x07`

Bell character (alert)


define WSH_SHELL_SYM_TAB

#define WSH_SHELL_SYM_TAB `'\t'`

Tab character



The documentation for this class was generated from the following file src/wsh_shell_io.h