README.md (8293B)
1 # Lunar Editor 2 3 A simple, elegant text editor for LuajitOS with word wrap and line numbers. 4 5 ## Features 6 7 - **Black text on white background** - Easy to read, classic text editor appearance 8 - **Line numbers** - Grey line numbers displayed on the left (default: ON) 9 - **Word wrap** - Automatically wrap long lines (default: ON) 10 - **Keyboard navigation** - Full cursor control with arrow keys 11 - **File operations** - Open and save files from/to user directory 12 - **Status bar** - Shows current file, line/column, modification status, and settings 13 14 ## Usage 15 16 ### Starting the Editor 17 18 ```lua 19 -- Open empty editor 20 run("com.luajitos.lunareditor") 21 22 -- Open specific file 23 run("com.luajitos.lunareditor", "~/myfile.txt") 24 ``` 25 26 ### Keyboard Controls 27 28 **Text Editing:** 29 - **Type** - Insert characters at cursor 30 - **Enter** - Insert new line 31 - **Backspace** - Delete character before cursor 32 - **Tab** - Insert 4 spaces 33 34 **Navigation:** 35 - **Arrow Keys** - Move cursor (Up, Down, Left, Right) 36 - **Left/Right** - Move between characters 37 - **Up/Down** - Move between lines 38 39 **File Operations:** 40 *(Currently requires API calls - see API section)* 41 42 ### Current State Indicators 43 44 The status bar shows: 45 - **File name** - Current file path or `[Untitled]` 46 - **[Modified]** - Appears if file has been edited 47 - **Line X, Col Y** - Current cursor position 48 - **Lines: N** - Total line count 49 - **Wrap: ON/OFF** - Word wrap state 50 - **LineNum: ON/OFF** - Line number display state 51 52 ## Configuration 53 54 Default settings are defined in the code: 55 56 ```lua 57 settings = { 58 wordWrap = true, -- Enable word wrap 59 lineNumbers = true, -- Show line numbers 60 fontSize = 8, -- Character width (pixels) 61 lineHeight = 12 -- Line height (pixels) 62 } 63 ``` 64 65 ## File Operations 66 67 ### Saving Files 68 69 ```lua 70 -- From within editor.lua or via exported function 71 saveFile("~/myfile.txt") 72 ``` 73 74 ### Loading Files 75 76 ```lua 77 -- From within editor.lua or via exported function 78 loadFile("~/myfile.txt") 79 80 -- Or pass as argument when running 81 run("com.luajitos.lunareditor", "~/document.txt") 82 ``` 83 84 ## Permissions 85 86 The editor requires the following permissions: 87 88 - **draw** - Display the editor window 89 - **filesystem** - Read and write files 90 91 ## Allowed Paths 92 93 - **~/** - Full access to user home directory and all subdirectories 94 95 This means you can edit any file in your home directory, such as: 96 - `~/notes.txt` 97 - `~/projects/code.lua` 98 - `~/documents/readme.md` 99 100 ## Visual Layout 101 102 ``` 103 ┌─────────────────────────────────────────────────┐ 104 │ Lunar Editor [X]│ 105 ├────┬──────────────────────────────────────────────┤ 106 │ 1 │ This is line one │ 107 │ 2 │ This is line two with some longer text that │ 108 │ │ wraps to the next display line if word wrap │ 109 │ │ is enabled │ 110 │ 3 │ Line three| │ 111 │ │ │ 112 │ │ │ 113 ├────┴──────────────────────────────────────────────┤ 114 │ ~/myfile.txt [Modified] | Line 3, Col 11 | ... │ 115 └─────────────────────────────────────────────────┘ 116 ``` 117 118 **Legend:** 119 - Left column: Line numbers (grey on light grey background) 120 - Main area: Text content (black on white) 121 - `|` - Cursor (blue, blinking) 122 - Bottom bar: Status information (grey background) 123 124 ## Color Scheme 125 126 - **Background:** White (`0xFFFFFF`) 127 - **Text:** Black (`0x000000`) 128 - **Line numbers:** Grey (`0x808080`) 129 - **Line number background:** Light grey (`0xF0F0F0`) 130 - **Cursor:** Blue (`0x0000FF`) 131 - **Status bar background:** Light grey (`0xE0E0E0`) 132 133 ## Implementation Details 134 135 ### Word Wrap Algorithm 136 137 When word wrap is enabled: 138 1. Calculate characters per line based on window width 139 2. Split text at character limit 140 3. Try to break at last space or tab before limit 141 4. If no word boundary, break at character limit 142 5. Create multiple display lines from single source line 143 144 ### Line Number Display 145 146 - Line numbers shown only for the first display segment of each source line 147 - When a line wraps, wrapped segments have no line number 148 - Line numbers always refer to source line, not display line 149 - Grey color distinguishes them from text content 150 151 ### Cursor Positioning 152 153 - Cursor position tracked in source text (line and column) 154 - Blinking cursor rendered at calculated display position 155 - Auto-scroll ensures cursor stays visible when navigating 156 - Cursor moves to end of line if target column doesn't exist 157 158 ### File Format 159 160 - Files saved with Unix line endings (`\n`) 161 - No BOM or encoding markers (plain ASCII/UTF-8) 162 - Trailing newline preserved if present in original file 163 164 ## Limitations 165 166 1. **No syntax highlighting** - Plain text only 167 2. **No undo/redo** - Edit carefully 168 3. **No search/replace** - Manual navigation only 169 4. **No clipboard** - Can't copy/paste 170 5. **No mouse selection** - Keyboard only 171 6. **Fixed window size** - 800x600 pixels 172 7. **ASCII only** - No Unicode support (limited by font rendering) 173 174 ## Troubleshooting 175 176 ### Editor doesn't respond to keyboard 177 178 **Solution:** Click on the editor window to focus it. 179 180 The editor must be the active window to receive keyboard input. 181 182 ### Can't save file 183 184 **Possible causes:** 185 - File path outside `~/` directory 186 - Missing filesystem permission 187 - Directory doesn't exist 188 189 **Solution:** Ensure you're saving to `~/` and the directory exists. 190 191 ### Word wrap doesn't break at words 192 193 This happens when: 194 - Line has no spaces or tabs 195 - Word is longer than line width 196 197 In these cases, the line breaks at character limit. 198 199 ### Line numbers missing 200 201 Check that `settings.lineNumbers = true` in editor.lua. 202 203 ## Examples 204 205 ### Create a new file 206 207 ```lua 208 -- 1. Start editor 209 run("com.luajitos.lunareditor") 210 211 -- 2. Type your content 212 -- (use keyboard to type) 213 214 -- 3. Save it 215 -- (requires calling saveFile function) 216 ``` 217 218 ### Edit an existing file 219 220 ```lua 221 -- Open file 222 run("com.luajitos.lunareditor", "~/readme.txt") 223 224 -- Make changes 225 -- (use arrow keys and typing) 226 227 -- Save changes 228 -- (requires calling saveFile function) 229 ``` 230 231 ## Future Enhancements 232 233 Potential features for future versions: 234 235 - [ ] Menu bar with File, Edit, View options 236 - [ ] Save/Save As dialogs 237 - [ ] Open file dialog 238 - [ ] Undo/Redo functionality 239 - [ ] Search and replace 240 - [ ] Goto line number 241 - [ ] Clipboard support (cut/copy/paste) 242 - [ ] Mouse selection and scrolling 243 - [ ] Configurable color schemes 244 - [ ] Syntax highlighting for Lua 245 - [ ] Multi-file tabs 246 - [ ] Status bar improvements (file size, encoding) 247 - [ ] Keyboard shortcuts (Ctrl+S, Ctrl+O, etc.) 248 249 ## Technical Specifications 250 251 - **Window size:** 800x600 pixels 252 - **Text area:** ~750x570 pixels (with line numbers) 253 - **Line number width:** 50 pixels 254 - **Status bar height:** 20 pixels 255 - **Character width:** ~8 pixels 256 - **Line height:** 12 pixels 257 - **Approximate capacity:** ~95 chars/line, ~47 lines visible 258 259 ## API Reference 260 261 ### Internal Functions 262 263 ```lua 264 -- File operations 265 saveFile(filepath) -- Save current content to file 266 loadFile(filepath) -- Load file into editor 267 268 -- Text manipulation 269 insertChar(char) -- Insert character at cursor 270 insertNewline() -- Insert new line at cursor 271 deleteChar() -- Delete character before cursor 272 273 -- Cursor movement 274 moveCursorLeft() -- Move cursor left 275 moveCursorRight() -- Move cursor right 276 moveCursorUp() -- Move cursor up 277 moveCursorDown() -- Move cursor down 278 279 -- Display 280 rebuildDisplayLines() -- Rebuild wrapped display lines 281 wrapLine(text, width) -- Wrap single line to width 282 ``` 283 284 ## Credits 285 286 **Developer:** luajitos 287 **Version:** 1.0.0 288 **Category:** Productivity 289 **License:** Part of LuajitOS 290 291 ## See Also 292 293 - **Application Development Guide** - Learn to create LuajitOS apps 294 - **SafeFS Documentation** - File system API reference 295 - **Manifest Specification** - App configuration format