199 lines
3.3 KiB
C
199 lines
3.3 KiB
C
#include "joey.h"
|
|
#include "ansiterm.h"
|
|
#include "ztypes.h"
|
|
|
|
|
|
static int _cursorIndex = 0;
|
|
static int _cursorSize = 9;
|
|
static unsigned int _cursorTime = 0;
|
|
static byte _cursor[] = { 32, 176, 177, 178, 219, 178, 177, 176, 32 };
|
|
|
|
|
|
void clear_line(void) {
|
|
termPrint("\33[K");
|
|
}
|
|
|
|
|
|
void clear_screen(void) {
|
|
termClearScreen();
|
|
termMoveCursor(1, screen_rows);
|
|
jlDisplayPresent();
|
|
}
|
|
|
|
|
|
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
|
|
if (!jlKeyPressed()) {
|
|
while (!jlKeyPressed() && !jlUtilMustExit()) {
|
|
// Animate cursor
|
|
if (_cursorTime != jlUtilTimer()) {
|
|
display_char(_cursor[_cursorIndex++]);
|
|
display_char(8);
|
|
if (_cursorIndex >= _cursorSize) {
|
|
_cursorIndex = 0;
|
|
}
|
|
_cursorTime = jlUtilTimer();
|
|
}
|
|
}
|
|
display_char(32);
|
|
display_char(8);
|
|
}
|
|
|
|
while (jlKeyPressed() && !jlUtilMustExit()) {
|
|
// Wait for key to be released
|
|
}
|
|
k = jlKeyRead();
|
|
|
|
if (jlUtilMustExit() && (interpreter_state == RUN)) {
|
|
interpreter_state = STOP;
|
|
}
|
|
|
|
return (int)k;
|
|
}
|
|
|
|
|
|
int input_line(int buflen, char *buffer, int timeout, int *read_size) {
|
|
int c = 0;
|
|
int curr_char_pos = 0;
|
|
(void)timeout;
|
|
|
|
while (!jlUtilMustExit()) {
|
|
c = input_character(0);
|
|
if (c > 0) {
|
|
if (c == 8) {
|
|
// Backspace
|
|
if (*read_size == 0) {
|
|
//***TODO*** Flash border or ding or something
|
|
} else {
|
|
--*read_size;
|
|
--curr_char_pos;
|
|
display_char(8);
|
|
display_char(32);
|
|
display_char(8);
|
|
}
|
|
} else {
|
|
// Normal Key
|
|
if (*read_size == (buflen - 1)) {
|
|
//***TODO*** Flash border or ding or something
|
|
} else {
|
|
if (c == 13) {
|
|
scroll_line();
|
|
return c;
|
|
} else {
|
|
buffer[curr_char_pos++] = (char)c;
|
|
if (*read_size < curr_char_pos) {
|
|
*read_size = curr_char_pos;
|
|
}
|
|
display_char(c);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
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");
|
|
}
|
|
}
|