class documentation

A MicroPython text editor running on a virtual terminal.

Method __init__ Initialize the editor state.
Method check_mark Decrement the mark priority and clear it when expired.
Method clear_mark Clear the selection mark state.
Method clear_to_eol Clear the line from the cursor to the end.
Method cursor Show or hide the terminal cursor.
Method delete_mark Delete the selected text, optionally yanking it first.
Method display_window Render the current editor window to the terminal.
Method edit_loop Run the main editor loop until quit or a handoff key.
Method expandtabs Expand tab characters into spaces.
Method find_in_file Find a pattern in the file starting from a position.
Method get_file Load a file or directory listing into the editor.
Method get_input Read and decode one key press from the terminal.
Method getsymbol Return the symbol around the given position.
Method goto Move the cursor to the given position.
Method handle_edit_keys Handle a decoded key and apply the corresponding edit.
Method hash_buffer Compute a hash of the current buffer content.
Method hilite Set the terminal highlight mode.
Method issymbol Check if a character is a symbol character.
Method line_edit Edit a single line of input at the status line.
Method line_range Return the selected line range.
Method mark_order Return the ordering of a position relative to the mark.
Method mark_range Return the normalized selection range.
Method mouse_reporting Enable or disable terminal mouse reporting.
Method move_down Move the cursor down one line.
Method move_left Move the cursor left one column.
Method move_right Move the cursor right one column.
Method move_up Move the cursor up one line.
Method packtabs Pack runs of spaces into tab characters.
Method put_file Save the buffer to a file.
Method redraw Redraw the editor screen.
Method scroll_down Scroll the terminal down by the given number of lines.
Method scroll_region Set or clear the terminal scroll region.
Method scroll_up Scroll the terminal up by the given number of lines.
Method set_mark Set the selection mark.
Method skip_down Move down when the cursor is at the end of a line.
Method skip_until Skip non-symbol characters in a direction.
Method skip_up Move up when the cursor is at the start of a line.
Method skip_while Skip symbol characters in a direction.
Method spaces Count leading spaces in a line up to a position.
Method undo_add Add an edit action to the undo stack.
Method undo_redo Move actions between the undo and redo stacks.
Method yank_mark Copy the selected text into the yank buffer.
Constant KEYMAP Undocumented
Constant TERMCMD Undocumented
Class Variable autoindent Undocumented
Class Variable case Undocumented
Class Variable comment_char Undocumented
Class Variable file_char Undocumented
Class Variable find_pattern Undocumented
Class Variable match_span Undocumented
Class Variable max_places Undocumented
Class Variable place_index Undocumented
Class Variable place_list Undocumented
Class Variable replc_pattern Undocumented
Class Variable word_char Undocumented
Class Variable yank_buffer Undocumented
Instance Variable changed Undocumented
Instance Variable col Undocumented
Instance Variable content Undocumented
Instance Variable cur_line Undocumented
Instance Variable fname Undocumented
Instance Variable hash Undocumented
Instance Variable io_device Undocumented
Instance Variable is_dir Undocumented
Instance Variable key_max Undocumented
Instance Variable margin Undocumented
Instance Variable mark Undocumented
Instance Variable mark_flag Undocumented
Instance Variable message Undocumented
Instance Variable mouse_last Undocumented
Instance Variable redo Undocumented
Instance Variable row Undocumented
Instance Variable storage Undocumented
Instance Variable tab_size Undocumented
Instance Variable top_line Undocumented
Instance Variable total_lines Undocumented
Instance Variable undo Undocumented
Instance Variable undo_index Undocumented
Instance Variable undo_limit Undocumented
Instance Variable vcol Undocumented
Instance Variable work_dir Undocumented
Instance Variable wr Undocumented
Instance Variable write_tabs Undocumented
def __init__(self, tab_size, undo_limit, io_device, storage=None):

Initialize the editor state.

