+/Femto
toy text editor
git clone https://git.julia.blue/+/Femto
973c5b9
master
1#pragma once 2 3#include <stdarg.h> 4#include <string.h> 5#include <time.h> 6 7#include "display.h" 8#include "fileio.h" 9#include "terminal.h" 10 11/** 12* Encapsulates a row of text including its position in the file and syntax 13* highlighting data. 14*/ 15struct erow { 16int index ; 17char * text ; 18int size ; 19char * hl ; 20int unclosed ; 21}; 22 23typedef struct erow erow ; 24 25/** 26* Global object containing the state of the editor. 27*/ 28struct editorConfig { 29int cx ,oldcx ,cy ; 30int width ,height ; 31int scrollRow ,scrollCol ; 32erow * row ; 33int numrows ; 34int dirty ; 35char * filename ; 36int tabSize ; 37char statusmsg [80 ]; 38time_t messageTime ; 39struct editorSyntax * syntax ; 40struct termios orig_termios ; 41}; 42 43extern struct editorConfig E ; 44 45enum keys { 46BACKSPACE = 127 , 47ARROW_UP = 1024 , 48ARROW_DOWN , 49ARROW_LEFT , 50ARROW_RIGHT , 51PAGE_UP , 52PAGE_DOWN , 53HOME_KEY , 54END_KEY , 55DEL_KEY 56}; 57 58/** 59* Initializes global editor object, destroying an old one of it existed. 60*/ 61void initEditor (); 62 63/** 64* Displays a string to the user with printf style fomatting flags. 65*/ 66void setStatusMessage (const char * fmt , ...); 67 68/** 69* Displays a string to the user and lets them input a response, with an 70* optional callback function firing after each keypress. 71*/ 72char * prompt (char * prompt ,void (* callback )(char * ,int )); 73 74/** 75* Callback function for the find operation. Handles moving between selections 76* with arrow keys and canceling or finishing the find operation. 77* @param query current search string 78* @param key latest key pressed 79*/ 80void findcb (char * query ,int key ); 81 82/** 83* Prompts the user to search for a string in the file. 84*/ 85void find (); 86 87/** 88* Creates a new row in the editor. 89* @param s seed string for new row 90* @param len seed string length 91*/ 92void insertRow (int at ,char * s ,size_t len ); 93 94void deleteRow (int at ); 95 96void freeRow (erow * row ); 97 98/** 99* Handles arrow key presses. 100*/ 101void moveCursor (int key ); 102 103void rowInsertChar (erow * row ,int at ,char c ); 104 105void rowDeleteChar (erow * row ,int at ); 106 107void rowAppendStr (erow * row ,char * s ,size_t len ); 108 109void insertNewline (); 110 111void insertChar (int c ); 112 113void deleteChar (); 114 115int countTabs (char * s ,size_t len ); 116 117/** 118* Contains the high level logic for handling different kinds of keys 119* (blocking). 120*/ 121void processKeypress ();