@document.meta
title: Structure
description: Internal program structure documentation of Phantom
authors: Shadorain
categories: docs
created: 2022-07-23
version: 0.0.11
@end
= TOC
* Ideas
** Screens -> Screen
> a collection of Screen objects that have all their own handling and components
@code neorg
DEPRECATED ┌─────────────────────────── Screens ────────────────────────────┐
┌──────────────┐ │┌────────┬────────┬─────────┐ │
│ Screen Model │ ││Screen 1│Screen 2│Screen 3 │ │
└──────────────┘ ┌─────────┐ │├────────┴────────┴─────────┴──────────────────────────────────┐│
NOTE: Only Screen 2 shown │ Screens │ ││ ┌──────────────────────────────────────────────────────────┐ ││
for example purposes └────┬────┘ ││ │Document ...... also a Component │ ││
┌─────────┬─────┴────┬──────────┐ ││ │ │ ││
Update: ┌────┴───┐ ┌───┴────┐ ┌───┴────┐ ┌───┴────┐ ││ │ │ ││
Screen(2, │Screen 1│ │Screen 2│ │Screen 3│ │Screen 4│ ││ │ │ ││
Component(1, └────────┘ └───┬────┘ └────────┘ └────────┘ ││ │ │ ││
Value ┌──────────┴─┬─────────────────┐ ││ │ │ ││
) ▼ ▼ ▼ ││ └──────────────────────────────────────────────────────────┘ ││
) ┌─────────────┐ ┌─────────────┐ ┌─────────────┐ ││ ┌────────────────────────Component─────────────────────────┐ ││
│ Component 1 │ │ Component 2 │ │ Component 3 │ ││ └────────────────────────StatusLine────────────────────────┘ ││
│ (StatusLine)│ │ (Document) │ │ (Wtvr else) │ │└──────────────────────────────────────────────────────────────┘│
└─────────────┘ └─────────────┘ └─────────────┘ └────────────────────────────────────────────────────────────────┘
@end
$$ Rules:
- Only one `Screens` instance open at a time
- `Screens` will fill the entire window
-- A `Screen` will tile into the `Screens`
- Can hold as many `Screen` elements as can handle within `Screens`
$$
*** ...
*** Screen
> A screen is made of a collection of Components that can be displayed on the screen
> Acts similar to a "Tab"
**** Component
> A component is a single element that can be displayed on a screen
** Screen
*** trait Component
- render
- handle_event
* Scratch
Screen needs to be used by editor, editor dropping a few things
Editor only returns result from new, others are handled unless lethal
Status bar i still need to figure out... i do like my idea of events tho for the diff components
* TODO
- [x] Rename to Phantom
- [-] Umbra TUI Framework library to take out screen aspects
- [x] screen.rs
- [-] Curses?
- [-] Documentation
-- [ ] Terminal
-- [-] Document
-- [-] Buffer
-- [ ] Editor
-- [-] Keybind -> Input
* Project Structures
** Editor
Link: {@ ../src/editor.rs}[Editor.rs]
*** Errors
$ EditorError:
- `Terminal(TermError)`
- `Document(DocError)`
- `Input(InputError)`
*** Fields
- `term: Terminal`
- ... (not set in stone)
*** Methods
**** new
> Creates a new Editor instance
> NOTE: Propogates error
$ Return:
- `Result<Self>`
**** push
> Pushes a message into the log queue
> Writes to the log file if setup
> NOTE: Doesn't propogate error, pushes into queue
$ Parameters:
- `msg: &str`
** Log
Link: {@ ../src/log.rs}[Log.rs]
*** Fields
- `queue: VecDeque<String>`
-- would like to have own LogMsg trait instead of String eventually
- `file: Option<File>`
*** Methods
**** with_file
> Sets up the file to log to
> NOTE: Doesn't propogate error, pushes into queue
$ Parameters:
- `filename: Option<&str>`
**** push
> Pushes a message into the log queue
> Writes to the log file if setup
> NOTE: Doesn't propogate error, pushes into queue
$ Parameters:
- `msg: &str`
**** pop
> Pops a message off the log queue
** Screen
Link: {@ ../src/screen.rs}[Screen.rs]
*** Fields
*** Methods
*** Enums
**** UpdateEvent
> Notifier to update components when necessary
- StatusBar,
- Document
*** screen::StatusBar
**** Fields
- `msg: Option<Box<dyn Status>>`
- `start: Instant`
- `duration: u128`
**** Methods
***** is_elapsed
> Determines whether status bar element has expired
**** Traits
***** Status
- show(&self) -> String
-- Returns a String to display
** Terminal
Link: {@ ../src/terminal.rs}[Terminal.rs]
** Input
Link: {@ ../src/input.rs}[Input.rs]
-- SubLink: {@ ../src/keybind.rs}[Keybind.rs]
-- SubLink: {@ ../src/command.rs}[Command.rs]
*** Errors
$ InputError:
- `Key(Keybind)`
- `Terminal(TermError)`
- `Command(CommandError)`
*** input::keybind::Keybind
**** Fields
- key: KeyEvent
- command: Command
**** Methods
***** fmt::Display
> Creates a new buffer based off of the passed file content.
$ Modifiers
- Control: `C`
- Shift: `S`
- Alt: `M`
$ KeyCode
- Char(c): `c`
- _: `T`
****** Examples
- `<C-S-b>`
- `<C-A-d>`
- `<S-Backspace>`
- `<C-Left>`
- `<M-f>`
- `<d>`
- `<Enter>/<CR>`
**** Enums
*** input::keybind::Keybinds
**** Fields
- pub keybinds: HashMap<KeyEvent, Keybind>
**** Methods
***** add
> Adds a keybind to the keybinds hashmap
$ Parameters:
- `key: KeyEvent`
- `command: Command`
***** get
> Retrieves the keybind for the given key.
> Returns None if no keybind exists for the given key.
$ Parameters:
- `key: KeyEvent`
$ Return:
- `Option<Command>`
**** Enums
*** input::command::Command
> Can store and execute a list of commands
**** Fields
- `edit_cmds: Vec<EditCommands>`
**** Methods
***** run
> Runs list of commands held in structure
**** Enums
***** EditCommand
- MoveLeft
- MoveDown
- MoveUp
- MoveRight
*** Functions
**** set_default_keybind
> Returns a populated instance of Keybinds with default
> keybinds set.
$ Return:
- `Keybinds`
** Document
Link: {@ ../src/document.rs}[Document.rs]
*** Fields
*** Methods
*** Enums
**** +CursorPosition+ -> ^Position^
> Handles position relative to the cursor.
> Not to be confused with internal buffer position.
**** Position
> Handles position relative to the row and column.
When passed to buffer, will be translated to map appropriately
to the proper position in the internal buffer.
*** Buffer
Link: {@ ../src/buffer.rs}[Buffer.rs]
**** Fields
- text: Rope
**** Methods
***** open
> Creates a new buffer based off of the passed file content.
> If the content is `None` then an empty Rope will be used.
$ Parameters:
- `content: Option<&str>`
$ Return:
- `Result<Self>`
***** insert
> Inserts the passed string at an index retrieved by position
> in the rope. Retrieved by `get_idx`
$ Parameters:
- `&mut self`
- `s: &str`
- `pos: &Position`
$ Return:
- `Result<Self>`
**** Enums
***** InsertItem
> An item type to be used by insertion functions, needs to be
> unicode compliant
- Char
- String
**** Ropey
*** File