Skip to content

File wsh_shell_history.h

FileList > src > wsh_shell_history.h

Go to the source code of this file

Shell history management API. More...

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

Classes

Type Name
struct WshShellHistory_Data_t
Internal structure for storing command history buffer.
struct WshShellHistory_IO_t
Structure holding function pointers for history persistence I/O.
struct WshShellHistory_t
Shell history structure with integrity check.

Public Types

Type Name
enum WSH_SHELL_HIST_CMD_DIR_t
Direction for history navigation.
typedef WshShellHistory_t(* WshShellHistory_ReadHandler_t
Function pointer type for reading shell history from persistent storage.
typedef void(* WshShellHistory_WriteHandler_t
Function pointer type for writing shell history to persistent storage.

Public Functions

Type Name
void WshShellHistory_Flush (WshShellHistory_IO_t * pHistIO)
Clear the command history buffer.
WshShell_Size_t WshShellHistory_GetNextCmd (WshShellHistory_IO_t * pHistIO, WshShell_Char_t * pOutBuff, WshShell_Size_t outBuffSize)
Retrieve the next command from history.
WshShell_Size_t WshShellHistory_GetPrevCmd (WshShellHistory_IO_t * pHistIO, WshShell_Char_t * pOutBuff, WshShell_Size_t outBuffSize)
Retrieve the previous command from history.
WshShell_Size_t WshShellHistory_GetTokenByIndex (WshShellHistory_IO_t * pHistIO, WshShell_Char_t * pOutBuff, WshShell_Size_t outBuffSize, WshShell_Size_t index)
Retrieve a command from history by its index.
WshShell_Size_t WshShellHistory_GetTokenNum (WshShellHistory_IO_t * pHistIO)
Get the total number of commands stored in history.
void WshShellHistory_Init (WshShellHistory_IO_t * pHistIO, WshShellHistory_ReadHandler_t readFn, WshShellHistory_WriteHandler_t writeFn)
Initialize the shell history system with custom I/O functions.
void WshShellHistory_SaveCmd (WshShellHistory_IO_t * pHistIO, const WshShell_Char_t * pcCmdStr, WshShell_Size_t cmdStrLen)
Save a new command to the history buffer.

Detailed Description

This module provides functionality for storing, navigating, and persisting command history in an embedded shell environment.

Author:

Whoosh Embedded Team

Copyright:

Copyright (c) 2025

Public Types Documentation

enum WSH_SHELL_HIST_CMD_DIR_t

Direction for history navigation.

1
2
3
4
enum WSH_SHELL_HIST_CMD_DIR_t {
    WSH_SHELL_HIST_CMD_PREV = 0,
    WSH_SHELL_HIST_CMD_NEXT
};


typedef WshShellHistory_ReadHandler_t

Function pointer type for reading shell history from persistent storage.

typedef WshShellHistory_t(* WshShellHistory_ReadHandler_t) (void);


typedef WshShellHistory_WriteHandler_t

Function pointer type for writing shell history to persistent storage.

typedef void(* WshShellHistory_WriteHandler_t) (WshShellHistory_t);


Public Functions Documentation

function WshShellHistory_Flush

Clear the command history buffer.

1
2
3
void WshShellHistory_Flush (
    WshShellHistory_IO_t * pHistIO
) 

Parameters:

  • pHistIO Pointer to the I/O structure.

function WshShellHistory_GetNextCmd

Retrieve the next command from history.

1
2
3
4
5
WshShell_Size_t WshShellHistory_GetNextCmd (
    WshShellHistory_IO_t * pHistIO,
    WshShell_Char_t * pOutBuff,
    WshShell_Size_t outBuffSize
) 

Parameters:

  • pHistIO Pointer to the I/O structure.
  • pOutBuff Buffer to store the command string.
  • outBuffSize Size of the output buffer.

Returns:

Length of the retrieved command.


function WshShellHistory_GetPrevCmd

Retrieve the previous command from history.

1
2
3
4
5
WshShell_Size_t WshShellHistory_GetPrevCmd (
    WshShellHistory_IO_t * pHistIO,
    WshShell_Char_t * pOutBuff,
    WshShell_Size_t outBuffSize
) 

Parameters:

  • pHistIO Pointer to the I/O structure.
  • pOutBuff Buffer to store the command string.
  • outBuffSize Size of the output buffer.

Returns:

Length of the retrieved command.


function WshShellHistory_GetTokenByIndex

Retrieve a command from history by its index.

1
2
3
4
5
6
WshShell_Size_t WshShellHistory_GetTokenByIndex (
    WshShellHistory_IO_t * pHistIO,
    WshShell_Char_t * pOutBuff,
    WshShell_Size_t outBuffSize,
    WshShell_Size_t index
) 

Index 0 corresponds to the most recently saved command, index 1 to the previous one, and so on.

Parameters:

  • pHistIO Pointer to the I/O structure.
  • pOutBuff Buffer to store the retrieved command.
  • outBuffSize Size of the output buffer.
  • index Index of the command to retrieve (0 = latest).

Returns:

Length of the retrieved command, or 0 if not found or buffer too small.


function WshShellHistory_GetTokenNum

Get the total number of commands stored in history.

1
2
3
WshShell_Size_t WshShellHistory_GetTokenNum (
    WshShellHistory_IO_t * pHistIO
) 

Starts from the most recently saved command and iterates backwards through the history buffer to count all stored commands.

Parameters:

  • pHistIO Pointer to the I/O structure.

Returns:

Number of stored commands in history.


function WshShellHistory_Init

Initialize the shell history system with custom I/O functions.

1
2
3
4
5
void WshShellHistory_Init (
    WshShellHistory_IO_t * pHistIO,
    WshShellHistory_ReadHandler_t readFn,
    WshShellHistory_WriteHandler_t writeFn
) 

This function sets up the internal history system and loads existing history using the provided read/write callbacks.

Parameters:

  • pHistIO Pointer to the I/O structure used for read/write access.
  • readFn Callback to read saved history data.
  • writeFn Callback to persist current history data.

function WshShellHistory_SaveCmd

Save a new command to the history buffer.

1
2
3
4
5
void WshShellHistory_SaveCmd (
    WshShellHistory_IO_t * pHistIO,
    const WshShell_Char_t * pcCmdStr,
    WshShell_Size_t cmdStrLen
) 

Parameters:

  • pHistIO Pointer to the I/O structure.
  • pcCmdStr Pointer to the command string (without EOL).
  • cmdStrLen Length of the command string.


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