This commit is contained in:
Ognjen Milan Robovic 2023-11-04 21:16:51 -04:00
parent 19017523c6
commit 27a152211b

View File

@ -6,18 +6,9 @@ And when you do redistribute it or modify it, it will use either version 3 of th
It is distributed in the hope that it will be useful or harmful, it really depends... But no warranty what so ever, seriously. See GNU/GPLv3.
*/
#include <xolatile/xtandard.c>
#include <xolatile/xyntax.c>
#include <xolatile/xurses.c>
#define CONTROL (0X1F)
#define ESCAPE (0X1B)
#define BACKSPACE (0X7F)
#define ARROW_UP (0X415B1B)
#define ARROW_DOWN (0X425B1B)
#define ARROW_RIGHT (0X435B1B)
#define ARROW_LEFT (0X445B1B)
int main (int argc, char * * argv) {
char * keywords [] = {
"register", "volatile", "auto", "const", "static", "extern", "if", "else",
@ -57,36 +48,49 @@ int main (int argc, char * * argv) {
curses_render_background (' ', COLOUR_WHITE, EFFECT_NORMAL);
/* Work in progress, this will be factored out or removed. */
length = 0;
curses_render_string (file_list_name [file_list_active], COLOUR_WHITE, EFFECT_REVERSE, length, 0);
length += string_length (file_list_name [file_list_active]);
/* */
curses_render_string (" $ ", COLOUR_WHITE, EFFECT_REVERSE, length, 0);
curses_render_string (" $ ", COLOUR_RED, EFFECT_REVERSE, length, 0);
length += 3;
curses_render_string (number_to_string (file_list_size [file_list_active]), COLOUR_WHITE, EFFECT_REVERSE, length, 0);
length += string_length (number_to_string (file_list_size [file_list_active]));
/* */
curses_render_string (" O ", COLOUR_WHITE, EFFECT_REVERSE, length, 0);
curses_render_string (" O ", COLOUR_GREEN, EFFECT_REVERSE, length, 0);
length += 3;
curses_render_string (number_to_string (cursor), COLOUR_WHITE, EFFECT_REVERSE, length, 0);
length += string_length (number_to_string (cursor));
/* */
curses_render_string (" X ", COLOUR_WHITE, EFFECT_REVERSE, length, 0);
curses_render_string (" X ", COLOUR_YELLOW, EFFECT_REVERSE, length, 0);
length += 3;
curses_render_string (number_to_string (cursor_x), COLOUR_WHITE, EFFECT_REVERSE, length, 0);
length += string_length (number_to_string (cursor_x));
/* */
curses_render_string (" Y ", COLOUR_WHITE, EFFECT_REVERSE, length, 0);
curses_render_string (" Y ", COLOUR_BLUE, EFFECT_REVERSE, length, 0);
length += 3;
curses_render_string (number_to_string (cursor_y), COLOUR_WHITE, EFFECT_REVERSE, length, 0);
length += string_length (number_to_string (cursor_y));
/* */
offset = character_count (file_list_data [file_list_active], CHARACTER_TAB_HORIZONTAL, cursor, 0, CHARACTER_LINE_FEED);
curses_render_string (" I ", COLOUR_CYAN, EFFECT_REVERSE, length, 0);
length += 3;
curses_render_string (number_to_string (offset), COLOUR_WHITE, EFFECT_REVERSE, length, 0);
length += string_length (number_to_string (offset));
/* */
curses_render_string (" C ", COLOUR_PINK, EFFECT_REVERSE, length, 0);
length += 3;
curses_render_character (file_list_data [file_list_active] [cursor], COLOUR_WHITE, EFFECT_REVERSE, length, 0);
length += 1;
for (offset = length; offset != curses_screen_width; ++offset) {
curses_render_string (" ", COLOUR_WHITE, EFFECT_REVERSE, offset, 0);
}
for (offset = 1; offset != curses_screen_height; ++offset) {
curses_render_string (string_realign (number_to_string (offset), 4, ' '), COLOUR_WHITE, EFFECT_REVERSE, 0, offset);
curses_render_string (string_realign (number_to_string (offset), 4, ' '), (offset == cursor_y + 1) ? COLOUR_GREEN : COLOUR_WHITE, EFFECT_REVERSE, 0, offset);
}
cursor_x = curses_realign_x = 5; /* Border offset... */
@ -112,34 +116,42 @@ int main (int argc, char * * argv) {
}
}
cursor_on_new_line = (file_list_data [file_list_active] [cursor] == '\n');
cursor_on_new_line = (file_list_data [file_list_active] [cursor] == CHARACTER_LINE_FEED);
cursor_y = character_count (file_list_data [file_list_active], '\n', 0, cursor + cursor_on_new_line, '\0') - cursor_on_new_line;
cursor_x = character_count (file_list_data [file_list_active], '\0', cursor - cursor_on_new_line, 0, '\n') + cursor_on_new_line;
/*cursor_y = character_count (file_list_data [file_list_active], CHARACTER_LINE_FEED, 0, cursor + cursor_on_new_line, CHARACTER_NULL) - cursor_on_new_line;
cursor_x = character_count (file_list_data [file_list_active], CHARACTER_NULL, cursor - cursor_on_new_line, 0, CHARACTER_LINE_FEED) + cursor_on_new_line;*/
cursor_y = character_count (file_list_data [file_list_active], CHARACTER_LINE_FEED, 0, cursor, CHARACTER_NULL);
cursor_x = character_count (file_list_data [file_list_active], CHARACTER_NULL, cursor - cursor_on_new_line, 0, CHARACTER_LINE_FEED) + cursor_on_new_line;
cursor_x += character_count (file_list_data [file_list_active], CHARACTER_TAB_HORIZONTAL, cursor, 0, CHARACTER_LINE_FEED) * (curses_tab_width - 1);
if (cursor_on_new_line && (file_list_data [file_list_active] [cursor - 1] == CHARACTER_LINE_FEED)) {
cursor_x = 0;
}
/*
dump ("a.log", string_concatenate (number_to_string (cursor_x), "\n"));
dump ("a.log", string_concatenate (number_to_string (curses_signal), "\n"));
*/
curses_render_cursor (cursor_x + curses_realign_x, cursor_y + curses_realign_y);
curses_synchronize ();
if (curses_character == (int) ('Q' & CONTROL)) {
if (curses_character == (int) ('Q' & 0X1F)) {
curses_active = 0;
} else if (curses_character == (int) '\r') {
file_list_insert_character ('\n', cursor);
++cursor;
} else if (curses_character == (int) ('S' & CONTROL)) {
} else if (curses_character == (int) ('S' & 0X1F)) {
file_list_export (file_list_name [file_list_active]);
} else if (curses_character == BACKSPACE) {
} else if (curses_character == SIGNAL_DELETE) {
file_list_remove_character (cursor);
--cursor;
} else if (curses_character == ARROW_UP) {
cursor -= character_count (file_list_data [file_list_active], '\0', cursor - 1, 0, '\n') - 1;
} else if (curses_character == ARROW_DOWN) {
cursor += character_count (file_list_data [file_list_active], '\0', cursor, file_list_size [file_list_active] - 1, '\n') + 1;
} else if (curses_character == ARROW_RIGHT) {
} else if (curses_character == SIGNAL_ARROW_UP) {
cursor -= character_count (file_list_data [file_list_active], CHARACTER_NULL, cursor - cursor_on_new_line, 0, CHARACTER_LINE_FEED) - 1;
} else if (curses_character == SIGNAL_ARROW_DOWN) {
cursor += character_count (file_list_data [file_list_active], CHARACTER_NULL, cursor + cursor_on_new_line, file_list_size [file_list_active] - 1, CHARACTER_LINE_FEED) + 1;
} else if (curses_character == SIGNAL_ARROW_RIGHT) {
++cursor;
} else if (curses_character == ARROW_LEFT) {
} else if (curses_character == SIGNAL_ARROW_LEFT) {
--cursor;
} else if (character_is_visible ((char) curses_character) != 0) {
file_list_insert_character ((char) curses_character, cursor);