#include "joey.h" #include "ansiterm.h" #include "ztypes.h" static int head_col; void clear_line(void) { termPrint("\33[K"); } void clear_screen(void) { termClearScreen(); jlDisplayPresent(); termMoveCursor(1, 1); } void clear_status_window(void) { int i; int row; int col; get_cursor_position(&row, &col); for (i=status_size; i; i--) { move_cursor(i, 1); clear_line(); } move_cursor(row, col); } void clear_text_window(void) { int i; int row; int col; get_cursor_position(&row, &col); for (i=status_size + 1; i<=screen_rows; i++) { move_cursor(i, 1); clear_line(); } move_cursor(row, col); } void create_status_window(void) { printf("Create Status Window\n"); } void delete_status_window(void) { printf("Delete Status Window\n"); } void display_char(int c) { termPrintChar((char)c); } void get_cursor_position(int *row, int *col) { termGetCursor(col, row); } void initialize_screen(void) { // Handled in main } int input_character(int timeout) { char k = 0; (void)timeout; // In 1/10ths of a second while (!jlKeyPressed() && !jlUtilMustExit()) { //***TODO*** Animate cursor here? } if (jlKeyPressed()) { while (jlKeyPressed()) { // Wait for key to be released } k = jlKeyRead(); } else { interpreter_state = STOP; } return (int)k; } int input_line(int buflen, char *buffer, int timeout, int *read_size) { int c = -1; int col; int row; int init_char_pos; int curr_char_pos; int loop; int tail_col; (void)timeout; // In 1/10ths of a second get_cursor_position(&row, &col); head_col = tail_col = col; init_char_pos = curr_char_pos = *read_size; while (!jlUtilMustExit()) { c = input_character(0); if (c == 8) { // Backspace get_cursor_position(&row, &col); if (col > head_col) { move_cursor(row, --col); for (loop = curr_char_pos; loop < *read_size; loop++) { buffer[loop - 1] = buffer[loop]; display_char(buffer[loop - 1]); } display_char(' '); curr_char_pos--; tail_col--; (*read_size)--; move_cursor(row, col); } } else { // Normal key if (*read_size == ( buflen - 1 )) { //***TODO*** Buffer full - Flash border? } else { if (c == 13) { // CR scroll_line(); return c; } else { // Used if the cursor is not at the end of the line if (col < tail_col) { // Moves the input line one character to the right for (loop = *read_size; loop >= curr_char_pos; loop--) { buffer[loop + 1] = buffer[loop]; } // Puts the character into the space created by the "for" loop above buffer[curr_char_pos] = (char)c; // Increment the end of the line values (*read_size)++; tail_col++; // Move the cursor back to its original position move_cursor(row, col); // Redisplays the input line from the point of insertion for (loop = curr_char_pos; loop < *read_size; loop++) { display_char(buffer[loop]); } // Moves the cursor to the next position move_cursor(row, ++col); curr_char_pos++; } else { // Used if the cursor is at the end of the line buffer[curr_char_pos++] = (char)c; display_char(c); (*read_size)++; tail_col++; } } } } } return c; } void move_cursor(int row, int col) { termMoveCursor(col, row); } void reset_screen(void) { // Handled in main } void restart_screen(void) { // I don't think we need this. } void restore_cursor_position(void) { termRestoreCursor(); } void save_cursor_position(void) { termSaveCursor(); } void scroll_line(void) { //***TODO*** Should really not clobber the status window. termPrintChar(13); termPrintChar(10); } void select_status_window(void) { save_cursor_position(); } void select_text_window(void) { restore_cursor_position(); } void set_attribute(int attribute) { if (attribute == NORMAL) { termPrint("\33[0m"); } if (attribute & REVERSE) { termPrint("\33[7m"); } }