removed STD archeus, moved console and ssh into linux folder. also added libdbus

This commit is contained in:
herbglitch 2025-02-08 02:15:23 -07:00
parent 119d1b2c64
commit 8fe402e04e
27 changed files with 622 additions and 145 deletions

View file

@ -0,0 +1,102 @@
#ifndef ARC_CONSOLE_LINE_BUFFER_H_
#define ARC_CONSOLE_LINE_BUFFER_H_
#ifdef __cplusplus
extern "C" {
#endif
#include <stdint.h>
#include "arc/console/view.h"
#include "arc/std/string.h"
/**
* @brief
*/
typedef struct ARC_ConsoleBuffer ARC_ConsoleBuffer;
/**
* @brief creates ARC_ConsoleBuffer type
*
* @param buffer ARC_ConsoleBuffer to create
*/
void ARC_ConsoleBuffer_Create(ARC_ConsoleBuffer **buffer);
/**
* @brief destroys ARC_ConsoleBuffer type
*
* @param buffer ARC_ConsoleBuffer to destroy
*/
void ARC_ConsoleBuffer_Destroy(ARC_ConsoleBuffer *buffer);
/**
* @brief clears the contents of a ARC_ConsoleBuffer
*
* @param buffer ARC_ConsoleBuffer to clear
*/
void ARC_ConsoleBuffer_Clear(ARC_ConsoleBuffer *buffer);
/**
* @brief renders a buffer to a ARC_ConsoleView
*
* @param buffer ARC_ConsoleBuffer to render
* @param view ARC_ConsoleView to render the buffer contents to
*/
void ARC_ConsoleBuffer_Render(ARC_ConsoleBuffer *buffer, ARC_ConsoleView *view);
/**
* @brief renders a section of buffer to a ARC_ConsoleView
*
* @param buffer ARC_ConsoleBuffer to render
* @param view ARC_ConsoleView to render the buffer contents to
* @param startIndex start index of buffer to render
* @param lines the number of lines of buffer to render
*/
void ARC_ConsoleBuffer_RenderSection(ARC_ConsoleBuffer *buffer, ARC_ConsoleView *view, uint32_t startIndex, uint32_t lines);
/**
* @brief adds a character to the buffer
*
* @param buffer ARC_ConsoleBuffer to add character to
* @param character char to add to ARC_ConsoleBuffer
*/
void ARC_ConsoleBuffer_AddChar(ARC_ConsoleBuffer *buffer, char character);
/**
* @brief adds an ARC_String to the buffer
*
* @param buffer ARC_ConsoleBuffer to add character to
* @param string ARC_String to add to ARC_ConsoleBuffer
*/
void ARC_ConsoleBuffer_AddString(ARC_ConsoleBuffer *buffer, ARC_String *string);
/**
* @brief adds a cstring to the buffer
*
* @param buffer ARC_ConsoleBuffer to add character to
* @param string cstring to add to ARC_ConsoleBuffer
* @param length the length of the c string to add
*/
void ARC_ConsoleBuffer_AddCString(ARC_ConsoleBuffer *buffer, char *cstring, uint64_t length);
/**
* @brief adds a cstring to the buffer with the cstrings string length
*
* @param buffer ARC_ConsoleBuffer to add character to
* @param string cstring to add to ARC_ConsoleBuffer
*/
void ARC_ConsoleBuffer_AddCStringWithStrlen(ARC_ConsoleBuffer *buffer, char *cstring);
/**
* @brief gets the number of lines from a console line buffer
*
* @param buffer ARC_ConsoleBuffer get number of lines from
*
* @return the number of lines within an ARC_ConsoleBuffer
*/
uint32_t ARC_ConsoleBuffer_GetLineNumbers(ARC_ConsoleBuffer *buffer);
#ifdef __cplusplus
}
#endif
#endif //!ARC_CONSOLE_LINE_BUFFER_H_

View file

