struct _ply_rich_text_t
{
- ply_array_t *characters;
- size_t reference_count;
+ ply_array_t *characters;
+ ply_rich_text_span_t span;
+ size_t reference_count;
};
ply_rich_text_t *
void
ply_rich_text_character_free (ply_rich_text_character_t *character)
{
+ if (character == NULL)
+ return;
+
free (character->bytes);
free (character);
}
characters = ply_rich_text_get_characters (rich_text);
+ if (character_index < rich_text->span.offset)
+ return;
+
+ if (character_index >= rich_text->span.offset + rich_text->span.range)
+ return;
+
+
if (characters[character_index] == NULL)
return;
size_t new_index)
{
ply_rich_text_character_t **characters = ply_rich_text_get_characters (rich_text);
+
+ if (old_index < rich_text->span.offset)
+ return;
+
+ if (new_index < rich_text->span.offset)
+ return;
+
+ if (old_index >= rich_text->span.offset + rich_text->span.range)
+ return;
+
+ if (new_index >= rich_text->span.offset + rich_text->span.range)
+ return;
+
+
characters[new_index] = characters[old_index];
characters[old_index] = NULL;
}
ply_rich_text_character_t **characters;
ply_rich_text_character_t *character;
+ while (ply_array_get_size (rich_text->characters) <= character_index) {
+ ply_array_add_pointer_element (rich_text->characters, NULL);
+ }
+
+
+ if (character_index < rich_text->span.offset)
+ return;
+
+ if (character_index >= rich_text->span.offset + rich_text->span.range)
+ return;
+
+
characters = ply_rich_text_get_characters (rich_text);
if (characters[character_index] == NULL) {
character = ply_rich_text_character_new ();
- ply_array_add_pointer_element (rich_text->characters, character);
- characters = (ply_rich_text_character_t **) ply_array_get_pointer_elements (rich_text->characters);
} else {
character = characters[character_index];
if (character->bytes) {
return true;
}
+
+void
+ply_rich_text_set_mutable_span (ply_rich_text_t *rich_text,
+ ply_rich_text_span_t *span)
+{
+ rich_text->span = *span;
+}
+
+void
+ply_rich_text_get_mutable_span (ply_rich_text_t *rich_text,
+ ply_rich_text_span_t *span)
+{
+ *span = rich_text->span;
+}
#include <stdio.h>
-#ifndef PLY_TERMINAL_LINE_MAX
-#define PLY_TERMINAL_LINE_MAX 4096
-#endif
-
#define PLY_TERMINAL_SPACES_PER_TAB 8
/* Characters between 64 to 157 end the escape sequence strings (in testing)
{
ply_terminal_emulator_parse_state_t state;
- size_t maximum_line_count;
+ size_t number_of_rows;
+ size_t number_of_columns;
+
size_t line_count;
ply_array_t *lines;
static void ply_terminal_emulator_command_free (ply_terminal_emulator_command_t *command);
ply_terminal_emulator_t *
-ply_terminal_emulator_new (size_t maximum_line_count)
+ply_terminal_emulator_new (size_t number_of_rows,
+ size_t number_of_columns)
{
ply_terminal_emulator_t *terminal_emulator;
+ ply_rich_text_t *terminal_emulator_line;
+ ply_rich_text_span_t span;
terminal_emulator = calloc (1, sizeof(struct _ply_terminal_emulator));
terminal_emulator->line_count = 1;
- terminal_emulator->maximum_line_count = maximum_line_count;
+ terminal_emulator->number_of_rows = number_of_rows;
+ terminal_emulator->number_of_columns = number_of_columns;
terminal_emulator->lines = ply_array_new (PLY_ARRAY_ELEMENT_TYPE_POINTER);
- for (int i = 0; i < terminal_emulator->maximum_line_count; i++) {
- ply_array_add_pointer_element (terminal_emulator->lines, ply_rich_text_new ());
+
+ span.offset = 0;
+ span.range = terminal_emulator->number_of_columns;
+
+ for (int i = 0; i < terminal_emulator->number_of_rows; i++) {
+ terminal_emulator_line = ply_rich_text_new ();
+ ply_rich_text_set_mutable_span (terminal_emulator_line, &span);
+ ply_array_add_pointer_element (terminal_emulator->lines, terminal_emulator_line);
}
terminal_emulator->cursor_row_offset = 0;
size_t new_string_length;
size_t append_count;
size_t string_move_end_offset;
+ ply_rich_text_span_t span;
+ size_t maximum_characters;
ply_trace ("terminal control sequence: insert blank characters");
parameter = 1;
}
+ ply_rich_text_get_mutable_span (terminal_emulator->current_line, &span);
+ maximum_characters = span.offset + span.range;
+
new_string_length = string_length + parameter;
- if (new_string_length >= PLY_TERMINAL_LINE_MAX) {
- append_count = PLY_TERMINAL_LINE_MAX - string_length - 1;
- new_string_length = PLY_TERMINAL_LINE_MAX - 1;
+ if (new_string_length >= maximum_characters) {
+ append_count = maximum_characters - string_length - 1;
+ new_string_length = maximum_characters - 1;
} else {
append_count = parameter;
}
string_move_end_offset = string_length - 1;
- if (string_move_end_offset >= PLY_TERMINAL_LINE_MAX)
- string_move_end_offset = PLY_TERMINAL_LINE_MAX - 1;
+ if (string_move_end_offset >= maximum_characters)
+ string_move_end_offset = maximum_characters - 1;
if (new_string_length <= 0)
return PLY_TERMINAL_EMULATOR_BREAK_STRING_NONE;
{
int parameter;
size_t string_length = ply_rich_text_get_length (terminal_emulator->current_line);
+ ply_rich_text_span_t span;
+ size_t maximum_characters;
ply_trace ("terminal control sequence: move cursor right");
terminal_emulator->cursor_column += parameter;
- if (terminal_emulator->cursor_column >= PLY_TERMINAL_LINE_MAX)
+ ply_rich_text_get_mutable_span (terminal_emulator->current_line, &span);
+ maximum_characters = span.offset + span.range;
+
+ if (terminal_emulator->cursor_column >= maximum_characters)
return PLY_TERMINAL_EMULATOR_BREAK_STRING;
fill_offsets_with_padding (terminal_emulator, string_length, terminal_emulator->cursor_column);
bool paramaters_valid)
{
int parameter;
+ ply_rich_text_span_t span;
+ size_t maximum_characters;
size_t string_length = ply_rich_text_get_length (terminal_emulator->current_line);
parameter = 1;
}
- if (parameter > PLY_TERMINAL_LINE_MAX) {
+ ply_rich_text_get_mutable_span (terminal_emulator->current_line, &span);
+ maximum_characters = span.offset + span.range;
+
+ if (parameter > maximum_characters) {
terminal_emulator->cursor_column = 1;
} else {
/* parameter is never 0. the column '1' represents the 0 index on the string */
size_t starting_offset = terminal_emulator->cursor_column;
size_t string_length = ply_rich_text_get_length (terminal_emulator->current_line);
size_t i;
+ ply_rich_text_span_t span;
+ size_t maximum_characters;
ply_trace ("terminal control sequence: erase line");
erase_line_type = PLY_TERMINAL_EMULATOR_ERASE_LINE_TYPE_CURSOR_TO_RIGHT;
}
- if (starting_offset >= PLY_TERMINAL_LINE_MAX)
- starting_offset = PLY_TERMINAL_LINE_MAX - 1;
+ ply_rich_text_get_mutable_span (terminal_emulator->current_line, &span);
+ maximum_characters = span.offset + span.range;
+
+ if (starting_offset >= maximum_characters)
+ starting_offset = maximum_characters - 1;
if (erase_line_type == PLY_TERMINAL_EMULATOR_ERASE_LINE_TYPE_CURSOR_TO_LEFT || erase_line_type == PLY_TERMINAL_EMULATOR_ERASE_LINE_TYPE_WHOLE_LINE) {
/* Ensure that all characters from the start of the string to the cursor are spaces */
size_t string_length = ply_rich_text_get_length (terminal_emulator->current_line);
size_t new_cursor_position;
size_t new_string_length;
+ ply_rich_text_span_t span;
+ size_t maximum_characters;
ply_trace ("terminal escape character: tab");
pad_character_count = PLY_TERMINAL_SPACES_PER_TAB - (terminal_emulator->cursor_column % PLY_TERMINAL_SPACES_PER_TAB);
}
+ ply_rich_text_get_mutable_span (terminal_emulator->current_line, &span);
+ maximum_characters = span.offset + span.range;
+
new_cursor_position = terminal_emulator->cursor_column + pad_character_count;
- if (new_cursor_position >= PLY_TERMINAL_LINE_MAX - 1)
- new_cursor_position = PLY_TERMINAL_LINE_MAX - 1;
+ if (new_cursor_position >= maximum_characters - 1)
+ new_cursor_position = maximum_characters - 1;
terminal_emulator->cursor_column = new_cursor_position;
new_string_length = string_length + pad_character_count;
- if (new_string_length >= PLY_TERMINAL_LINE_MAX - 1)
- new_string_length = PLY_TERMINAL_LINE_MAX - 1;
+ if (new_string_length >= maximum_characters - 1)
+ new_string_length = maximum_characters - 1;
for (size_t i = string_length; i < new_string_length; i++) {
ply_rich_text_set_character (terminal_emulator->current_line, terminal_emulator->current_style, i, " ", 1);
int line_number)
{
ply_rich_text_t *const *console_lines = (ply_rich_text_t *const *) ply_array_get_pointer_elements (terminal_emulator->lines);
- return console_lines[line_number % terminal_emulator->maximum_line_count];
+ return console_lines[line_number % terminal_emulator->number_of_rows];
}
int
ply_terminal_emulator_break_string_t break_string = PLY_TERMINAL_EMULATOR_BREAK_STRING_NONE;
int parameter_value;
ply_terminal_emulator_command_t *command;
+ ply_rich_text_span_t span;
+ size_t maximum_characters;
int character_length;
ply_list_node_t *node;
return;
}
- if (terminal_emulator->cursor_column >= PLY_TERMINAL_LINE_MAX)
+ ply_rich_text_get_mutable_span (terminal_emulator->current_line, &span);
+ maximum_characters = span.offset + span.range;
+
+ if (terminal_emulator->cursor_column >= maximum_characters)
terminal_emulator->cursor_column = 0;
new_length = ply_rich_text_get_length (terminal_emulator->current_line);
i++;
- if (i >= PLY_TERMINAL_LINE_MAX)
+ if (i >= maximum_characters)
break;
}
ply_rich_text_set_character (terminal_emulator->current_line, terminal_emulator->current_style, terminal_emulator->cursor_column, character_string, character_length);
ply_rich_text_set_character (terminal_emulator->current_line, terminal_emulator->current_style, terminal_emulator->cursor_column, character_string, 1);
terminal_emulator->cursor_column++;
- if (terminal_emulator->cursor_column >= PLY_TERMINAL_LINE_MAX) {
- terminal_emulator->cursor_column = 0;
+ if (terminal_emulator->cursor_column >= maximum_characters) {
+ terminal_emulator->cursor_row_offset++;
+ terminal_emulator->break_action = PLY_TERMINAL_EMULATOR_BREAK_STRING_ACTION_RESET_CURSOR_COLUMN;
break_string = PLY_TERMINAL_EMULATOR_BREAK_STRING;
}
}