Skip to content

vtf txb _buffercomponents row

srccircumflex edited this page Apr 24, 2023 · 4 revisions

↑ vtf-txb-_buffercomponents

row

Objects

class row._Row

Row object for the processing and editing of text.

A Row can NOT be considered as an independent object, but rather as a tool of the TextBuffer. Basically, direct operations on this type without further ado, can disturb the stability of the whole TextBuffer and cause fatal errors.

A positive return value of the manipulating methods is implemented as WriteItem and the subclass WriteItem.Overflow. This item contains the data for further processing by the TextBuffer. For example, the overflow, which is always returned by writelines, is inserted into the data by TextBuffer depending on the write mode.

Read processes on a _Row can be performed safely.

  • Attribute content: The content data of the line without eventual line break.
  • Attribute end: The end of the row, can be None for a non-existent, "" for a non-breaking or "\n" for an ordinary line break.

Metadata: correct values cannot be assumed until after indexing() has been executed in the buffer. (The main buffer methods handle this).

  • Attribute __row_index__: Indicates the location of the row in the list in the buffer.
  • Attribute __row_num__: Contains the row number (respecting all data).
  • Attribute __line_num__: Contains the line number (respecting all data). A line is defined in comparison to a row, as the area between two line breaks + line break at the end.
  • Attribute __content_start__: Contains the content data start point at the beginning of the row (respecting all data). Content concerns the data without ends in the rows.
  • Attribute __data_start__: Contains the data start point at the beginning of the row (respecting all data). Corresponds to the total number of characters before the row.
  • Attribute __next_row_num__: __row_num__ of the next line.
  • Attribute __next_line_num__: __line_num__ of the next line.
  • Attribute __next_content__: __content_start__ of the next line.
  • Attribute __next_data__: __data_start__ of the next line.
  • Object cursors: _Cursors is used for cursor processing of _Row and contains the positions of the cursor of a row in different contexts. Moving the cursor of the current row over this type has actual effect on the cursor in the TextBuffer.
  • Object data_cache: _DataCache is a data cache for metadata about the row and the stored content.

__content_start__: int

__data_start__: int

__line_num__: int

__next_content__: int

__next_data__: int

__next_line_num__: int

__next_row_num__: int

__row_index__: int

__row_num__: int

autowrap_points: Pattern | None

content: str

cursors: _Cursors

data_cache: _DataCache

end: None | Literal["", "\n"] | str

maxsize_param: int | None

tab_size: int

tab_to_blanks: bool

visual_max: int | None

__bool__() -> bool

Whether written data is available.

__enter__() -> _Row

Start processing independently of the cache memory. (Called by its own methods)

__exit__(*args) -> None

Stop the cache independent processing and clears the cache memory. (Called by its own methods)

__getitem__(item) -> str

eq. <str>[...] (str.__getitem__)

__hash__() -> int

Calculated from:
  • class name
  • __row_num__
  • __line_num__
  • __content_start__
  • __data_start__
  • __row_index__
  • row content
  • row end
  • current content cursor position

__init__(__buffer__, vis_maxsize, autowrap_points, jump_points, back_jump_points, tab_size, tab_to_blanks)

Create a new row.

Parameter:
  • __buffer__
    The TextBuffer object for which _Row is created.
  • vis_maxsize
    The visual representation of the row content includes the shift of the tab character. This parameter can be used to define a maximum visual data size.
  • autowrap_points
    Can be specified for wrapping the row at a specific point as re.Pattern. Then wrapping is done at the end of the re.Match when an vis_maxsize is specified.
  • jump_points
    Jump points for a special cursor movement defined as re.Pattern. Applied when the cursor is moved forward in jump mode, the cursor is then moved to the end point of the re.Match or to the end of the row.
  • back_jump_points
    Jump points for a special cursor movement defined as re.Pattern. Applied when the cursor is moved backward in jump mode, the cursor is then moved to the start point of the re.Match or to the beginning of the row.
  • tab_size
    Define the size of the visual representation of tab shifts.
  • tab_to_blanks
    Converts tabs to spaces directly as they are entered in a write operation, relative to the shift to the next tab stop.

__lt__(other) -> bool

self.__row_num__ < other.__row_num__

classmethod __newrow__(baserow, **kwargs) -> _Row

Create a new row with the parameters from baserow. For the items of kwargs is a simple setattr loop used.

__str__() -> str

row content + row end

backspace() -> WriteItem | None

Delete a character to the left of the cursor.

Returns WriteItem if applicable in the row, otherwise None.

delete(end=False) -> WriteItem | None

Delete a character to the right of the cursor or the row ending.

Returns WriteItem if applicable in the row, otherwise None.

inrow() -> bool

Whether when the main/buffer cursor is in the row.

read_row_content(start, stop, st_gt_end=True) -> tuple[str, str | Literal[False] | None]

Read the area from start to stop in the row (negative indexing is NOT allowed).

Allow the coordinates to be greater than the existing data and read the end of line for it, instead of raising an IndexError if st_gt_end is set to True.

Returns: ( <read content>, <read row end> | False )

replace_tabs(start, stop, to_char=' ') -> WriteItem | None

Replace tab ranges to_char in the range from start to stop in the row (negative indexing is NOT allowed).

Returns WriteItem if applicable in the row, otherwise None.

shift(back=False) -> WriteItem | None

Write depending on the configuration of tab_to_blanks blanks or tabs when forward shifting, remove a tab or at most the equivalent number of blanks at the beginning of the line when back shifting.

Returns WriteItem if applicable in the row, otherwise None.

write(string, sub_chars=False, force_sub_chars=False, sub_line=False, nbnl=False) -> WriteItem

Write the first line from string and create an overflow object from the rest (WriteItem) [ ! ] CR ( "\r" ) is not allowed.