Parameters
tab_size:intThe tab width in spaces.
undo_limit:intThe maximum number of undo entries.
io_deviceThe virtual terminal device.
storage:Storage or NoneThe storage interface. Defaults to None.
def check_mark(self):

Decrement the mark priority and clear it when expired.

def clear_mark(self):

Clear the selection mark state.

def clear_to_eol(self):

Clear the line from the cursor to the end.

def cursor(self, onoff):

Show or hide the terminal cursor.

Parameters
onoff:boolTrue to show the cursor, False to hide it.
def delete_mark(self, yank):

Delete the selected text, optionally yanking it first.

Parameters
yank:boolTrue to copy the selection before deleting.
def display_window(self):

Render the current editor window to the terminal.

def edit_loop(self):

Run the main editor loop until quit or a handoff key.

Returns
int or EditorThe quit key, handoff key, or target editor.
def expandtabs(self, s):

Expand tab characters into spaces.

Parameters
s:strThe text to expand.
Returns
strThe expanded text.
def find_in_file(self, pattern, col, end):

Find a pattern in the file starting from a position.

Parameters
pattern:strThe search pattern.
col:intThe starting column.
end:intThe end line.
Returns
int or NoneThe match length, or None if not found.
def get_file(self, fname):

Load a file or directory listing into the editor.

Parameters
fname:strThe file or directory path.
def get_input(self):

Read and decode one key press from the terminal.

Returns
tupleThe key code and optional character data.
def getsymbol(self, s, pos, zap):

Return the symbol around the given position.

Parameters
s:strThe line text.
pos:intThe cursor position.
zap:str or NoneSymbol characters.
Returns
strThe symbol text, or an empty string.
def goto(self, row, col):

Move the cursor to the given position.

Parameters
row:intThe zero-based row.
col:intThe zero-based column.
def handle_edit_keys(self, key, char):

Handle a decoded key and apply the corresponding edit.

Parameters
key:intThe key code.
char:str or NoneThe character for text input.
Returns
int or EditorThe resulting key or a target editor.
def hash_buffer(self):

Compute a hash of the current buffer content.

Returns
intThe buffer hash.
def hilite(self, mode):

Set the terminal highlight mode.

Parameters
mode:intThe highlight mode (0 normal, 1 status, 2 inverse).
def issymbol(self, c, zap):

Check if a character is a symbol character.

Parameters
c:strThe character to check.
zap:strSymbol characters.
Returns
boolTrue if the character is a symbol.
def line_edit(self, prompt, default, zap=None):

Edit a single line of input at the status line.

Parameters
prompt:strThe prompt text.
default:strThe default value.
zap:str or NoneCharacters treated as symbol characters. Defaults to None.
Returns
str or NoneThe entered value, or None if cancelled.
def line_range(self):

Return the selected line range.

Returns
tupleThe start and end lines.
def mark_order(self, line, col):

Return the ordering of a position relative to the mark.

Parameters
line:intThe line to compare.
col:intThe column to compare.
Returns
intThe difference in line or column order.
def mark_range(self):

Return the normalized selection range.

Returns
tupleThe start line, start column, end line, and end column.
def mouse_reporting(self, onoff):

Enable or disable terminal mouse reporting.

Parameters
onoff:boolTrue to enable, False to disable.
def move_down(self):

Move the cursor down one line.

def move_left(self):

Move the cursor left one column.

def move_right(self, l):

Move the cursor right one column.

Parameters
l:strThe current line text.
def move_up(self):

Move the cursor up one line.

def packtabs(self, s):

Pack runs of spaces into tab characters.

Parameters
s:strThe text to pack.
Returns
strThe packed text.
def put_file(self, fname):

Save the buffer to a file.

Parameters
fname:strThe destination file path.
Raises
OSErrorIf the file cannot be written.
def redraw(self, flag):

Redraw the editor screen.

Parameters
flag:boolWhether to show the version banner.
def scroll_down(self, scrolling):

Scroll the terminal down by the given number of lines.