@ -0,0 +1,78 @@
#ifndef ARC_NCURSES_ELEMENT_H_
#define ARC_NCURSES_ELEMENT_H_
#ifdef __cplusplus
extern "C" {
#endif
#include <stdint.h>
#include "view.h"
#include "arc/std/string.h"
#include "arc/std/bool.h"
#include "arc/math/point.h"
/**
* @brief
*/
typedef struct ARC_ConsoleElement ARC_ConsoleElement;
/**
* @brief
*/
typedef void (*ARC_ConsoleElement_RenderFn)(ARC_ConsoleView *view, ARC_ConsoleElement *element);
/**
* @brief
*/
typedef struct ARC_ConsoleElement {
uint32_t type;
uint8_t flags;
ARC_String *string;
ARC_Point pos;
ARC_ConsoleElement_RenderFn renderFn;
} ARC_ConsoleElement;
/**
* @brief
*/
#define ARC_CONSOLE_ELEMENT_FLAG_NONE 0b00000000
#define ARC_CONSOLE_ELEMENT_FLAG_SELECTABLE 0b00000001
#define ARC_CONSOLE_ELEMENT_FLAG_SELECTED 0b00000010
/**
* @brief
*/
void ARC_ConsoleElement_Create(ARC_ConsoleElement **element, uint32_t type, uint8_t flags, ARC_String *string, ARC_Point pos, ARC_ConsoleElement_RenderFn renderFn);
/**
* @brief
*/
void ARC_ConsoleElement_Destroy(ARC_ConsoleElement *element);
/**
* @brief
*/
void ARC_ConsoleElement_DefaultRenderFn(ARC_ConsoleView *view, ARC_ConsoleElement *element);
/**
* @brief
*
* @param
*/
ARC_Bool ARC_ConsoleElement_IsSelectable(ARC_ConsoleElement *element);
/**
* @brief
*
* @param
*/
void ARC_ConsoleElement_SetSelected(ARC_ConsoleElement *element, ARC_Bool selected);
/**
* @brief
*/
void ARC_ConsoleElement_ToggleSelected(ARC_ConsoleElement *element);
#endif //!ARC_CONSOLE_ELEMENT_H_

View file

@ -0,0 +1,82 @@
#ifndef ARC_CONSOLE_KEY_H_
#define ARC_CONSOLE_KEY_H_
#ifdef __cplusplus
extern "C" {
#endif
#include "arc/std/bool.h"
#include <stdint.h>
typedef struct ARC_ConsoleKeyType ARC_ConsoleKey;
typedef enum ARC_ConsoleKey_Key {
ARC_CONSOLE_KEY_A,
ARC_CONSOLE_KEY_B,
ARC_CONSOLE_KEY_C,
ARC_CONSOLE_KEY_D,
ARC_CONSOLE_KEY_E,
ARC_CONSOLE_KEY_F,
ARC_CONSOLE_KEY_G,
ARC_CONSOLE_KEY_H,
ARC_CONSOLE_KEY_I,
ARC_CONSOLE_KEY_J,
ARC_CONSOLE_KEY_K,
ARC_CONSOLE_KEY_L,
ARC_CONSOLE_KEY_M,
ARC_CONSOLE_KEY_N,
ARC_CONSOLE_KEY_O,
ARC_CONSOLE_KEY_P,
ARC_CONSOLE_KEY_Q,
ARC_CONSOLE_KEY_R,
ARC_CONSOLE_KEY_S,
ARC_CONSOLE_KEY_T,
ARC_CONSOLE_KEY_U,
ARC_CONSOLE_KEY_V,
ARC_CONSOLE_KEY_W,
ARC_CONSOLE_KEY_X,
ARC_CONSOLE_KEY_Y,
ARC_CONSOLE_KEY_Z,
ARC_CONSOLE_KEY_0,
ARC_CONSOLE_KEY_1,
ARC_CONSOLE_KEY_2,
ARC_CONSOLE_KEY_3,
ARC_CONSOLE_KEY_4,
ARC_CONSOLE_KEY_5,
ARC_CONSOLE_KEY_6,
ARC_CONSOLE_KEY_7,
ARC_CONSOLE_KEY_8,
ARC_CONSOLE_KEY_9,
ARC_CONSOLE_KEY_LEFT,
ARC_CONSOLE_KEY_RIGHT,
ARC_CONSOLE_KEY_DOWN,
ARC_CONSOLE_KEY_UP,
ARC_CONSOLE_KEY_FORWARD_SLASH,
ARC_CONSOLE_KEY_BACKSPACE,
ARC_CONSOLE_KEY_ENTER,
ARC_CONSOLE_KEY_ESC
} ARC_ConsoleKey_Key;
void ARC_ConsoleKey_Create(ARC_ConsoleKey **consoleKey, ARC_ConsoleKey_Key *key);
void ARC_ConsoleKey_Destroy(ARC_ConsoleKey *consoleKey);
ARC_Bool ARC_ConsoleKey_Equals(ARC_ConsoleKey consoleKey, enum ARC_ConsoleKey_Key key);
ARC_Bool ARC_ConsoleKey_EqualsPointer(ARC_ConsoleKey *consoleKey, enum ARC_ConsoleKey_Key key);
ARC_ConsoleKey ARC_Keyboard_GetConsoleKey(enum ARC_ConsoleKey_Key key);
uint8_t ARC_ConsoleKey_GetCharFromKey(ARC_ConsoleKey *consoleKey);
#ifdef __cplusplus
}
#endif
#endif // !ARC_CONSOLE_KEY_H_

View file

@ -0,0 +1,97 @@
#ifndef ARC_CONSOLE_SHELL_H_
#define ARC_CONSOLE_SHELL_H_
#ifdef __cplusplus
extern "C" {
#endif
//TODO: fix up this file
#include "view.h"
#include "buffer.h"
#include "arc/std/string.h"
#include "arc/std/vector.h"
#include <stdint.h>
/**
* @brief
*/
typedef struct ARC_ConsoleShell ARC_ConsoleShell;
/**
* @brief
*/
typedef void (* ARC_ConsoleShell_UpdateFn)(ARC_ConsoleShell *shell);
/**
* @brief
*/
struct ARC_ConsoleShell {
ARC_ConsoleView *view;
ARC_ConsoleBuffer *buffer;
uint32_t bufferLineIndex;
ARC_Vector *history;
uint32_t historyIndex;
ARC_ConsoleShell_UpdateFn updateFn;
ARC_String *currentLine;
ARC_String *userInput;
};
/**
* @brief creates ARC_ConsoleShell type
*
* @param shell ARC_ConsoleShell to create
* @param view ARC_ConsoleView to attach the shell to
* @param updateFn ARC_ConsoleShell_UpdateFn provided that will run the console
*/
void ARC_ConsoleShell_Create(ARC_ConsoleShell **shell, ARC_ConsoleView *view, ARC_ConsoleShell_UpdateFn updateFn);
/**
* @brief destroys ARC_ConsoleShell type
*
* @param shell ARC_ConsoleShell to destroy
*/
void ARC_ConsoleShell_Destroy(ARC_ConsoleShell *shell);
/**
* @brief updates the ARC_ConsoleShell type
*
* @param shell the ARC_ConsoleShell to update
*/
void ARC_ConsoleShell_Update(ARC_ConsoleShell *shell);
/**
* @brief renders the ARC_ConsoleShell type
*
* @param shell the ARC_ConsoleShell to render
*/
void ARC_ConsoleShell_Render(ARC_ConsoleShell *shell);
/**
* @brief adds history ARC_String to ARC_ConsoleShell
*
* @param shell the ARC_ConsoleShell to add history to
* @param string the history string to add to ARC_ConsoleShell
*/
void ARC_ConsoleShell_AddHistory(ARC_ConsoleShell *shell, ARC_String *string);
/**
* @brief gets history from ARC_ConsoleShell
*
* @note the index 0 will start from the last added history
*
* @param shell the ARC_ConsoleShell to get history from
* @param index the location to get history at
*
* @return the history as an ARC_String
*/
ARC_String *ARC_ConsoleShell_GetHistoryAt(ARC_ConsoleShell *shell, uint32_t index);
#ifdef __cplusplus
}
#endif
#endif //!ARC_CONSOLE_SHELL_H_

View file

@ -0,0 +1,267 @@
#ifndef ARC_CONSOLE_VIEW_H_
#define ARC_CONSOLE_VIEW_H_
#ifdef __cplusplus
extern "C" {
#endif
#include <stdint.h>
#include <wchar.h>
#include "arc/console/key.h"
#include "arc/math/rectangle.h"
#include "arc/std/bool.h"
#include "arc/std/string.h"
/**
* @brief
*/
typedef struct ARC_ConsoleView ARC_ConsoleView;
/**
* @brief
*/
typedef struct ARC_ConsoleElement ARC_ConsoleElement;
/**
* @brief creates ARC_ConsoleView type
*
* @param view ARC_ConsoleView to create
* @param bounds the bounds of the window, if bounds.w == 0 or bounds.h == 0, bounds will take up the entire screen
*/
void ARC_ConsoleView_Create(ARC_ConsoleView **view, ARC_Rect bounds);
/**
* @brief destroys ARC_ConsoleView type
*
* @param view ARC_ConsoleView to destroy
*/
void ARC_ConsoleView_Destroy(ARC_ConsoleView *view);
/**
* @brief adds an ARC_ConsoleElement to the ARC_ConsoleView type
*
* @note the elements position will be based on the ARC_ConsoleView which might mess up how it looks
*
* @param view
* @param elment
*/
void ARC_ConsoleView_AddElement(ARC_ConsoleView *view, ARC_ConsoleElement *element);
/**
* @brief
*
* @param view
* @param index
*/
void ARC_ConsoleView_RemoveElement(ARC_ConsoleView *view, uint32_t index);
/**
* @brief
*
* @param view
* @param index
*/
void ARC_ConsoleView_Clear(ARC_ConsoleView *view);
/**
* @brief
*
* @param view
* @param character
* @param pos
*/
void ARC_ConsoleView_RenderCharAt(ARC_ConsoleView *view, char character, ARC_Point pos);
/**
* @brief
*
* @param view
* @param character
* @param pos
*/
void ARC_ConsoleView_RenderWCharAt(ARC_ConsoleView *view, wchar_t character, ARC_Point pos);
/**
* @brief
*
* @param view
* @param key
* @param pos
*/
void ARC_ConsoleView_RenderKeyAt(ARC_ConsoleView *view, ARC_ConsoleKey key, ARC_Point pos);
/**
* @brief
*
* @param view
* @param uint32
* @param pos
*/
void ARC_ConsoleView_RenderUint32At(ARC_ConsoleView *view, uint32_t uint32, ARC_Point pos);
/**
* @brief
*
* @param view
* @param text
* @param pos
*/
void ARC_ConsoleView_RenderStringAt(ARC_ConsoleView *view, ARC_String *text, ARC_Point pos);
/**
* @brief
*
* @param view
* @param text
* @param pos
*/
void ARC_ConsoleView_RenderCStringWithStrlenAt(ARC_ConsoleView *view, char *cstr, ARC_Point pos);
/**
* @brief
*
* @param view
* @param bounds
*/
void ARC_ConsoleView_RenderRect(ARC_ConsoleView *view, ARC_Rect bounds);
/**
* @brief
*
* @param view
*/
void ARC_ConsoleView_RenderElements(ARC_ConsoleView *view);
/**
* @brief gets the bounds of an ARC_ConsoleView
*
* @param view ARC_ConsoleView to get bounds from
*
* @return the bounds of the ARC_ConsoleView
*/
ARC_Rect ARC_ConsoleView_GetBounds(ARC_ConsoleView *view);
/**
* @brief adds an ARC_ConsoleElement to the ARC_ConsoleView type
*
* @note the elements position will be based on the ARC_ConsoleView which might mess up how it looks
*
* @param view
* @param index
*/
ARC_ConsoleElement *ARC_ConsoleView_GetElement(ARC_ConsoleView *view, uint32_t index);
/**
* @brief gets a char from the view
*
* @note use ARC_ConsoleView_GetInt32At if you want to check for direction key or special character input
*
* @param view the ARC_ConsoleView to get the char from
*/
char ARC_ConsoleView_GetChar(ARC_ConsoleView *view);
/**
* @brief gets a char from the view at a position
*
* @note use ARC_ConsoleView_GetInt32At if you want to check for direction key or special character input
*
* @param view the ARC_ConsoleView to get the char from
* @param pos the positiion to get the char at
*/
char ARC_ConsoleView_GetCharAt(ARC_ConsoleView *view, ARC_Point pos);
/**
* @brief gets a console key from the view at a position
*
* @note you most likely do not want to use this function outside of a backend as ARC_ConsoleKey is defined within the console backend
*
* @param view the ARC_ConsoleView to get the console key from
* @param pos the positiion to get the console key at
*
* @return a console key
*/
ARC_ConsoleKey ARC_ConsoleView_GetConsoleKeyAt(ARC_ConsoleView *view, ARC_Point pos);
/**
* @brief gets and creates a console key from the view at a position
*
* @note the given ARC_ConsoleKey needs to be destroyed
* @note use ARC_ConsoleView_GetConsoleKeyAt if you want to check for keyboard or special character input
*
* @param view the ARC_ConsoleView to get the console key from
* @param pos the positiion to get the console key at
*
* @return a console key
*/
ARC_ConsoleKey *ARC_ConsoleView_GetCreateConsoleKeyAt(ARC_ConsoleView *view, ARC_Point pos);
/**
* @brief callback to check char being read in and override functionality
*
* @note this function is used for pressing arrow keys but can be used for anything
*
* @param key the current key being read in
* @param inputCStr the cstring that holds the current contents of the input
* @param inputSize the size of the current contents of the input string
* @param maxInputSize the max size inputCStr can store
* @param userdata data that a user can pass to use within this function
*/
typedef ARC_Bool (* ARC_ConsoleView_OverrideCharInputFn)(ARC_ConsoleKey *key, char *inputCStr, uint32_t *inputSize, uint32_t maxInputSize, void *userdata);
/**
* @brief gets a ARC_String from the view at a position
*
* @param view the ARC_ConsoleView to get the string from
* @param pos the positiion to get the string at
* @param overrideCharInputFn a function to allow overriding what happens when inputing chars, can be NULL
* @param userdata data that a user can pass to use within the overrideCharInputFn
*/
ARC_String *ARC_ConsoleView_GetStringInput(ARC_ConsoleView *view, ARC_Point pos, ARC_ConsoleView_OverrideCharInputFn *overrideCharInputFn, void *userdata);
/**
* @brief mouse options
*/
#define ARC_CONSOLE_VIEW_CURSOR_HIDDEN 0x00
#define ARC_CONSOLE_VIEW_CURSOR_VISIBLE 0x01
/**
* @brief sets a visibility of the cursor with an ARC_ConsoleView
*
* @param view ARC_ConsoleView to set mouse visibility
* @param visibility the visibility to set
*/
void ARC_ConsoleView_SetCursorVisibility(ARC_ConsoleView *view, uint8_t visibility);
/**
* @brief border options
*/
#define ARC_CONSOLE_VIEW_BORDER_NONE 0x00
#define ARC_CONSOLE_VIEW_BORDER_DEFAULT 0x01
/**
* @brief sets a border on the ARC_ConsoleView
*
* @param view ARC_ConsoleView to set border to
* @param border The border to set
*/
void ARC_ConsoleView_SetBorder(ARC_ConsoleView *view, uint32_t border);
/**
* @brief border options
*/
#define ARC_CONSOLE_VIEW_ATTRIBUTE_NONE 0x00
#define ARC_CONSOLE_VIEW_ATTRIBUTE_REVERSE 0x01
/**
* @brief sets a border on the ARC_ConsoleView
*
* @param view ARC_ConsoleView to set border to
* @param border The border to set
*/
void ARC_ConsoleView_SetAttribute(ARC_ConsoleView *view, uint32_t attribute);
#ifdef __cplusplus
}
#endif
#endif //!ARC_CONSOLE_VIEW_H_

View file

@ -0,0 +1,38 @@
#ifndef ARC_DBUS_H_
#define ARC_DBUS_H_
#ifdef __cplusplus
extern "C" {
#endif
#include <stdint.h>
#include <dbus/dbus.h>
#include <arc/std/vector.h>
/**
* @brief
*/
typedef struct ARC_DBus ARC_DBus;
void ARC_DBus_Create(ARC_DBus **dbus);
void ARC_DBus_Destroy(ARC_DBus *dbus);
//Docs: https://flatpak.github.io/xdg-desktop-portal/docs/doc-org.freedesktop.portal.Request.html#org-freedesktop-portal-request-response
void ARC_DBus_RequestResponse();
//Docs: https://flatpak.github.io/xdg-desktop-portal/docs/doc-org.freedesktop.portal.GlobalShortcuts.html#org-freedesktop-portal-globalshortcuts-createsession
void ARC_DBus_InitSession(ARC_DBus *dbus);
//Docs: https://flatpak.github.io/xdg-desktop-portal/docs/doc-org.freedesktop.portal.GlobalShortcuts.html#org-freedesktop-portal-globalshortcuts-bindshortcuts
//NOTE: this is a vector of ARC_DBusShortcut
void ARC_DBus_BindShortcuts(ARC_DBus *dbus, ARC_Vector *dbusShortcutVector);
//NOTE: https://flatpak.github.io/xdg-desktop-portal/docs/doc-org.freedesktop.portal.GlobalShortcuts.html#org-freedesktop-portal-globalshortcuts-listshortcuts
void ARC_DBus_ListShortcuts(ARC_DBus *dbus);
#ifdef __cplusplus
}
#endif
#endif // !ARC_DBUS_H_

View file

@ -0,0 +1,55 @@
#ifndef ARC_DBUS_HELPER_H_
#define ARC_DBUS_HELPER_H_
#ifdef __cplusplus
extern "C" {
#endif
#include <stdint.h>
#include <dbus/dbus.h>
/**
* @brief
*/
typedef struct ARC_DBus ARC_DBus;
/**
* @brief
*
* @param[in] dbus
* @param[in] interface
* @param[in] objectPath
*/
void ARC_DBusHelper_BusRequestName(ARC_DBus *dbus, const char *interface, const char *objectPath);
/**
* @brief
*
* @param[in] dbus
* @param[in] interface
* @param[in] objectPath
* @param[in] member
*/
void ARC_DBusHelper_BusAddMatch(ARC_DBus *dbus, const char *interface, const char *objectPath, const char *member);
/**
* @brief
*
* @param[in] message
*/
void ARC_DBusHelper_HandleSignal(DBusMessage *message);
/**
* @brief
*
* @param[in] dictonaryIter
* @param[in] stringKey
* @param[in] varientStringValue
*/
void ARC_DBusHelper_AddStringVarientStringToMessageIterDictionary(DBusMessageIter *dictonaryIter, const char *stringKey, const char *varientStringValue);
#ifdef __cplusplus
}
#endif
#endif // !ARC_DBUS_HELPER_H_

View file

@ -0,0 +1,58 @@
#ifndef ARC_SSH_H_
#define ARC_SSH_H_
#include "arc/std/string.h"
#ifdef __cplusplus
extern "C" {
#endif
/**
* @brief ssh type that holds ssh connection along with credentials
*/
typedef struct ARC_Ssh ARC_Ssh;
/**
* @brief a ssh session function
*
* @param data user data that can be used within the callback
*/
typedef void (* ARC_Ssh_SessionFn)(void *data);
/**
* @brief creates ARC_Ssh type
*
* @param ssh ARC_Ssh to create
*/
void ARC_Ssh_Create(ARC_Ssh **ssh, char *host, char *user, char *password);
/**
* @brief destroyes ARC_Ssh type
*
* @param ssh ARC_Ssh to destroy
*/
void ARC_Ssh_Destroy(ARC_Ssh *ssh);
/**
* @brief runs a callback function within a ssh session
*
* @param ssh ARC_Ssh to create and run function in ssh session
* @param sessionFN callback to run in a ssh session
*/
void ARC_Ssh_RunInSession(ARC_Ssh *ssh, ARC_Ssh_SessionFn sessionFn);
/**
* @brief
*/
void ARC_Ssh_ExecStrInNewSession(ARC_Ssh *ssh, char *command);
/**
* @brief
*/
ARC_String *ARC_Ssh_ExecStrInNewSessionAndGetResponse(ARC_Ssh *ssh, char *command);
#ifdef __cplusplus
}
#endif
#endif //!ARC_SSH_H_