// Copyright (c) 2003 Juraj Kolesár (koli) #include "tt.h" /* get {{{ ********************************************************************/ int tt_str_get(POS point, int n, char *str) { bool End = false; int Pos = 0; int Status; do { tt_str_draw(point, n, Pos, '_', str); Status = tt_str_input(tt_input(), n, &Pos, str); if ( (Status == __TT_ENTER) || (Status == __TT_ESC) || (Status == __TT_TAB) ) End = true; } while (!(End)); tt_str_draw(point, n, 0, ' ', str); return(Status); } /* }}} */ /* input {{{ ******************************************************************/ int tt_str_input(int input, int n, int *pos, char *str) { int length = strlen(str); switch (input) { case __TT_RIGHT: if ((*pos < n-1) && (*pos < length)) (*pos)++; break; case __TT_LEFT: if (*pos > 0) *pos = *pos - 1; break; case __TT_BACKSPACE: if (*pos > 0) { (*pos)--; str_remove_char(*pos, str); } else beep(); break; case __TT_DEL: if (*pos < length) { str_remove_char(*pos, str); } else beep(); break; default: if ((31 < input) && (input < 256)) { //available asci chars if (*pos == length) str[*pos+1] = '\0'; str[*pos] = input; if (*pos < (n-1)) (*pos)++; else beep(); } else return(input); } return(__TT_ERR); } /* }}} */ /* draw {{{ *******************************************************************/ int tt_str_draw(POS point, int n, int pos, int fill, char *str) { int i,by,bx; int length = strlen(str); int win_width; int win_height; char Str[__TT_STR_MAX] = {'\0'}; getmaxyx(point.win, win_height, win_width); if ((win_width - point.y < n) || (win_width - point.y < length)) n = win_width - point.y; if (n < length) strncpy(Str,str,n); else strcpy(Str,str); mvwprintw(GET_POS(point), Str); wmove(GET_POS(point) + length); for (i = length; i < n; i++) waddch(point.win, fill); wmove(GET_POS(point) + pos); wrefresh(point.win); return(0); } /* }}} */