Parameters
scrolling:intThe number of lines to scroll.
def scroll_region(self, stop):

Set or clear the terminal scroll region.

Parameters
stop:int or NoneThe last scroll line, or None to reset.
def scroll_up(self, scrolling):

Scroll the terminal up by the given number of lines.

Parameters
scrolling:intThe number of lines to scroll.
def set_mark(self, flag=999999999):

Set the selection mark.

Parameters
flag:intThe mark priority. Defaults to 999999999.
def skip_down(self, l):

Move down when the cursor is at the end of a line.

Parameters
l:strThe current line text.
Returns
boolTrue if the cursor moved down.
def skip_until(self, s, pos, zap, way):

Skip non-symbol characters in a direction.

Parameters
s:strThe line text.
pos:intThe starting position.
zap:strSymbol characters.
way:intThe direction, -1 or 1.
Returns
intThe position after skipping.
def skip_up(self):

Move up when the cursor is at the start of a line.

Returns
boolTrue if the cursor moved up.
def skip_while(self, s, pos, zap, way):

Skip symbol characters in a direction.

Parameters
s:strThe line text.
pos:intThe starting position.
zap:strSymbol characters.
way:intThe direction, -1 or 1.
Returns
intThe position after skipping.
def spaces(self, line, pos=None):

Count leading spaces in a line up to a position.

Parameters
line:strThe line text.
pos:int or NoneThe position to measure up to. Defaults to None.
Returns
intThe number of leading spaces.
def undo_add(self, lnum, text, key, span=1, chain=False):

Add an edit action to the undo stack.

Parameters
lnum:intThe affected line number.
text:listThe affected line contents.
key:intThe key that caused the edit.
span:intThe number of affected lines. Defaults to 1.
chain:boolWhether to chain with the next action. Defaults to False.
def undo_redo(self, undo, redo):

Move actions between the undo and redo stacks.

Parameters
undo:listThe source stack.
redo:listThe destination stack.
def yank_mark(self):

Copy the selected text into the yank buffer.

KEYMAP =

Undocumented

Value
{'\x1b[A': KEY_UP,
 '\x1b[1;2A': KEY_SHIFT_UP,
 '\x1b[1;3A': KEY_ALT_UP,
 '\x1b[B': KEY_DOWN,
 '\x1b[1;2B': KEY_SHIFT_DOWN,
 '\x1b[1;3B': KEY_ALT_DOWN,
 '\x1b[D': KEY_LEFT,
...
TERMCMD: list[str] =

Undocumented

Value
['\x1b[{row};{col}H',
 '\x1b[0K',
 '\x1b[?25h',
 '\x1b[?25l',
 '\x1b[0m',
 '\x1b[1;37;44m',
 '\x1b[43m',
...
autoindent: str =

Undocumented

case: str =

Undocumented

comment_char: str =

Undocumented

file_char: str =

Undocumented

find_pattern: str =

Undocumented

match_span: int =

Undocumented

max_places: int =

Undocumented

place_index: int =

Undocumented

place_list: list =

Undocumented

replc_pattern: str =

Undocumented

word_char: str =

Undocumented

yank_buffer: list =

Undocumented

changed: str =

Undocumented

col =

Undocumented

content =

Undocumented

cur_line =

Undocumented

fname =

Undocumented

hash =

Undocumented

io_device =

Undocumented

is_dir: bool =

Undocumented

key_max =

Undocumented

margin =

Undocumented

mark =

Undocumented

mark_flag: int =

Undocumented

message =

Undocumented

mouse_last: tuple[int, ...] =

Undocumented

redo: list =

Undocumented

row =

Undocumented

storage =

Undocumented

tab_size =

Undocumented

top_line =

Undocumented

total_lines =

Undocumented

undo: list =

Undocumented

undo_index: int =

Undocumented

undo_limit =

Undocumented

vcol =

Undocumented

work_dir =

Undocumented

wr =

Undocumented

write_tabs: bool =

Undocumented