static void update_title_win(struct view *view) { size_t len; if (view == display[current_view]) wbkgdset(view->title, get_line_attr(LINE_TITLE_FOCUS)); #ifdef yaomoon fprintf(moon_log,"get linue red attr =%d\n",get_line_attr(LINE_TITLE_FOCUS)); #endif werase(view->title); wmove(view->title, 0, 0); wprintw(view->title, "[RPathN]"); wmove(view->title, 0, 9); waddstr(view->title, view->file); len = strlen(view->file); wmove(view->title, 0, len + 13); if (view->lines) { wprintw(view->title, "line %d of %d (%d%%)", view->lineno + 1, view->lines, (view->lineno + 1) * 100 / view->lines); } wclrtoeol(view->title); wrefresh(view->title); }
static inline void set_view_attr(struct view *view, enum line_type type) { if (!view->curline->selected && view->curtype != type) { (void) wattrset(view->win, get_line_attr(type)); wchgat(view->win, -1, 0, get_line_color(type), NULL); view->curtype = type; } }
static void redraw_display_separator(bool clear) { if (displayed_views() > 1 && vertical_split_is_enabled()) { chtype separator = opt_line_graphics ? ACS_VLINE : '|'; if (clear) wclear(display_sep); wbkgd(display_sep, separator + get_line_attr(NULL, LINE_TITLE_BLUR)); wnoutrefresh(display_sep); } }
static void redraw_display_separator(bool clear) { if (display_sep) { chtype separator = opt_line_graphics ? ACS_VLINE : '|'; if (clear) wclear(display_sep); wbkgd(display_sep, separator + get_line_attr(NULL, LINE_TITLE_BLUR)); wnoutrefresh(display_sep); } }
static void init(void) { int x, y; #ifdef yaomoon moon_log = fopen("moon_log","w+"); #endif /* Initialize the curses library */ if (isatty(STDIN_FILENO)) { cursed = !!initscr(); } else { /* Leave stdin and stdout alone when acting as a pager. */ FILE *io = fopen("/dev/tty", "r+"); cursed = !!newterm(NULL, io, io); } if (!cursed) die("Failed to initialize curses"); nonl(); /* tell curses not to do NL->CR/NL on output */ cbreak(); /* take input chars one at a time, no wait for \n */ noecho(); /* don't echo input */ leaveok(stdscr, TRUE); if (has_colors()) { init_colors(); } getmaxyx(stdscr, y, x); #ifdef yaomoon fprintf(moon_log,"getmaxyx y=%d\n",y); fprintf(moon_log,"getmaxyx x=%d\n",x); #endif status_win = newwin(1, 0, y - 10, 0); if (!status_win) die("failed to create status window"); keypad(status_win, TRUE); wbkgdset(status_win, get_line_attr(LINE_STATUS)); }
static void update_title_win(struct view *view) { if (view == display[current_view]) wbkgdset(view->title, get_line_attr(LINE_TITLE_FOCUS)); werase(view->title); wmove(view->title, 0, 0); if (view->lines) { wprintw(view->title, "line %d of %d (%d%%)", view->lineno + 1, view->lines, (view->lineno + 1) * 100 / view->lines); } wclrtoeol(view->title); wrefresh(view->title); }
void init_display(void) { const char *term; int x, y; die_callback = done_display; /* XXX: Restore tty modes and let the OS cleanup the rest! */ if (atexit(done_display)) die("Failed to register done_display"); /* Initialize the curses library */ if (isatty(STDIN_FILENO)) { cursed = !!initscr(); opt_tty = stdin; } else { /* Leave stdin and stdout alone when acting as a pager. */ opt_tty = fopen("/dev/tty", "r+"); if (!opt_tty) die("Failed to open /dev/tty"); cursed = !!newterm(NULL, opt_tty, opt_tty); } if (!cursed) die("Failed to initialize curses"); nonl(); /* Disable conversion and detect newlines from input. */ cbreak(); /* Take input chars one at a time, no wait for \n */ noecho(); /* Don't echo input */ leaveok(stdscr, FALSE); if (has_colors()) init_colors(); getmaxyx(stdscr, y, x); status_win = newwin(1, x, y - 1, 0); if (!status_win) die("Failed to create status window"); /* Enable keyboard mapping */ keypad(status_win, TRUE); wbkgdset(status_win, get_line_attr(NULL, LINE_STATUS)); enable_mouse(opt_mouse); #if defined(NCURSES_VERSION_PATCH) && (NCURSES_VERSION_PATCH >= 20080119) set_tabsize(opt_tab_size); #else TABSIZE = opt_tab_size; #endif term = getenv("XTERM_VERSION") ? NULL : getenv("COLORTERM"); if (term && !strcmp(term, "gnome-terminal")) { /* In the gnome-terminal-emulator, the message from * scrolling up one line when impossible followed by * scrolling down one line causes corruption of the * status line. This is fixed by calling wclear. */ use_scroll_status_wclear = TRUE; use_scroll_redrawwin = FALSE; } else if (term && !strcmp(term, "xrvt-xpm")) { /* No problems with full optimizations in xrvt-(unicode) * and aterm. */ use_scroll_status_wclear = use_scroll_redrawwin = FALSE; } else { /* When scrolling in (u)xterm the last line in the * scrolling direction will update slowly. */ use_scroll_redrawwin = TRUE; use_scroll_status_wclear = FALSE; } }
/** * This function is used to draw the ls output, * we store all the output of the ls into a global * struct lsview. so we render each item one by one * and support the scroll. * */ void Draw_LS_OutPut() { int totallines = lsview->fileno; int i,highlight,j=0; int start, end; enum line_type type; start = 0; highlight = g_current + g_change; if(highlight <= 0) { mvwaddstr(status_win,0,0,"At the top"); highlight = 0; }else if(highlight <= LINES - 2){ if(highlight == totallines) {/*mean at the end */ mvwaddstr(status_win,0,0,"At the end"); highlight = totallines - 1; } }else { start = highlight - LINES + 2; /*hide one line*/ //end = highlight+1; /*current line is hightghit - 1*/ if(highlight == totallines ){ /*really at the end of the array*/ mvwaddstr(status_win,0,0,"Hit the bottom"); highlight = totallines - 1; start=highlight - LINES + 1; } } if(totallines <= LINES-1) end = totallines; /*not overlap the screen*/ else if(totallines >= LINES) end = start + LINES; werase(stdscr); for(i = start; i < end; i++) { if(i == highlight) { snprintf(vim_cmd,sizeof(vim_cmd), VIM_CMD,lsview->fileinfo[i].name); type = LINE_CURSOR; g_current = i; wattrset(stdscr, get_line_attr(type)); wchgat(stdscr,-1,0,type,NULL); }else{ type = LINE_FILE_LINCON; wchgat(stdscr,-1,0,type,NULL); wattrset(stdscr,get_line_attr(LINE_FILE_NAME)); } /*set filename, size and type*/ if(type != LINE_CURSOR){ wattrset(stdscr,get_line_attr(LINE_FILE_NAME)); mvwaddstr(stdscr,j,0,lsview->fileinfo[i].name); }else{ mvwaddstr(stdscr,j,0,lsview->fileinfo[i].name); } //wmove(stdscr,i,40); if(type != LINE_CURSOR){ wattrset(stdscr,get_line_attr(LINE_FILE_LINUM)); } mvwaddstr(stdscr,j,40,lsview->fileinfo[i].size); //wmove(stdscr,i,60); if(type != LINE_CURSOR){ wattrset(stdscr, get_line_attr(LINE_DELIMITER)); } mvwaddstr(stdscr,j,60,lsview->fileinfo[i].type); mvwaddch(stdscr,j,COLS-1,'\n'); j++; /*j control the screen loop*/ } g_change = 0; /*clear the offset*/ }
void Draw_Find_OutPut(void) { int totallines = fdview->lineidx; int i,highlight, j = 0; int start =0,end = 0; enum line_type type; start = 0; highlight = g_current + g_change; if(highlight < 0){ mvwaddstr(status_win,0,0,"At the top"); highlight = 0; }else if(highlight < LINES -2){ if(highlight == totallines) { mvwaddstr(status_win,0,0,"At the end"); highlight = totallines - 1; } }else{ start = highlight - LINES + 2; if(highlight == totallines){ mvwaddstr(status_win,0,0,"Hit the bottom"); highlight = totallines - 1; start = highlight - LINES + 1; } } if(totallines < LINES - 1) end = totallines; else if(totallines >= LINES) end = start + LINES; werase(stdscr); for(i = start; i < end; i++){ if(i == highlight){ snprintf(vim_cmd,sizeof(vim_cmd),VIM_CMD_FIND,fdview->findinfo[i].path,fdview->findinfo[i].name); type = LINE_CURSOR; g_current = i; wattrset(stdscr,get_line_attr(type)); wchgat(stdscr,-1,0,type,NULL); }else{ type = LINE_FILE_LINCON; wchgat(stdscr,-1,0,type,NULL); wattrset(stdscr,get_line_attr(LINE_FILE_NAME)); } if(type != LINE_CURSOR){ wattrset(stdscr,get_line_attr(LINE_FILE_NAME)); mvwaddstr(stdscr,j,0,fdview->findinfo[i].path); }else{ mvwaddstr(stdscr,j,0,fdview->findinfo[i].path); } if(type != LINE_CURSOR){ wattrset(stdscr,get_line_attr(LINE_FILE_LINUM)); } right_trim(fdview->findinfo[i].name); mvwaddstr(stdscr,j,35,fdview->findinfo[i].name); if(type != LINE_CURSOR){ wattrset(stdscr,get_line_attr(LINE_DELIMITER)); } mvwaddstr(stdscr,j,60,fdview->findinfo[i].type); mvwaddch(stdscr,j,COLS-1,'\n'); j++; } g_change = 0; }
static bool default_render(struct view *view, unsigned int lineno) { struct fileinfo *fileinfo; enum line_type type; int col = 0; size_t numberlen; size_t namelen; char *fname, *fnumber; if (view->offset + lineno >= view->lines) return false; fileinfo = view->line[view->offset + lineno]; if (!*fileinfo->name) return false; wmove(view->win, lineno, col); if (view->offset + lineno == view->lineno) { fnumber = fileinfo->number; fname = fileinfo->name; snprintf(vim_cmd, sizeof(vim_cmd), VIM_CMD, fnumber, fname); type = LINE_CURSOR; wattrset(view->win, get_line_attr(type)); wchgat(view->win, -1, 0, type, NULL); } else { type = LINE_FILE_LINCON; wchgat(view->win, -1, 0, type, NULL); wattrset(view->win, get_line_attr(LINE_FILE_NAME)); } waddstr(view->win, fileinfo->name); namelen = strlen(fileinfo->name); col += 20; wmove(view->win, lineno, col); if (type != LINE_CURSOR) wattrset(view->win, get_line_attr(LINE_FILE_LINUM)); waddstr(view->win, fileinfo->number); numberlen = strlen(fileinfo->number); col += 7; if (type != LINE_CURSOR) wattrset(view->win, A_NORMAL); wmove(view->win, lineno, col + 2); col += 2; if (type != LINE_CURSOR) wattrset(view->win, get_line_attr(type)); int contentlen = strlength(fileinfo->content); if (col + contentlen > view->width) contentlen = view->width - col - 20; if (contentlen > 0) waddnstr(view->win, fileinfo->content, contentlen); else waddnstr(view->win, fileinfo->content, 4); return TRUE; }
static bool default_render(struct view *view, unsigned int lineno) { struct fileinfo *fileinfo; enum line_type type; int col = 0; size_t namelen; char *fname, *fnumber; int opt_file_name = 25; char text[SIZEOF_STR]; if (view->offset + lineno >= view->lines) return false; fileinfo = view->line[view->offset + lineno]; if (!*fileinfo->name) return false; fnumber = fileinfo->number; fname = blankspace(fileinfo->name); wmove(view->win, lineno, col); if (view->offset + lineno == view->lineno) { snprintf(vim_cmd, sizeof(vim_cmd), VIM_CMD, fnumber, fname); type = LINE_CURSOR; wattrset(view->win, get_line_attr(type)); wchgat(view->win, -1, 0, type, NULL); string_copy(view->file, fileinfo->name); } else { type = LINE_FILE_LINCON; wchgat(view->win, -1, 0, type, NULL); wattrset(view->win, get_line_attr(LINE_FILE_NAME)); } namelen = strlen(fileinfo->name); if (namelen > opt_file_name){ int n = namelen-opt_file_name; if (type != LINE_CURSOR) wattrset(view->win, get_line_attr(LINE_DELIMITER)); waddch(view->win, '~'); if (type != LINE_CURSOR) wattrset(view->win, get_line_attr(LINE_FILE_NAME)); waddnstr(view->win, fileinfo->name + n, opt_file_name); } else waddstr(view->win, fileinfo->name); col += opt_file_name + 2; wmove(view->win, lineno, col); if (type != LINE_CURSOR) wattrset(view->win, get_line_attr(LINE_FILE_LINUM)); waddstr(view->win, fileinfo->number); col += 9; if (type != LINE_CURSOR) wattrset(view->win, A_NORMAL); wmove(view->win, lineno, col); if (type != LINE_CURSOR) wattrset(view->win, get_line_attr(type)); int contentlen = strlength(fileinfo->content); string_expand(text, sizeof(text), fileinfo->content, opt_tab_size); if (col + contentlen > view->width){ contentlen = view->width - col; if (contentlen < 0) return TRUE; else { waddnstr(view->win, text, contentlen-1); if (type != LINE_CURSOR) wattrset(view->win, get_line_attr(LINE_DELIMITER)); waddch(view->win, '~'); } } else { waddstr(view->win, fileinfo->content); } return TRUE; }
void init_display(void) { bool no_display = !!getenv("TIG_NO_DISPLAY"); const char *term; int x, y; die_callback = done_display; /* XXX: Restore tty modes and let the OS cleanup the rest! */ if (atexit(done_display)) die("Failed to register done_display"); /* Initialize the curses library */ { /* Leave stdin and stdout alone when acting as a pager. */ FILE *out_tty; opt_tty = fopen("/dev/tty", "r+"); out_tty = no_display ? fopen("/dev/null", "w+") : opt_tty; if (!opt_tty || !out_tty) die("Failed to open /dev/tty"); cursed = !!newterm(NULL, out_tty, opt_tty); } if (!cursed) die("Failed to initialize curses"); set_terminal_modes(); init_colors(); getmaxyx(stdscr, y, x); status_win = newwin(1, x, y - 1, 0); if (!status_win) die("Failed to create status window"); /* Enable keyboard mapping */ keypad(status_win, true); wbkgdset(status_win, get_line_attr(NULL, LINE_STATUS)); enable_mouse(opt_mouse); #if defined(NCURSES_VERSION_PATCH) && (NCURSES_VERSION_PATCH >= 20080119) set_tabsize(opt_tab_size); #else TABSIZE = opt_tab_size; #endif term = getenv("XTERM_VERSION") ? NULL : (getenv("TERM_PROGRAM") ? getenv("TERM_PROGRAM") : getenv("COLORTERM")); if (term && !strcmp(term, "gnome-terminal")) { /* In the gnome-terminal-emulator, the warning message * shown when scrolling up one line while the cursor is * on the first line followed by scrolling down one line * corrupts the status line. This is fixed by calling * wclear. */ use_scroll_status_wclear = true; use_scroll_redrawwin = false; } else if (term && (!strcmp(term, "xrvt-xpm") || !strcmp(term, "Apple_Terminal") || !strcmp(term, "iTerm.app"))) { /* No problems with full optimizations in * xrvt-(unicode) * aterm * Terminal.app * iTerm2 */ use_scroll_status_wclear = use_scroll_redrawwin = false; } else { /* When scrolling in (u)xterm the last line in the * scrolling direction will update slowly. This is * the conservative default. */ use_scroll_redrawwin = true; use_scroll_status_wclear = false; } }