Class Utf8edit

UTF8 based editline class.

This class handles a UTF8 string with editing operations, and cursor and width tracking.

Usage:

    local Utf8edit = require("terminal.utf8edit")
    local line = Utf8edit("héllo界")
    
    print(line)                                      -- Output: héllo界
    print("Characters:", line:len_char())            -- Output: Characters: 6
    print("Columns:", line:len_col())                -- Output: Columns: 7 (since '界' is width 2)
    
    -- Move the cursor
    line:left(2)
    print("Cursor char position:", line:pos_char())  -- Output: 4
    print("Cursor column position:", line:pos_col()) -- Output: 4
    
    -- Editing
    line:insert("!")
    print(line)                                      -- Output: héll!o界
    

Functions

UTF8EditLine:backspace ([n=1]) Deletes the character left of the current cursor position.
UTF8EditLine:delete ([n=1]) Deletes the character at the current cursor position.
UTF8EditLine:init ([s=""]) Creates a new utf8edit instance.
UTF8EditLine:insert (s) Inserts a string at the current cursor position.
UTF8EditLine:insert_cp (cp) Inserts a unicode codepoint at the current cursor position.
UTF8EditLine:left ([n=1]) Moves the cursor to the left.
UTF8EditLine:len_char () Returns the current length (chars).
UTF8EditLine:len_col () Returns the current length (columns).
UTF8EditLine:pos_char () Returns the current cursor position (chars).
UTF8EditLine:pos_col () Returns the current cursor position (columns).
UTF8EditLine:right ([n=1]) Moves the cursor to the right.


Functions

UTF8EditLine:backspace ([n=1])
Deletes the character left of the current cursor position. If/once the cursor is at the start of the string, it does nothing.

Parameters:

  • n number the number of characters to delete (default 1)
UTF8EditLine:delete ([n=1])
Deletes the character at the current cursor position. If/once the cursor is at the end of the string, it does nothing.

Parameters:

  • n number the number of characters to delete (default 1)
UTF8EditLine:init ([s=""])
Creates a new utf8edit instance. This method is invoked by calling on the class. The cursor position will be at the end of the string.

Parameters:

  • s string the UTF8 string to parse (default "")

Returns:

    new editline object

Usage:

    local Utf8edit = require("terminal.utf8edit")
    local newLineObj = Utf8edit("héllo界")
UTF8EditLine:insert (s)
Inserts a string at the current cursor position.

Parameters:

  • s string the string to insert
UTF8EditLine:insert_cp (cp)
Inserts a unicode codepoint at the current cursor position.

Parameters:

  • cp number the codepoint to insert
UTF8EditLine:left ([n=1])
Moves the cursor to the left. This function moves the cursor left by n characters. It will not move the cursor past the start of the string (no error will be raised).

Parameters:

  • n number the number of characters to move left (default 1)
UTF8EditLine:len_char ()
Returns the current length (chars).

Returns:

    number the current length in UTF8 characters
UTF8EditLine:len_col ()
Returns the current length (columns).

Returns:

    number the current length in display columns
UTF8EditLine:pos_char ()
Returns the current cursor position (chars).

Returns:

    number the current cursor position in UTF8 characters.
UTF8EditLine:pos_col ()
Returns the current cursor position (columns).

Returns:

    number the current cursor position in display columns
UTF8EditLine:right ([n=1])
Moves the cursor to the right. This function moves the cursor right by n characters. It will not move the cursor past the end of the string (no error will be raised).

Parameters:

  • n number the number of characters to move right (default 1)
generated by LDoc 1.5.0