Archeus 0.0.0
A C library and game engine that focuses on documentation
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_StringARC_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
shellthe ARC_ConsoleShell to add history to
stringthe history string to add to ARC_ConsoleShell

Definition at line 46 of file shell.c.

46 {
47 ARC_Vector_Add(shell->history, (void *)string);
48}
ARC_Vector * history
Definition shell.h:34
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
shellARC_ConsoleShell to create
viewARC_ConsoleView to attach the shell to
updateFnARC_ConsoleShell_UpdateFn provided that will run the console

Definition at line 8 of file shell.c.

8 {
9 *shell = (ARC_ConsoleShell *)malloc(sizeof(ARC_ConsoleShell));
10
11 (*shell)->view = view;
12 ARC_ConsoleBuffer_Create(&((*shell)->buffer));
13 (*shell)->bufferLineIndex = 0;
14
15 ARC_Vector_Create(&((*shell)->history));
16 (*shell)->historyIndex = 0;
17
18 (*shell)->updateFn = updateFn;
19 (*shell)->currentLine = NULL;
20 (*shell)->userInput = NULL;
21}
void ARC_ConsoleBuffer_Create(ARC_ConsoleBuffer **buffer)
creates ARC_ConsoleBuffer type
Definition buffer.c:13
ARC_ConsoleView * view
Definition shell.h:30
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
shellARC_ConsoleShell to destroy

Definition at line 23 of file shell.c.

23 {
25
26 for(uint32_t i = 0; i < ARC_Vector_Size(shell->history); i++){
27 ARC_String *temp = (ARC_String *)ARC_Vector_Get(shell->history, i);
28
29 if(temp != NULL){
31 }
32 }
33
35 free(shell);
36}
void ARC_ConsoleBuffer_Destroy(ARC_ConsoleBuffer *buffer)
destroys ARC_ConsoleBuffer type
Definition buffer.c:22
void ARC_String_Destroy(ARC_String *string)
destroys ARC_String type
Definition string.c:52
ARC_ConsoleBuffer * buffer
Definition shell.h:31
substring position within a string
Definition string.h:14
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
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
shellthe ARC_ConsoleShell to get history from
indexthe location to get history at
Returns
the history as an ARC_String

Definition at line 50 of file shell.c.

50 {
51 uint32_t maxHistory = ARC_Vector_Size(shell->history);
52 if(index >= maxHistory){
53 return NULL;
54 }
55
56 return (ARC_String *)ARC_Vector_Get(shell->history, (maxHistory - 1) - index);
57}

References ARC_Vector_Get(), and ARC_ConsoleShell::history.

◆ ARC_ConsoleShell_Render()

void ARC_ConsoleShell_Render ( ARC_ConsoleShell * shell)

renders the ARC_ConsoleShell type

Parameters
shellthe ARC_ConsoleShell to render

Definition at line 42 of file shell.c.

42 {
43 ARC_ConsoleBuffer_Render(shell->buffer, shell->view);
44}
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
shellthe ARC_ConsoleShell to update

Definition at line 38 of file shell.c.

38 {
39 shell->updateFn(shell);
40}
ARC_ConsoleShell_UpdateFn updateFn
Definition shell.h:37

References ARC_ConsoleShell::updateFn.