added documentation, almost done with code
This commit is contained in:
+75
-2
@@ -1,8 +1,13 @@
|
||||
#include "dynstr.h"
|
||||
#include <stdint.h>
|
||||
|
||||
/**
|
||||
* maintains the state of a text editor, including the text buffer,
|
||||
* cursor position, and various editor settings.
|
||||
*/
|
||||
typedef struct {
|
||||
uint32_t lines;
|
||||
uint32_t capacity;
|
||||
uint32_t buffer_line;
|
||||
uint32_t buffer_col;
|
||||
uint32_t y_offset;
|
||||
@@ -10,16 +15,84 @@ typedef struct {
|
||||
bool unsaved_changes;
|
||||
bool editmode;
|
||||
String_t* buffer;
|
||||
String_t* original;
|
||||
String_t filename;
|
||||
} Editor;
|
||||
|
||||
Editor new_editor();
|
||||
/**
|
||||
* Creates a new editor instance from a filename
|
||||
*
|
||||
* @param filename The name of the file to open
|
||||
* @return Editor A new editor instance initialized with the file's content
|
||||
*/
|
||||
Editor new_editor(String_t filename);
|
||||
|
||||
Editor editor_from(String_t input_string);
|
||||
/**
|
||||
* Creates a new editor instance from an input string
|
||||
*
|
||||
* @param input_string initial editor content
|
||||
* @param filename name of the file being edited
|
||||
* @return an instance of the editor
|
||||
*/
|
||||
Editor editor_from(String_t input_string, String_t filename);
|
||||
|
||||
/**
|
||||
* Moves the cursor in the editor (relative to it's current position)
|
||||
*
|
||||
* @param self Pointer to the editor instance
|
||||
* @param x Horizontal movement (negative for left, positive for right)
|
||||
* @param y Vertical movement (negative for up, positive for down)
|
||||
*/
|
||||
void move_cursor(Editor* self, int x, int y);
|
||||
|
||||
/**
|
||||
* Deletes the character before the cursor
|
||||
*
|
||||
* @param self Pointer to the editor instance
|
||||
*/
|
||||
void delchar(Editor* self);
|
||||
|
||||
/**
|
||||
* Adds a character at the cursor position
|
||||
*
|
||||
* @param self Pointer to the editor instance
|
||||
* @param c The character to add
|
||||
*/
|
||||
void addchar(Editor* self, char c);
|
||||
|
||||
/**
|
||||
* Handles the enter key press, creating a new line
|
||||
*
|
||||
* @param self Pointer to the editor instance
|
||||
*/
|
||||
void pressed_enter(Editor* self);
|
||||
|
||||
/**
|
||||
* Toggles between edit and command mode
|
||||
*
|
||||
* @param self Pointer to the editor instance
|
||||
*/
|
||||
void switch_mode(Editor* self);
|
||||
|
||||
/**
|
||||
* Cleans up and frees resources used by the editor
|
||||
*
|
||||
* @param self Pointer to the editor instance
|
||||
*/
|
||||
void shutdown_editor(Editor* self);
|
||||
|
||||
/**
|
||||
* Saves the current buffer content to the file
|
||||
*
|
||||
* @param self Pointer to the editor instance
|
||||
* @return int Returns 0 on success, non-zero on failure
|
||||
*/
|
||||
int save_file(Editor* self);
|
||||
|
||||
/**
|
||||
* Converts the editor's buffer content to a String_t type
|
||||
*
|
||||
* @param self Pointer to the editor instance
|
||||
* @return String_t* Pointer to a string containing the buffer content
|
||||
*/
|
||||
String_t* to_string(Editor* self);
|
||||
|
||||
Reference in New Issue
Block a user