Loading...
Searching...
No Matches
shell.c
Go to the documentation of this file.
#include "arc/console/shell.h"
#include "arc/console/buffer.h"
#include "arc/std/string.h"
#include "arc/std/vector.h"
#include <stdlib.h>
void ARC_ConsoleShell_Create(ARC_ConsoleShell **shell, ARC_ConsoleView *view, ARC_ConsoleShell_UpdateFn updateFn){
*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;
}
void ARC_ConsoleShell_Destroy(ARC_ConsoleShell *shell){
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);
}
void ARC_ConsoleShell_Update(ARC_ConsoleShell *shell){
shell->updateFn(shell);
}
void ARC_ConsoleShell_Render(ARC_ConsoleShell *shell){
ARC_ConsoleBuffer_Render(shell->buffer, shell->view);
}
void ARC_ConsoleShell_AddHistory(ARC_ConsoleShell *shell, ARC_String *string){
ARC_Vector_Add(shell->history, (void *)string);
}
ARC_String *ARC_ConsoleShell_GetHistoryAt(ARC_ConsoleShell *shell, uint32_t index){
uint32_t maxHistory = ARC_Vector_Size(shell->history);
if(index >= maxHistory){
return NULL;
}
return (ARC_String *)ARC_Vector_Get(shell->history, (maxHistory - 1) - index);
}
buffer.h
ARC_ConsoleBuffer_Render
void ARC_ConsoleBuffer_Render(ARC_ConsoleBuffer *buffer, ARC_ConsoleView *view)
renders a buffer to a ARC_ConsoleView
Definition buffer.c:51
ARC_ConsoleBuffer_Create
void ARC_ConsoleBuffer_Create(ARC_ConsoleBuffer **buffer)
creates ARC_ConsoleBuffer type
Definition buffer.c:13
ARC_ConsoleBuffer_Destroy
void ARC_ConsoleBuffer_Destroy(ARC_ConsoleBuffer *buffer)
destroys ARC_ConsoleBuffer type
Definition buffer.c:22
ARC_ConsoleShell_Render
void ARC_ConsoleShell_Render(ARC_ConsoleShell *shell)
renders the ARC_ConsoleShell type
Definition shell.c:42
ARC_ConsoleShell_Destroy
void ARC_ConsoleShell_Destroy(ARC_ConsoleShell *shell)
destroys ARC_ConsoleShell type
Definition shell.c:23
ARC_ConsoleShell_GetHistoryAt
ARC_String * ARC_ConsoleShell_GetHistoryAt(ARC_ConsoleShell *shell, uint32_t index)
gets history from ARC_ConsoleShell
Definition shell.c:50
ARC_ConsoleShell_Create
void ARC_ConsoleShell_Create(ARC_ConsoleShell **shell, ARC_ConsoleView *view, ARC_ConsoleShell_UpdateFn updateFn)
creates ARC_ConsoleShell type
Definition shell.c:8
ARC_ConsoleShell_AddHistory
void ARC_ConsoleShell_AddHistory(ARC_ConsoleShell *shell, ARC_String *string)
adds history ARC_String to ARC_ConsoleShell
Definition shell.c:46
ARC_ConsoleShell_Update
void ARC_ConsoleShell_Update(ARC_ConsoleShell *shell)
updates the ARC_ConsoleShell type
Definition shell.c:38
shell.h
ARC_ConsoleShell_UpdateFn
void(* ARC_ConsoleShell_UpdateFn)(ARC_ConsoleShell *shell)
Definition shell.h:24
string.h
ARC_String_Destroy
void ARC_String_Destroy(ARC_String *string)
destroys ARC_String type
Definition string.c:52
ARC_ConsoleShell
Definition shell.h:29
ARC_ConsoleShell::view
ARC_ConsoleView * view
Definition shell.h:30
ARC_ConsoleShell::buffer
ARC_ConsoleBuffer * buffer
Definition shell.h:31
ARC_ConsoleShell::history
ARC_Vector * history
Definition shell.h:34
ARC_ConsoleShell::updateFn
ARC_ConsoleShell_UpdateFn updateFn
Definition shell.h:37
ARC_ConsoleView
Definition view.c:15
ARC_String
substring position within a string
Definition string.h:14
vector.h
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_Add
void ARC_Vector_Add(ARC_Vector *vector, void *data)
adds an item to an ARC_Vector
Definition vector.c:70
ARC_Vector_Destroy
void ARC_Vector_Destroy(ARC_Vector *vector)
destroys an ARC_Vector
Definition vector.c:54
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