Loading...
Searching...
No Matches
shell.c File Reference
`#include "arc/console/shell.h"`
`#include "arc/console/buffer.h"`
`#include "arc/std/string.h"`
`#include "arc/std/vector.h"`
`#include <stdlib.h>`

Go to the source code of this file.

## Functions

void | ARC_ConsoleShell_Create (ARC_ConsoleShell **shell, ARC_ConsoleView *view, ARC_ConsoleShell_UpdateFn updateFn)
| creates ARC_ConsoleShell type
void | ARC_ConsoleShell_Destroy (ARC_ConsoleShell *shell)
| destroys ARC_ConsoleShell type
void | ARC_ConsoleShell_Update (ARC_ConsoleShell *shell)
| updates the ARC_ConsoleShell type
void | ARC_ConsoleShell_Render (ARC_ConsoleShell *shell)
| renders the ARC_ConsoleShell type
void | ARC_ConsoleShell_AddHistory (ARC_ConsoleShell *shell, ARC_String *string)
| adds history ARC_String to ARC_ConsoleShell
ARC_String * | ARC_ConsoleShell_GetHistoryAt (ARC_ConsoleShell *shell, uint32_t index)
| gets history from ARC_ConsoleShell

## Function Documentation

## ARC_ConsoleShell_AddHistory()

void ARC_ConsoleShell_AddHistory | ( | ARC_ConsoleShell * | shell,
|  | ARC_String * | string )

adds history ARC_String to ARC_ConsoleShell

Parameters

  shell | the ARC_ConsoleShell to add history to
  string | the history string to add to ARC_ConsoleShell

Definition at line 46 of file shell.c.

{
ARC_Vector_Add(shell->history, (void *)string);
}
ARC_ConsoleShell::history
ARC_Vector * history
Definition shell.h:34
ARC_Vector_Add
void ARC_Vector_Add(ARC_Vector *vector, void *data)
adds an item to an ARC_Vector
Definition vector.c:70

References ARC_Vector_Add(), and ARC_ConsoleShell::history.

## ARC_ConsoleShell_Create()

void ARC_ConsoleShell_Create | ( | ARC_ConsoleShell ** | shell,
|  | ARC_ConsoleView * | view,
|  | ARC_ConsoleShell_UpdateFn | updateFn )

creates ARC_ConsoleShell type

Parameters

  shell | ARC_ConsoleShell to create
  view | ARC_ConsoleView to attach the shell to
  updateFn | ARC_ConsoleShell_UpdateFn provided that will run the console

Definition at line 8 of file shell.c.

{
*shell = (ARC_ConsoleShell *)malloc(sizeof(ARC_ConsoleShell));
(*shell)->view = view;
ARC_ConsoleBuffer_Create(&((*shell)->buffer));
(*shell)->bufferLineIndex = 0;
ARC_Vector_Create(&((*shell)->history));
(*shell)->historyIndex = 0;
(*shell)->updateFn = updateFn;
(*shell)->currentLine = NULL;
(*shell)->userInput = NULL;
}
ARC_ConsoleBuffer_Create
void ARC_ConsoleBuffer_Create(ARC_ConsoleBuffer **buffer)
creates ARC_ConsoleBuffer type
Definition buffer.c:13
ARC_ConsoleShell
Definition shell.h:29
ARC_ConsoleShell::view
ARC_ConsoleView * view
Definition shell.h:30
ARC_Vector_Create
void ARC_Vector_Create(ARC_Vector **vector, ARC_Vector_CompareDataFn *compareDataFn, ARC_Vector_DestroyDataFn *destroyDataFn)
creates an ARC_Vector which is an "expandable" array
Definition vector.c:31

References ARC_ConsoleBuffer_Create(), ARC_Vector_Create(), and ARC_ConsoleShell::view.

## ARC_ConsoleShell_Destroy()

void ARC_ConsoleShell_Destroy | ( | ARC_ConsoleShell * | shell | ) |

destroys ARC_ConsoleShell type

Parameters

  shell | ARC_ConsoleShell to destroy

Definition at line 23 of file shell.c.

{
ARC_ConsoleBuffer_Destroy(shell->buffer);
for(uint32_t i = 0; i < ARC_Vector_Size(shell->history); i++){
ARC_String *temp = (ARC_String *)ARC_Vector_Get(shell->history, i);
if(temp != NULL){
ARC_String_Destroy(temp);
}
}
ARC_Vector_Destroy(shell->history);
free(shell);
}
ARC_ConsoleBuffer_Destroy
void ARC_ConsoleBuffer_Destroy(ARC_ConsoleBuffer *buffer)
destroys ARC_ConsoleBuffer type
Definition buffer.c:22
ARC_String_Destroy
void ARC_String_Destroy(ARC_String *string)
destroys ARC_String type
Definition string.c:52
ARC_ConsoleShell::buffer
ARC_ConsoleBuffer * buffer
Definition shell.h:31
ARC_String
substring position within a string
Definition string.h:14
ARC_Vector_Get
void * ARC_Vector_Get(ARC_Vector *vector, uint32_t index)
gets an item from an ARC_Vector at a position index
Definition vector.c:153
ARC_Vector_Destroy
void ARC_Vector_Destroy(ARC_Vector *vector)
destroys an ARC_Vector
Definition vector.c:54

References ARC_ConsoleBuffer_Destroy(), ARC_String_Destroy(), ARC_Vector_Destroy(), ARC_Vector_Get(), ARC_ConsoleShell::buffer, and ARC_ConsoleShell::history.

## ARC_ConsoleShell_GetHistoryAt()

ARC_String * ARC_ConsoleShell_GetHistoryAt | ( | ARC_ConsoleShell * | shell,
|  | uint32_t | index )

gets history from ARC_ConsoleShell

Note
  the index 0 will start from the last added history

Parameters

  shell | the ARC_ConsoleShell to get history from
  index | the location to get history at

Returns
  the history as an ARC_String

Definition at line 50 of file shell.c.

{
uint32_t maxHistory = ARC_Vector_Size(shell->history);
if(index >= maxHistory){
return NULL;
}
return (ARC_String *)ARC_Vector_Get(shell->history, (maxHistory - 1) - index);
}

References ARC_Vector_Get(), and ARC_ConsoleShell::history.

## ARC_ConsoleShell_Render()

void ARC_ConsoleShell_Render | ( | ARC_ConsoleShell * | shell | ) |

renders the ARC_ConsoleShell type

Parameters

  shell | the ARC_ConsoleShell to render

Definition at line 42 of file shell.c.

{
ARC_ConsoleBuffer_Render(shell->buffer, shell->view);
}
ARC_ConsoleBuffer_Render
void ARC_ConsoleBuffer_Render(ARC_ConsoleBuffer *buffer, ARC_ConsoleView *view)
renders a buffer to a ARC_ConsoleView
Definition buffer.c:51

References ARC_ConsoleBuffer_Render(), ARC_ConsoleShell::buffer, and ARC_ConsoleShell::view.

## ARC_ConsoleShell_Update()

void ARC_ConsoleShell_Update | ( | ARC_ConsoleShell * | shell | ) |

updates the ARC_ConsoleShell type

Parameters

  shell | the ARC_ConsoleShell to update

Definition at line 38 of file shell.c.

{
shell->updateFn(shell);
}
ARC_ConsoleShell::updateFn
ARC_ConsoleShell_UpdateFn updateFn
Definition shell.h:37

References ARC_ConsoleShell::updateFn.