Write in substitute_chars mode to replace characters associatively to the input in the row, at most up to the next tab (only used if neither a newline nor a tab is present in the string); OR

don't care about tabs in the input and apply the substitution also to tabs when the mode forcible_substitute_chars is active; OR

substitute the entire row from the cursor position in mode substitute_line;

and replace line breaks with non-breaking line breaks when nbnl (non-breaking-new-line) is set to True.

Returns: WriteItem

writelines(lines, sub_chars=False, force_sub_chars=False, sub_line=False, nbnl=False) -> WriteItem

Write the first line from list lines and create an overflow object from the rest (WriteItem) [ ! ] CR ( "\r" ) is not allowed.

Write in substitute_chars mode to replace characters associatively to the input in the row, at most up to the next tab (only used if neither a newline nor a tab is present in the string); OR

don't care about tabs in the input and apply the substitution also to tabs when the mode forcible_substitute_chars is active; OR

substitute the entire row from the cursor position in mode substitute_line;

and replace line breaks with non-breaking line breaks when nbnl (non-breaking-new-line) is set to True.

Returns: WriteItem

Components

class row._CursorCache

LRU-Cache for cursor (_Cursors) translations.

The maximum number of values stored in a method-slot is queried from TextBuffer (__cursor_translation_cache_sizes__).

__enter__() -> None

Independent processing.

__exit__(*args) -> None

Stops independent processing.

clear() -> None

Clear each method cache.

class row._Cursors

Row Cursor processing.

The methods with tool_ prefix can be used to calculate coordinates in relation to the data in the _Row. In addition, information about the cursor positioning of the _Row can be retrieved. Within the object a cache is used for the calculations, the maximum size of a method-memory in the _CursorCache is queried from TextBuffer (__cursor_translation_cache_sizes__).

back_jump_points: Pattern

Configured by _Row.

content: int

Cursor position within the row-content-string.

cur_translation_cache: _CursorCache

in_segment: int

Cursor position within the tap-separated-row-content-string-segment.

jump_points: Pattern

Configured by _Row.

segment: int

Segment number of the tap-separated-row-content-string in which the cursor is located.

vis_pos_max: int | None

Configured by _Row.

visual: int

Row-Cursor position with consideration of the visual representation of tab spaces.
@property
content_limit() -> int

Current maximum position of the content cursor.

_CursorCache slot: 5

@property
data_cursor() -> int
The current cursor position in the totality of the data.

move(__z, jump=False, border=False) -> bool

Move the cursor of a _Row by a content-cursor-summand (integer). Jump to a predefined point or to the outermost border of the data, in which case __z indicates the direction. Return True if the movement was successful, otherwise False.

Depending on whether this row is defined as current_row in the TextBuffer, this has an effect on the main cursor in the buffer.

new_cnt_cursor(__z, jump=False, border=False, as_far=False) -> int | None

Calculate and verify a new content-cursor position in the _Row by a content-cursor-summand (integer). Jump to a predefined point or to the outermost border of the data, in which case __z indicates the direction. Return the new content-cursor when the position is in proportion to the data, otherwise None.

reset() -> None

Reset each value to 0.

set_by_cnt(__n) -> None

Set the cursors by a content-cursor position (natural number).

Depending on whether this row is defined as current_row in the TextBuffer, this has an effect on the main cursor in the buffer.

raises:
  • IndexError: if n is too large in relation to the row data

set_by_vis(__n) -> None

Set the cursors by a visual-cursor position (natural number).

Depending on whether this row is defined as current_row in the TextBuffer, this has an effect on the main cursor in the buffer.

raises:
  • IndexError: if n is too large in relation to the row data

tool_cnt_to_seg_in_seg(__n) -> tuple[int, int]

Segment-cursors in relation to content-cursor.

_CursorCache slot: 2

raises:
  • IndexError: if n is too large in relation to the row data

tool_cnt_to_vis(__n) -> int

Visual-cursor in relation to content-cursor.

_CursorCache slot: 3

raises:
  • IndexError: if n is too large in relation to the row data

tool_seg_in_seg_to_vis(seg, in_seg) -> int

Visual-cursor in relation to segment-cursors.

_CursorCache slot: 1

tool_vis_to_cnt(__n) -> int

Content-cursor in relation to visual-cursor, incl. incompletely enclosed tab.

_CursorCache slot: 4

raises:
  • IndexError: if n is too large in relation to the row data

tool_vis_to_cnt_excl(__n) -> int

Content-cursor in relation to visual-cursor, excl. incompletely enclosed tab.

_CursorCache slot: 0

raises:
  • IndexError: if n is too large in relation to the row data

class row._DataCache

Row Metadata Cache.

@property
free_space() -> int | None
Remaining content space in the row. Is an integer value only if a maximum is defined.
@property
len_abscontent() -> int
The total content length at the end of the row (excl. line breaks).
@property
len_absdata() -> int
The total data length at the end of the row (incl. all line breaks).
@property
len_absdata_excl() -> int
The total data length at the end of the row (incl. all line breaks, except the own).
@property
len_content() -> int
The string length.
@property
len_visual() -> int
The visual length (incl. visual tab representation).
@property
len_visual_incl() -> int
The visual length (incl. visual tab representation) incl. linebreak.
@property
raster() -> list[str]
The row data as tab separated raster.
@property
visual_len_index() -> list[int]
The visual lengths of each segment.

__enter__() -> None

Independent processing.

__exit__(*args) -> None

Stops independent processing.

change() -> None

Mark a change.

reset() -> None

Clear each field.

Date: 20 Dec 2022
Version: 0.1
Author: Adrian Hoefflin [srccircumflex]
Doc-Generator: "pyiStructure-RSTGenerator" <prototype>
Clone this wiki locally