⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 curses.c

📁 linux下的网络下载工具prozilla的源码
💻 C
📖 第 1 页 / 共 2 页
字号:
	}    }    /* Display whats in the message buffer */    /* Lock the mutex */    pthread_mutex_lock(&curses_msg_mutex);    move(19, 0);    clrtoeol();    move(20, 0);    clrtoeol();    move(21, 0);    clrtoeol();    attrset(COLOR_PAIR(MSG_PAIR) | A_BOLD);    mvprintw(19, 0, "%s", message_buffer);    /* Unlock the mutex */    pthread_mutex_unlock(&curses_msg_mutex);}interface_retcurses_do_interface(connection_data * connections,		    int num_connections, ftp_mirror * mirrors,		    int num_servers){    int cur_server;    extern pthread_t *threads;    while (1)    {	handle_threads();	/*	 * display the URL	 */	napms(100);	curses_draw_display(connections, num_connections, mirrors,			    num_servers);	refresh();	switch (getch())	{	case CTRL('R'):	    /*	     * if connections are ==1 then resume isn't suppported 	     */	    if (connections[0].u.resume_support)	    {		curses_exit_resume(connections, num_connections);	    }	    break;	case CTRL('X'):	    curses_exit_no_resume(connections, num_connections);	    break;	case CTRL('N'):	    if (rt.ftp_search == TRUE && num_servers > 1)	    {		cur_server =		    get_mirror_list_pos(connections[0].u.url, mirrors,					num_servers);		debug_prz("cur_server %d", cur_server);		if ((cur_server >= 0 && cur_server < num_servers - 1)		    && !(cur_server == num_servers - 1))		{		    terminate_threads(threads, num_connections);		    return USER_NEXT_SERV;		}	    }	    break;	case CTRL('P'):	    if (rt.ftp_search == TRUE && num_servers > 1)	    {		cur_server =		    get_mirror_list_pos(connections[0].u.url, mirrors,					num_servers);		debug_prz("cur_server %d", cur_server);		if ((cur_server > 0 && cur_server < num_servers - 1)		    && !(cur_server == 0))		{		    terminate_threads(threads, num_connections);		    return USER_PREV_SERV;		}	    }	    break;	case CTRL('L'):	/*				   * Repaint the screen 				 */	    /*	     * force a complete clear of the screen 	     */	    clear();	    refresh();	    /*	     * now redraw it 	     */	    curses_draw_display(connections, num_connections, mirrors,				num_servers);	    refresh();	    break;	case KEY_DOWN:	    if (num_connections <= 4)	/* no need to scroll */		break;	    if (top_con < num_connections - 4)	/* more than 4 connections */		top_con++;	    break;	case KEY_UP:	    if (top_con > 0)		top_con--;	    break;	default:	    break;	}	if (all_dls_complete(connections, num_connections) == TRUE)	{	    /*	     * redraw the display again 	     */	    /*	     * Delay a bit to get the proper value	     */	    napms(300);	    curses_draw_display(connections, num_connections, mirrors,				num_servers);	    refresh();	    break;	}    }    return DONE;}void curses_exit_resume(connection_data * connections, int num_connections){    /*     * Ugly      */    extern pthread_t *threads;    /* indicate that we are out of the display loop */    rt.in_curses_display_loop = FALSE;    message("Aborting...");    terminate_threads(threads, num_connections);    quit("Ok..please resume later with the -r switch");}voidcurses_exit_no_resume(connection_data * connections, int num_connections){    /*     * Ugly      */    extern pthread_t *threads;    /* indicate that we are out of the display loop */    rt.in_curses_display_loop = FALSE;    terminate_threads(threads, num_connections);    if (delete_downloads(connections, num_connections) == 1)    {	message("Cleaned up the file parts");    } else    {	message("unable to cleanup the downloaded file parts");    }    if (log_delete_logfile(&connections[0].u) != 0)    {	die("Error while deleting the logfile: %s", strerror(errno));    }    quit("Aborted...ok");}/* because of different args for different ncurses, I had to write these  * my self  */#define kwattr_get(win,a,p,opts)	  ((void)((a) != 0 && (*(a) = (win)->_attrs)), (void)((p) != 0 && (*(p) = PAIR_NUMBER((win)->_attrs))),OK)#define kwattr_set(win,a,p,opts) ((win)->_attrs = (((a) & ~A_COLOR) | COLOR_PAIR(p)), OK)/* Message: prints a message to the screen */void curses_message(const char *msg){    attr_t attrs;    short i;    int x, y;    /*     * Lock the mutex      */    pthread_mutex_lock(&curses_msg_mutex);    if (rt.in_curses_display_loop == TRUE)    {	strncpy(message_buffer, msg, MAX_MSG_SIZE);	pthread_mutex_unlock(&curses_msg_mutex);	return;    } else    {	/*	 * get the cursor position 	 */	getyx(stdscr, y, x);	kwattr_get(stdscr, &attrs, &i, NULL);	move(19, 0);	clrtoeol();	move(20, 0);	clrtoeol();	move(21, 0);	clrtoeol();	attrset(COLOR_PAIR(MSG_PAIR) | A_BOLD);	mvprintw(19, 0, "%s", msg);	attrset(COLOR_PAIR(NULL_PAIR));	/*	 * Unlock the mutex 	 */	refresh();	kwattr_set(stdscr, attrs, i, NULL);	/*	 * set the cursor to whhere it was */	move(y, x);	pthread_mutex_unlock(&curses_msg_mutex);    }}/* Displays the mesasge and gets the users input for overwriting files*/int curses_query_user_input(const char *args, ...){    char p[MAX_MSG_SIZE];    va_list vp;    attr_t attrs;    int x, y;    int ch;    int i;    va_start(vp, args);    vsnprintf(p, sizeof(p), args, vp);    va_end(vp);    getyx(stdscr, y, x);    kwattr_get(stdscr, &attrs, &i, NULL);    attrset(COLOR_PAIR(PROMPT_PAIR) | A_BOLD);    move(19, 0);    clrtoeol();    move(20, 0);    clrtoeol();    move(21, 0);    clrtoeol();    mvprintw(19, 0, "%s", p);    echo();    refresh();    do    {	napms(20);	ch = getch();    }    while (ch == ERR);    refresh();    noecho();    kwattr_set(stdscr, attrs, i, NULL);    /*     * set the cursor to where it was      */    move(y, x);    /*     * the following strange line  is for compatibility      */    return islower(ch) ? toupper(ch) : ch;}void curses_display_est_time(int row, int col, off_t bytes_left,			     float current_speed){    long long seconds_left;/* If the bytes left to obtain is less than zero, or the current_speed is zero * then just quit without printing anything  */    if (bytes_left < 0 || current_speed <= 0)	return;    else	seconds_left = (long long) (bytes_left / current_speed);    move(row, col);    clrtoeol();    if (seconds_left >= 3600)	mvprintw(row, col, "Time remaining %Ld hours %Ld minutes %Ld seconds",		 seconds_left / 3600, seconds_left % 3600 / 60,		 (seconds_left % 3600) % 60);    else if (seconds_left >= 60)	mvprintw(row, col, "Time remaining %Ld minutes %Ld seconds",		 seconds_left % 3600 / 60, (seconds_left % 3600) % 60);    else	mvprintw(row, col, "Time remaining %Ld seconds", seconds_left);    return;}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -