Archeus 0.0.0
A C library and game engine that focuses on documentation
Loading...
Searching...
No Matches
shell.c
Go to the documentation of this file.
1#include "arc/console/shell.h"
2
4#include "arc/std/string.h"
5#include "arc/std/vector.h"
6#include <stdlib.h>
7
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}
22
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}
37
39 shell->updateFn(shell);
40}
41
45
47 ARC_Vector_Add(shell->history, (void *)string);
48}
49
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}
void ARC_ConsoleBuffer_Render(ARC_ConsoleBuffer *buffer, ARC_ConsoleView *view)
renders a buffer to a ARC_ConsoleView
Definition buffer.c:51
void ARC_ConsoleBuffer_Create(ARC_ConsoleBuffer **buffer)
creates ARC_ConsoleBuffer type
Definition buffer.c:13
void ARC_ConsoleBuffer_Destroy(ARC_ConsoleBuffer *buffer)
destroys ARC_ConsoleBuffer type
Definition buffer.c:22
void ARC_ConsoleShell_Render(ARC_ConsoleShell *shell)
renders the ARC_ConsoleShell type
Definition shell.c:42
void ARC_ConsoleShell_Destroy(ARC_ConsoleShell *shell)
destroys ARC_ConsoleShell type
Definition shell.c:23
ARC_String * ARC_ConsoleShell_GetHistoryAt(ARC_ConsoleShell *shell, uint32_t index)
gets history from ARC_ConsoleShell
Definition shell.c:50
void ARC_ConsoleShell_Create(ARC_ConsoleShell **shell, ARC_ConsoleView *view, ARC_ConsoleShell_UpdateFn updateFn)
creates ARC_ConsoleShell type
Definition shell.c:8
void ARC_ConsoleShell_AddHistory(ARC_ConsoleShell *shell, ARC_String *string)
adds history ARC_String to ARC_ConsoleShell
Definition shell.c:46
void ARC_ConsoleShell_Update(ARC_ConsoleShell *shell)
updates the ARC_ConsoleShell type
Definition shell.c:38
void(* ARC_ConsoleShell_UpdateFn)(ARC_ConsoleShell *shell)
Definition shell.h:24
void ARC_String_Destroy(ARC_String *string)
destroys ARC_String type
Definition string.c:52
ARC_ConsoleView * view
Definition shell.h:30
ARC_ConsoleBuffer * buffer
Definition shell.h:31
ARC_Vector * history
Definition shell.h:34
ARC_ConsoleShell_UpdateFn updateFn
Definition shell.h:37
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_Add(ARC_Vector *vector, void *data)
adds an item to an ARC_Vector
Definition vector.c:70
void ARC_Vector_Destroy(ARC_Vector *vector)
destroys an ARC_Vector
Definition vector.c:54
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