/*
* this is the ncurses implementation of sc-im user interface, or called tui.
* it mainly consists on the following two windows:
* main_win: window that shows the grid
* input_win: state bar window and stdin input
*
* these are the functions called outside tui.c:
* ui_start_screen
* ui_stop_screen
* ui_show_header
* ui_update
* ui_do_welcome
* ui_handle_cursor
* ui_yyerror
* ui_show_text
* ui_bail
* ui_sc_msg
* ui_winchg
* ui_print_mult_pend
* ui_show_celldetails
* ui_start_colors
* ui_set_ucolor
* ui_clr_header
* ui_print_mode
*
* these functions are here and should be out of tui.c:
* pad_and_align
* calc_offscr_sc_cols
* calc_offscr_sc_rows
*
* once these three are arranged,
* ANYONE WHO WANTS TO PORT THIS TO ANOTHER UI, WOULD JUST NEED TO REIMPLEMENT THIS FILE
* AND HELP() IN HELP.C
*/
#include <string.h>
#include <ncurses.h>
#include <stdio.h>
#include <time.h>
#include <locale.h>
#include <stdlib.h>
#include <stdarg.h>
#include "main.h"
#include "conf.h"
#include "input.h"
#include "tui.h"
#include "range.h"
#include "sc.h"
#include "cmds.h"
#include "cmds_visual.h"
#include "conf.h"
#include "version.h"
#include "file.h"
#include "format.h"
#include "utils/string.h"
extern struct dictionary * d_colors_param;
extern int cmd_pending;
extern int cmd_multiplier;
extern char insert_edit_submode;
unsigned int curmode;
int rescol = RESCOL; // Columns reserved for row numbers
WINDOW * main_win;
WINDOW * input_win;
// off screen spreadsheet rows and columns
int offscr_sc_rows = 0, offscr_sc_cols = 0;
int center_hidden_cols = 0;
int center_hidden_rows = 0;
SCREEN * sstderr;
SCREEN * sstdout;
srange * ranges;
void ui_start_screen() {
sstderr = newterm(NULL, stderr, NULL);
noecho();
sstdout = newterm(NULL, stdout, stdin);
set_term(sstdout);
main_win = newwin(LINES - RESROW, COLS, RESROW, 0);
input_win = newwin(RESROW, COLS, 0, 0); // just 2 rows (RESROW = 2)
#ifdef USECOLORS
if (has_colors()) {
start_color();
if (get_d_colors_param() == NULL) {
start_default_ucolors();
// in case we decide to change colors
// Create a dictionary and save equivalences between macros and
// values defined in '.sc' files
set_colors_param_dict();
}
wbkgd(main_win, COLOR_PAIR((ucolors[DEFAULT].fg+1) * 9 + ucolors[DEFAULT].bg + 2));
wbkg