Moving curses code to a separate module to make main cleaner.

This commit is contained in:
Martin Dvorak 2014-01-25 13:38:20 +01:00
parent 9b1de77d8c
commit f14091ed44
3 changed files with 13 additions and 24 deletions

View file

@ -17,12 +17,13 @@ AC_CONFIG_SRCDIR([src/hstr.c])
AC_PROG_CC AC_PROG_CC
# Checks for libraries. # Checks for libraries.
AC_CHECK_LIB(ncurses, initscr) AC_CHECK_LIB(ncurses, initscr, [], [AC_MSG_ERROR([Could not find Curses library])])
AC_CHECK_LIB(m,cos) AC_CHECK_LIB(m, cos, [], [AC_MSG_ERROR([Could not find Math library])])
AC_CHECK_LIB(readline, using_history) AC_CHECK_LIB(readline, using_history, [], [AC_MSG_ERROR([Could not find Readline library])])
# Checks for header files. # Checks for header files.
AC_CHECK_HEADER(assert.h) AC_CHECK_HEADER(assert.h)
AC_CHECK_HEADER(ctype.h)
AC_CHECK_HEADER(curses.h) AC_CHECK_HEADER(curses.h)
AC_CHECK_HEADER(fcntl.h) AC_CHECK_HEADER(fcntl.h)
AC_CHECK_HEADER(math.h) AC_CHECK_HEADER(math.h)

View file

@ -7,7 +7,8 @@ bin_PROGRAMS = hh
hh_SOURCES = \ hh_SOURCES = \
hashset.c include/hashset.h \ hashset.c include/hashset.h \
radixsort.c include/radixsort.h \ hstr_curses.c include/hstr_curses.h \
hstr_history.c include/hstr_history.h \ hstr_history.c include/hstr_history.h \
hstr_utils.c include/hstr_utils.h \ hstr_utils.c include/hstr_utils.h \
radixsort.c include/radixsort.h \
hstr.c hstr.c

View file

@ -21,10 +21,10 @@
#include <readline/chardefs.h> #include <readline/chardefs.h>
#include "include/hashset.h" #include "include/hashset.h"
#include "include/hstr_utils.h" #include "include/hstr_curses.h"
#include "include/hstr_history.h" #include "include/hstr_history.h"
#include "include/hstr_utils.h"
#define FILE_BASHRC ".bashrc"
#define SELECTION_CURSOR_IN_PROMPT -1 #define SELECTION_CURSOR_IN_PROMPT -1
#define SELECTION_PREFIX_MAX_LNG 500 #define SELECTION_PREFIX_MAX_LNG 500
#define CMDLINE_LNG 250 #define CMDLINE_LNG 250
@ -53,10 +53,6 @@
#define K_BACKSPACE 127 #define K_BACKSPACE 127
#define K_ENTER 10 #define K_ENTER 10
#define color_attr_on(C) if(terminalHasColors) { attron(C); }
#define color_attr_off(C) if(terminalHasColors) { attroff(C); }
#define color_init_pair(X, Y, Z) if(terminalHasColors) { init_pair(X, Y, Z); }
#ifdef DEBUG_KEYS #ifdef DEBUG_KEYS
#define LOGKEYS(Y,KEY) mvprintw(Y, 0, "Key: '%3d' / Char: '%c'", KEY, KEY); clrtoeol() #define LOGKEYS(Y,KEY) mvprintw(Y, 0, "Key: '%3d' / Char: '%c'", KEY, KEY); clrtoeol()
#else #else
@ -84,7 +80,6 @@ static const char *LABEL_HELP=
static char **selection=NULL; static char **selection=NULL;
static unsigned selectionSize=0; static unsigned selectionSize=0;
static bool terminalHasColors=FALSE;
static bool caseSensitive=FALSE; static bool caseSensitive=FALSE;
static bool defaultOrder=FALSE; static bool defaultOrder=FALSE;
static char screenLine[1000]; static char screenLine[1000];
@ -117,7 +112,6 @@ void print_cmd_deleted_label(char *cmd, int occurences)
refresh(); refresh();
} }
// make this status row
void print_history_label(HistoryItems *history) void print_history_label(HistoryItems *history)
{ {
sprintf(screenLine, "- HISTORY - case:%s (C-t) - order:%s (C-/) - %d/%d ", sprintf(screenLine, "- HISTORY - case:%s (C-t) - order:%s (C-/) - %d/%d ",
@ -232,13 +226,12 @@ void print_selection_row(char *text, int y, int width, char *prefix) {
} }
color_attr_off(A_BOLD); color_attr_off(A_BOLD);
} }
} }
void print_highlighted_selection_row(char *text, int y, int width) { void print_highlighted_selection_row(char *text, int y, int width) {
color_attr_on(A_REVERSE); color_attr_on(A_REVERSE);
color_attr_on(A_BOLD); color_attr_on(A_BOLD);
snprintf(screenLine, getmaxx(stdscr), "%s%s", (terminalHasColors?" ":">"), text); snprintf(screenLine, getmaxx(stdscr), "%s%s", (terminal_has_colors()?" ":">"), text);
mvprintw(y, 0, "%s", screenLine); mvprintw(y, 0, "%s", screenLine);
color_attr_off(A_BOLD); color_attr_off(A_BOLD);
color_attr_off(A_REVERSE); color_attr_off(A_REVERSE);
@ -289,13 +282,6 @@ void highlight_selection(int selectionCursorPosition, int previousSelectionCurso
} }
} }
void color_start()
{
terminalHasColors=has_colors();
if(terminalHasColors) {
start_color();
}
}
void selection_remove(char *cmd, HistoryItems *history) void selection_remove(char *cmd, HistoryItems *history)
{ {
@ -548,6 +534,7 @@ int main(int argc, char *argv[])
if(argc>0) { if(argc>0) {
if(argc==2 && strstr(argv[1], "--show-configuration")) { if(argc==2 && strstr(argv[1], "--show-configuration")) {
install_show(); install_show();
// TODO --help (tr --help)
} else { } else {
assemble_cmdline(argc, argv); assemble_cmdline(argc, argv);
hstr(); hstr();