summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authormongo <andmarti@gmail.com>2017-04-05 14:34:17 -0300
committermongo <andmarti@gmail.com>2017-04-05 14:34:17 -0300
commita60fa43aedacc49397ff1f5e93af31e18c20eb65 (patch)
tree81da037606975dd1325438310bd7ea5269d24ba0
parent5b1baaddf351a5d4c24789f109cf5bfa17d62586 (diff)
more cleaning of ui
-rw-r--r--src/cmds_command.c3
-rw-r--r--src/cmds_edit.c5
-rw-r--r--src/cmds_normal.c16
-rw-r--r--src/help.c3
-rw-r--r--src/lua.c122
-rw-r--r--src/tui.c89
-rw-r--r--src/tui.h5
7 files changed, 112 insertions, 131 deletions
diff --git a/src/cmds_command.c b/src/cmds_command.c
index dac99e0..101bcc5 100644
--- a/src/cmds_command.c
+++ b/src/cmds_command.c
@@ -260,8 +260,7 @@ void do_commandmode(struct block * sb) {
break;
}
inputline_pos = wcswidth(inputline, real_inputline_pos);
- wmove(input_win, 0, inputline_pos + 1 + rescol);
- wrefresh(input_win);
+ ui_show_header();
return;
} else if (sb->value == '\t') { // TAB completion
diff --git a/src/cmds_edit.c b/src/cmds_edit.c
index 4acea24..b2ed559 100644
--- a/src/cmds_edit.c
+++ b/src/cmds_edit.c
@@ -233,10 +233,7 @@ void do_editmode(struct block * sb) {
inputline[real_inputline_pos] = c;
++real_inputline_pos;
inputline_pos = wcswidth(inputline, real_inputline_pos);
-
- mvwprintw(input_win, 0, 1 + rescol, "%ls", inputline);
- wmove(input_win, 0, inputline_pos + 1 + rescol);
- wrefresh(input_win);
+ ui_show_header();
}
if (ui_getch_b(&wi) != -1) return;
c = wi;
diff --git a/src/cmds_normal.c b/src/cmds_normal.c
index dd636b5..582f50e 100644
--- a/src/cmds_normal.c
+++ b/src/cmds_normal.c
@@ -389,23 +389,16 @@ void do_normalmode(struct block * buf) {
#ifdef HISTORY_FILE
add(commandline_history, L"");
#endif
- ui_clr_header(0);
- ui_print_mode();
- wrefresh(input_win);
-
handle_cursor();
inputline_pos = 0;
real_inputline_pos = 0;
+ ui_show_header();
break;
// enter visual mode
case L'v':
chg_mode('v');
-
- ui_clr_header(0);
- ui_print_mode();
- wrefresh(input_win);
-
+ ui_show_header();
handle_cursor();
start_visualmode(currow, curcol, currow, curcol);
break;
@@ -422,12 +415,9 @@ void do_normalmode(struct block * buf) {
ori_insert_edit_submode = buf->value;
add(insert_history, L"");
#endif
- ui_clr_header(0);
- ui_print_mode();
- wrefresh(input_win);
-
inputline_pos = 0;
real_inputline_pos = 0;
+ ui_show_header();
break;
// EDITION COMMANDS
diff --git a/src/help.c b/src/help.c
index 3a390df..335ff87 100644
--- a/src/help.c
+++ b/src/help.c
@@ -19,6 +19,9 @@ static int max;
static int look_result = -1;
static char word_looked[50] = "";
+extern WINDOW * main_win;
+extern WINDOW * input_win;
+
// Load the contents of help_doc into memory
int load_help () {
register FILE * f;
diff --git a/src/lua.c b/src/lua.c
index 88b0d65..4781239 100644
--- a/src/lua.c
+++ b/src/lua.c
@@ -14,7 +14,6 @@
#include <lauxlib.h> /* Always include this when calling Lua */
#include <lualib.h> /* Prototype for luaL_openlibs(), */
/* always include this when calling Lua */
-#include <curses.h>
#include <ctype.h>
#include <unistd.h>
#include <stdlib.h>
@@ -29,7 +28,6 @@
#include "conf.h"
extern FILE * fdoutput;
-extern WINDOW * input_win;
#define LC_NUMBER2(n,v) \
static int l_ ## n(lua_State *L) \
@@ -39,40 +37,6 @@ extern WINDOW * input_win;
}
lua_State *L;
-extern SCREEN * sstderr;
-extern SCREEN * sstdout;
-extern WINDOW * input_win;
-extern char stderr_buffer[1024];
-
-void bail(lua_State *L, char * msg){
- /*
- volatile char *error=lua_tostring(L,-1);
- fprintf(stderr,"%s",error);
- */
-
- fprintf(stderr,"FATAL ERROR: %s: %s\n", msg, lua_tostring(L, -1));
-
- move(0, 0);
- clrtobot();
- wrefresh(stdscr);
-
- set_term(sstderr);
- move(0, 0);
- clrtobot();
- clearok(stdscr, TRUE);
- mvprintw(0, 0, "%s", stderr_buffer);
- stderr_buffer[0]='\0';
- fseek(stderr, 0, SEEK_END);
-
- refresh();
- getch();
-
- set_term(sstdout);
- clearok(stdscr, TRUE);
- ui_show_header();
- refresh();
- update(TRUE);
-}
static int l_getnum (lua_State *L) {
int r,c;
@@ -205,75 +169,13 @@ static int l_colrow(lua_State *L) {
return 2;
}
-char * query(char * initial_msg) {
- char * hline = (char *) malloc(sizeof(char) * BUFFERSIZE);
- hline[0]='\0';
-
- // curses is not enabled
- if ( atoi(get_conf_value("nocurses"))) {
- if (strlen(initial_msg)) wprintf(L"%s", initial_msg);
-
- if (fgets(hline, BUFFERSIZE-1, stdin) == NULL)
- hline[0]='\0';
-
- clean_carrier(hline);
- return hline;
- }
-
- // curses is enabled
- int loading_o;
- if (loading) {
- loading_o=loading;
- loading=0;
- update(0);
- loading=loading_o;
- }
- curs_set(1);
-
- // show initial message
- if (strlen(initial_msg)) sc_info(initial_msg);
-
- // ask for input
- wtimeout(input_win, -1);
- notimeout(input_win, TRUE);
- wmove(input_win, 0, rescol);
- wclrtoeol(input_win);
- wrefresh(input_win);
- int d = wgetch(input_win);
-
- while (d != OKEY_ENTER && d != OKEY_ESC) {
- if (d == OKEY_BS || d == OKEY_BS2) {
- del_char(hline, strlen(hline) - 1);
- } else {
- sprintf(hline + strlen(hline), "%c", d);
- }
-
- mvwprintw(input_win, 0, rescol, "%s", hline);
- wclrtoeol(input_win);
- wrefresh(input_win);
- d = wgetch(input_win);
- }
- if (d == OKEY_ESC) hline[0]='\0';
-
- // go back to spreadsheet
- noecho();
- curs_set(0);
- wtimeout(input_win, TIMEOUT_CURSES);
- wmove(input_win, 0,0);
- wclrtoeol(input_win);
- wmove(input_win, 1,0);
- wclrtoeol(input_win);
- wrefresh(input_win);
- return hline;
-}
-
int l_query (lua_State *L) {
char * val;
char * ret;
val = (char *) lua_tostring(L,1);
- ret = query(val);
+ ret = ui_query(val);
//sc_debug("return of query:%s.\n", ret);
if (ret == '\0') {
free(ret);
@@ -341,10 +243,10 @@ char * doLUA( struct enode * se) {
sprintf(buffer,"lua/%s",cmd);
if(plugin_exists(buffer,strlen(buffer),buffer1)) {
if (luaL_loadfile(L, buffer1)) /* Load but don't run the Lua script */
- bail(L, "luaL_loadfile() failed"); /* Error out if file can't be read */
+ ui_bail(L, "luaL_loadfile() failed"); /* Error out if file can't be read */
if (lua_pcall(L, 0, 0, 0)) /* PRIMING RUN. FORGET THIS AND YOU'RE TOAST */
- bail(L, "lua_pcall() failed"); /* Error out if Lua file has an error */
+ ui_bail(L, "lua_pcall() failed"); /* Error out if Lua file has an error */
/* Tell what function to run */
// lua_getglobal(L, "tellme");
@@ -356,17 +258,17 @@ char * doLUA( struct enode * se) {
void doLuaTriger() {
if (luaL_loadfile(L, "trigger.lua")) /* Load but don't run the Lua script */
return;
- //bail(L, "luaL_loadfile() failed"); /* Error out if file can't be read */
+ //ui_bail(L, "luaL_loadfile() failed"); /* Error out if file can't be read */
if (lua_pcall(L, 0, 0, 0)) /* PRIMING RUN. FORGET THIS AND YOU'RE TOAST */
- bail(L, "lua_pcall() failed"); /* Error out if Lua file has an error */
+ ui_bail(L, "lua_pcall() failed"); /* Error out if Lua file has an error */
lua_getglobal(L, "trigger"); /* Tell what function to run */
//sc_debug("In C, calling Lua");
if (lua_pcall(L, 0, 0, 0)) /* Run the function */
- bail(L, "lua_pcall() failed"); /* Error out if Lua file has an error */
+ ui_bail(L, "lua_pcall() failed"); /* Error out if Lua file has an error */
//sc_debug("Back in C again");
return;
}
@@ -374,10 +276,10 @@ void doLuaTriger() {
void doLuaTriger2(int row, int col, int flags) {
if (luaL_loadfile(L, "trigger.lua")) /* Load but don't run the Lua script */
return;
- //bail(L, "luaL_loadfile() failed"); /* Error out if file can't be read */
+ //ui_bail(L, "luaL_loadfile() failed"); /* Error out if file can't be read */
if (lua_pcall(L, 0, 0, 0)) /* PRIMING RUN. FORGET THIS AND YOU'RE TOAST */
- bail(L, "lua_pcall() failed"); /* Error out if Lua file has an error */
+ ui_bail(L, "lua_pcall() failed"); /* Error out if Lua file has an error */
lua_getglobal(L, "trigger_cell"); /* Tell what function to run */
@@ -386,7 +288,7 @@ void doLuaTriger2(int row, int col, int flags) {
lua_pushinteger(L, flags);
//sc_debug("In C, calling Lua");
if (lua_pcall(L, 3, 0, 0)) /* Run the function */
- bail(L, "lua_pcall() failed"); /* Error out if Lua file has an error */
+ ui_bail(L, "lua_pcall() failed"); /* Error out if Lua file has an error */
//sc_debug("Back in C again");
return;
}
@@ -408,11 +310,11 @@ void doLuaTrigger_cell(struct ent *p, int flags) {
if(plugin_exists(buffer,strlen(buffer),buffer1)) {
if (luaL_loadfile(L, buffer1)) /* Load but don't run the Lua script */
return;
- //bail(L, "luaL_loadfile() failed"); /* Error out if file can't be read */
+ //ui_bail(L, "luaL_loadfile() failed"); /* Error out if file can't be read */
if (lua_pcall(L, 0, 0, 0)) /* PRIMING RUN. FORGET THIS AND YOU'RE TOAST */
- bail(L, "lua_pcall() failed"); /* Error out if Lua file has an error */
+ ui_bail(L, "lua_pcall() failed"); /* Error out if Lua file has an error */
lua_getglobal(L, trigger->function); /* Tell what function to run */
@@ -421,7 +323,7 @@ void doLuaTrigger_cell(struct ent *p, int flags) {
lua_pushinteger(L, flags);
//sc_debug("In C, calling Lua");
if (lua_pcall(L, 3, 0, 0)) /* Run the function */
- bail(L, "lua_pcall() failed"); /* Error out if Lua file has an error */
+ ui_bail(L, "lua_pcall() failed"); /* Error out if Lua file has an error */
//sc_debug("Back in C again");
}
return;
diff --git a/src/tui.c b/src/tui.c
index fb51efd..02c0c5e 100644
--- a/src/tui.c
+++ b/src/tui.c
@@ -14,6 +14,7 @@
* ui_yyerror
* ui_show_text
+ * ui_bail
* ui_sc_msg
* ui_winchg
* ui_print_mult_pend
@@ -1171,3 +1172,91 @@ void winchg() {
//signal(SIGWINCH, winchg);
return;
}
+
+#ifdef XLUA
+/* function to print errors of lua scripts */
+void ui_bail(lua_State *L, char * msg) {
+ extern char stderr_buffer[1024];
+ fprintf(stderr,"FATAL ERROR: %s: %s\n", msg, lua_tostring(L, -1));
+ move(0, 0);
+ clrtobot();
+ wrefresh(stdscr);
+ set_term(sstderr);
+ move(0, 0);
+ clrtobot();
+ clearok(stdscr, TRUE);
+ mvprintw(0, 0, "%s", stderr_buffer);
+ stderr_buffer[0]='\0';
+ fseek(stderr, 0, SEEK_END);
+ refresh();
+ getch();
+ set_term(sstdout);
+ clearok(stdscr, TRUE);
+ ui_show_header();
+ refresh();
+ update(TRUE);
+}
+#endif
+
+/* function to read text from stdin */
+char * ui_query(char * initial_msg) {
+ char * hline = (char *) malloc(sizeof(char) * BUFFERSIZE);
+ hline[0]='\0';
+
+ // curses is not enabled
+ if ( atoi(get_conf_value("nocurses"))) {
+ if (strlen(initial_msg)) wprintf(L"%s", initial_msg);
+
+ if (fgets(hline, BUFFERSIZE-1, stdin) == NULL)
+ hline[0]='\0';
+
+ clean_carrier(hline);
+ return hline;
+ }
+
+ // curses is enabled
+ int loading_o;
+ if (loading) {
+ loading_o=loading;
+ loading=0;
+ update(0);
+ loading=loading_o;
+ }
+ curs_set(1);
+
+ // show initial message
+ if (strlen(initial_msg)) sc_info(initial_msg);
+
+ // ask for input
+ wtimeout(input_win, -1);
+ notimeout(input_win, TRUE);
+ wmove(input_win, 0, rescol);
+ wclrtoeol(input_win);
+ wrefresh(input_win);
+ int d = wgetch(input_win);
+
+ while (d != OKEY_ENTER && d != OKEY_ESC) {
+ if (d == OKEY_BS || d == OKEY_BS2) {
+ del_char(hline, strlen(hline) - 1);
+ } else {
+ sprintf(hline + strlen(hline), "%c", d);
+ }
+
+ mvwprintw(input_win, 0, rescol, "%s", hline);
+ wclrtoeol(input_win);
+ wrefresh(input_win);
+ d = wgetch(input_win);
+ }
+ if (d == OKEY_ESC) hline[0]='\0';
+
+ // go back to spreadsheet
+ noecho();
+ curs_set(0);
+ wtimeout(input_win, TIMEOUT_CURSES);
+ wmove(input_win, 0,0);
+ wclrtoeol(input_win);
+ wmove(input_win, 1,0);
+ wclrtoeol(input_win);
+ wrefresh(input_win);
+ return hline;
+}
diff --git a/src/tui.h b/src/tui.h
index 05977eb..d733900 100644
--- a/src/tui.h
+++ b/src/tui.h
@@ -1,5 +1,6 @@
#include <ncurses.h>
#include <wchar.h>
+#include <lua.h>
#define N_INIT_PAIRS 19
#define DEFAULT_COLOR -1
@@ -12,8 +13,6 @@
#define CYAN COLOR_CYAN
#define WHITE COLOR_WHITE
-extern WINDOW * main_win;
-extern WINDOW * input_win;
extern int offscr_sc_rows, offscr_sc_cols;
extern unsigned int curmode;
extern struct srange * ranges;
@@ -46,3 +45,5 @@ void write_j(WINDOW * win, const char * word, const unsigned int row, const unsi
void yyerror(char *err); // error routine for yacc (gram.y)
void show_text(char * val);
+void ui_bail(lua_State *L, char * msg);
+char * ui_query(char * initial_msg);