From 61a4ae63d3c9444af59755c58b56bc59bd7ef186 Mon Sep 17 00:00:00 2001 From: andmarti1424 Date: Fri, 15 Dec 2017 12:24:29 -0300 Subject: [PATCH] renamed winch to sig_winch. current fg and bg colors are kept if they are not specified in :cellcolor. added comments in tui.c --- src/cmds_command.c | 2 +- src/cmds_normal.c | 4 ++-- src/color.c | 20 ++++++++++---------- src/main.c | 6 +++--- src/main.h | 2 +- src/tui.c | 37 +++++++++++++++++++------------------ src/tui.h | 1 + 7 files changed, 37 insertions(+), 35 deletions(-) diff --git a/src/cmds_command.c b/src/cmds_command.c index 43beba64..5bbc33c9 100644 --- a/src/cmds_command.c +++ b/src/cmds_command.c @@ -375,7 +375,7 @@ void do_commandmode(struct block * sb) { } else if (find_val(sb, OKEY_ENTER)) { if ( ! wcscmp(inputline, L"refresh")) { - winchg(); + sig_winchg(); } else if ( ! wcscmp(inputline, L"help") || ! wcscmp(inputline, L"h") ) { help(); diff --git a/src/cmds_normal.c b/src/cmds_normal.c index f670a09e..6f661188 100644 --- a/src/cmds_normal.c +++ b/src/cmds_normal.c @@ -54,7 +54,7 @@ #include "history.h" #include "hide_show.h" #include "shift.h" -#include "main.h" // for winchg +#include "main.h" // for sig_winchg #include "interp.h" #include "freeze.h" #include "utils/extra.h" @@ -1059,7 +1059,7 @@ void do_normalmode(struct block * buf) { } case ctl('l'): - winchg(); + sig_winchg(); break; case L'@': diff --git a/src/color.c b/src/color.c index 670ce106..eed3543a 100644 --- a/src/color.c +++ b/src/color.c @@ -70,7 +70,7 @@ struct dictionary * get_d_colors_param() { * @brief Generate DEFAULT 'initcolor' colors * * Generate DEFAULT 'initcolor' colors. - * + * * Example usage: * @code * start_default_ucolors(); @@ -307,13 +307,13 @@ void chg_color(char * str) { * supports undo / redo */ /** - * @brief TODO + * @brief * * Changes coloring and format for cell or range of cells. * * Format options: bold, underline. * - * This funciton supports undo/redo. + * This function supports undo/redo. * * Example usage: * @code @@ -368,8 +368,8 @@ void color_cell(int r, int c, int rf, int cf, char * str) { n = lookat(i, j); if (n->ucolor == NULL) { n->ucolor = (struct ucolor *) malloc(sizeof(struct ucolor)); - n->ucolor->fg = WHITE; - n->ucolor->bg = BLACK; + n->ucolor->fg = NONE_COLOR; + n->ucolor->bg = NONE_COLOR; n->ucolor->bold = 0; n->ucolor->dim = 0; n->ucolor->reverse = 0; @@ -406,9 +406,9 @@ void color_cell(int r, int c, int rf, int cf, char * str) { } /** - * @brief TODO + * @brief * - * TODO Write longer function description. + * Cleans format from a range of cells * * Example usage: * @code @@ -467,7 +467,7 @@ void unformat(int r, int c, int rf, int cf) { } /** - * @brief TODO + * @brief * * This function receives two ucolor variables and returns 1 if both have the * same values, returns 0 otherwise. @@ -508,7 +508,7 @@ int same_ucolor(struct ucolor * u, struct ucolor * v) { int redefine_color(char * color, int r, int g, int b) { #if defined(NCURSES) && defined(USECOLORS) - extern void winchg(); + extern void sig_winchg(); if ( ! atoi(get_conf_value("nocurses")) && has_colors() && can_change_color() @@ -519,7 +519,7 @@ int redefine_color(char * color, int r, int g, int b) { return -1; } if (init_color(atoi(s), r, g, b) == 0) { - winchg(); + sig_winchg(); if (! loading) sc_info("Color %s redefined to %d %d %d.", color, r, g, b); return 0; } diff --git a/src/main.c b/src/main.c index 2a377aa6..51accbf7 100644 --- a/src/main.c +++ b/src/main.c @@ -589,7 +589,7 @@ void signals() { void sig_abrt(); void sig_term(); void nopipe(); - void winchg(); + void sig_winchg(); void sig_tstp(); void sig_cont(); @@ -598,7 +598,7 @@ void signals() { signal(SIGTERM, sig_term); // kill signal(SIGPIPE, nopipe); //(void) signal(SIGALRM, time_out); - signal(SIGWINCH, winchg); + signal(SIGWINCH, sig_winchg); //(void) signal(SIGBUS, doquit); //(void) signal(SIGFPE, doquit); signal(SIGTSTP, sig_tstp); @@ -644,7 +644,7 @@ void sig_tstp() { void sig_cont() { signal(SIGTSTP, sig_tstp); /* set handler back to this */ - winchg(); + sig_winchg(); reset_prog_mode(); refresh(); ui_update(TRUE); diff --git a/src/main.h b/src/main.h index 0bb17ce7..9da1afea 100644 --- a/src/main.h +++ b/src/main.h @@ -58,7 +58,7 @@ void show_version_and_quit(); void sig_int(); // SIGWINCH signal - resize of terminal -void winchg(); +void sig_winchg(); extern FILE * fdoutput; // output file descriptor (stdout or file) extern unsigned int curmode; diff --git a/src/tui.c b/src/tui.c index 35f6c259..737eb40b 100644 --- a/src/tui.c +++ b/src/tui.c @@ -105,7 +105,7 @@ SCREEN * sstdout; srange * ranges; /** - * \brief Called to start UI + * \brief Called to start UI * * \return none */ @@ -328,7 +328,7 @@ void ui_do_welcome() { * \details This function is used to refresh the screen content. If * the header flag is set, the first column of the screen gets * refreshed. - * + * * \param[in] header * * \return none @@ -429,7 +429,7 @@ void ui_handle_cursor() { * \details Internal function to print a string with alignment. * * JUSTIF: 0 left shift - * + * * JUSTIF: 1 right shift * * \param[in] win @@ -1143,15 +1143,11 @@ void ui_show_text(char * val) { /** - * \brief TODO Document winchg() - * + * \brief + * UI function thats called after SIGWINCH signal. * \return none */ - -// TODO Consider renaming this to sig_winchg for consistancy with -// the other signal funcitons. - -void winchg() { +void sig_winchg() { endwin(); refresh(); clear(); @@ -1306,6 +1302,7 @@ char * ui_query(char * initial_msg) { */ void ui_set_ucolor(WINDOW * w, struct ucolor * uc) { + short color; long attr = A_NORMAL; if (uc->bold) attr |= A_BOLD; if (uc->dim) attr |= A_DIM; @@ -1313,7 +1310,14 @@ void ui_set_ucolor(WINDOW * w, struct ucolor * uc) { if (uc->standout) attr |= A_STANDOUT; if (uc->blink) attr |= A_BLINK; if (uc->underline) attr |= A_UNDERLINE; - wattrset (w, attr | COLOR_PAIR((uc->fg+1)*9 + uc->bg + 2)); + if (uc->bg == NONE_COLOR || uc->fg == NONE_COLOR) { + // get current window color; + attr_t a; + wattr_get(w, &a, &color, NULL); + } else { + color = (uc->fg+1)*9 + uc->bg + 2; + } + wattrset (w, attr | COLOR_PAIR(color)); } /** @@ -1321,7 +1325,6 @@ void ui_set_ucolor(WINDOW * w, struct ucolor * uc) { * * \return none */ - void ui_start_colors() { if (! has_colors()) return; int i, j; @@ -1333,11 +1336,10 @@ void ui_start_colors() { } /** - * \brief TODO Document ui_pause() - * + * \brief + * UI function thats called after SIGTSTP signal. * \return none */ - void ui_pause() { def_prog_mode(); set_term(sstderr); @@ -1346,11 +1348,10 @@ void ui_pause() { } /** - * \brief TODO Document ui_resume - * + * \brief + * UI function thats called after SIGCONT signal. * \return none */ - void ui_resume() { set_term(sstdout); reset_prog_mode(); diff --git a/src/tui.h b/src/tui.h index 6aee44e5..80518900 100644 --- a/src/tui.h +++ b/src/tui.h @@ -49,6 +49,7 @@ #endif #include "color.h" +#define NONE_COLOR -2 #define DEFAULT_COLOR -1 #define BLACK COLOR_BLACK #define RED COLOR_RED