Skip to content

File wsh_shell_history.c

FileList > src > wsh_shell_history.c

Go to the source code of this file

  • #include "wsh_shell_history.h"

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.

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.c