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

📄 ncurses.c

📁 video linux conference
💻 C
📖 第 1 页 / 共 4 页
字号:
    if( ( ! psz_searchstring ) ||  strlen( psz_searchstring ) <= 0 )    {        p_sys->i_box_plidx = p_sys->i_before_search;        return;    }    i_max = p_sys->i_current_view == VIEW_ALL ?                p_playlist->i_size : p_sys->i_plist_entries;    i_item = SubSearchPlaylist( p_intf, psz_searchstring, i_first + 1, i_max );    if( i_item < 0 )    {        i_item = SubSearchPlaylist( p_intf, psz_searchstring, 0, i_first );    }    if( i_item < 0 || i_item >= i_max ) return;    p_sys->i_box_plidx = i_item;}static int SubSearchPlaylist( intf_thread_t *p_intf, char *psz_searchstring,                              int i_start, int i_stop ){    intf_sys_t *p_sys = p_intf->p_sys;    playlist_t *p_playlist = p_sys->p_playlist;    int i, i_item = -1;    if( p_sys->i_current_view == VIEW_ALL )    {        for( i = i_start + 1; i < i_stop; i++ )        {            if( strcasestr( p_playlist->pp_items[i]->input.psz_name,                            psz_searchstring ) != NULL                || strcasestr( p_playlist->pp_items[i]->input.psz_uri,                               psz_searchstring ) != NULL )            {                i_item = i;                break;            }        }    }    else    {        for( i = i_start + 1; i < i_stop; i++ )        {            if( strcasestr( p_sys->pp_plist[i]->psz_display,                            psz_searchstring ) != NULL )            {                i_item = i;                break;            }        }    }    return i_item;}static void mvnprintw( int y, int x, int w, const char *p_fmt, ... ){    va_list  vl_args;    char    *p_buf = NULL;    int      i_len;    va_start( vl_args, p_fmt );    vasprintf( &p_buf, p_fmt, vl_args );    va_end( vl_args );    if( p_buf == NULL )    {        return;    }    if(  w > 0 )    {        if( ( i_len = strlen( p_buf ) ) > w )        {            int i_cut = i_len - w;            int x1 = i_len/2 - i_cut/2;            int x2 = x1 + i_cut;            if( i_len > x2 )            {                memmove( &p_buf[x1], &p_buf[x2], i_len - x2 );            }            p_buf[w] = '\0';            if( w > 7 )            {                p_buf[w/2-1] = '.';                p_buf[w/2  ] = '.';                p_buf[w/2+1] = '.';            }            mvprintw( y, x, "%s", p_buf );        }        else        {            mvprintw( y, x, "%s", p_buf );            mvhline( y, x + i_len, ' ', w - i_len );        }    }}static void MainBoxWrite( intf_thread_t *p_intf, int l, int x, const char *p_fmt, ... ){    intf_sys_t     *p_sys = p_intf->p_sys;    va_list  vl_args;    char    *p_buf = NULL;    if( l < p_sys->i_box_start || l - p_sys->i_box_start >= p_sys->i_box_lines )    {        return;    }    va_start( vl_args, p_fmt );    vasprintf( &p_buf, p_fmt, vl_args );    va_end( vl_args );    if( p_buf == NULL )    {        return;    }    mvnprintw( p_sys->i_box_y + l - p_sys->i_box_start, x, COLS - x - 1, "%s", p_buf );}static void Redraw( intf_thread_t *p_intf, time_t *t_last_refresh ){    intf_sys_t     *p_sys = p_intf->p_sys;    input_thread_t *p_input = p_sys->p_input;    int y = 0;    int h;    int y_end;    //clear();    /* Title */    attrset( A_REVERSE );    mvnprintw( y, 0, COLS, "VLC media player" " (ncurses interface) [ h for help ]" );    attroff( A_REVERSE );    y += 2;    /* Infos */    if( p_input && !p_input->b_dead )    {        char buf1[MSTRTIME_MAX_SIZE];        char buf2[MSTRTIME_MAX_SIZE];        vlc_value_t val;        vlc_value_t val_list;        /* Source */        mvnprintw( y++, 0, COLS, " Source   : %s",                   p_input->input.p_item->psz_uri );        /* State */        var_Get( p_input, "state", &val );        if( val.i_int == PLAYING_S )        {            mvnprintw( y++, 0, COLS, " State    : Playing" );        }        else if( val.i_int == PAUSE_S )        {            mvnprintw( y++, 0, COLS, " State    : Paused" );        }        else        {            y++;        }        if( val.i_int != INIT_S && val.i_int != END_S )        {            audio_volume_t i_volume;            /* Position */            var_Get( p_input, "time", &val );            msecstotimestr( buf1, val.i_time / 1000 );            var_Get( p_input, "length", &val );            msecstotimestr( buf2, val.i_time / 1000 );            mvnprintw( y++, 0, COLS, " Position : %s/%s (%.2f%%)", buf1, buf2, p_sys->f_slider );            /* Volume */            aout_VolumeGet( p_intf, &i_volume );            mvnprintw( y++, 0, COLS, " Volume   : %i%%", i_volume*200/AOUT_VOLUME_MAX );            /* Title */            if( !var_Get( p_input, "title", &val ) )            {                var_Change( p_input, "title", VLC_VAR_GETCHOICES, &val_list, NULL );                if( val_list.p_list->i_count > 0 )                {                    mvnprintw( y++, 0, COLS, " Title    : %d/%d", val.i_int, val_list.p_list->i_count );                }                var_Change( p_input, "title", VLC_VAR_FREELIST, &val_list, NULL );            }            /* Chapter */            if( !var_Get( p_input, "chapter", &val ) )            {                var_Change( p_input, "chapter", VLC_VAR_GETCHOICES, &val_list, NULL );                if( val_list.p_list->i_count > 0 )                {                    mvnprintw( y++, 0, COLS, " Chapter  : %d/%d", val.i_int, val_list.p_list->i_count );                }                var_Change( p_input, "chapter", VLC_VAR_FREELIST, &val_list, NULL );            }        }        else        {            y += 2;        }    }    else    {        mvnprintw( y++, 0, COLS, "Source: <no current item>" );        DrawEmptyLine( p_sys->w, y++, 0, COLS );        DrawEmptyLine( p_sys->w, y++, 0, COLS );        DrawEmptyLine( p_sys->w, y++, 0, COLS );    }    DrawBox( p_sys->w, y, 0, 3, COLS, "" );    DrawEmptyLine( p_sys->w, y+1, 1, COLS-2);    DrawLine( p_sys->w, y+1, 1, (int)(p_intf->p_sys->f_slider/100.0 * (COLS -2)) );    y += 3;    p_sys->i_box_y = y + 1;    p_sys->i_box_lines = LINES - y - 2;    h = LINES - y;    y_end = y + h - 1;    if( p_sys->i_box_type == BOX_HELP )    {        /* Help box */        int l = 0;        DrawBox( p_sys->w, y++, 0, h, COLS, " Help " );        MainBoxWrite( p_intf, l++, 1, "[Display]" );        MainBoxWrite( p_intf, l++, 1, "     h,H         Show/Hide help box" );        MainBoxWrite( p_intf, l++, 1, "     i           Show/Hide info box" );        MainBoxWrite( p_intf, l++, 1, "     L           Show/Hide messages box" );        MainBoxWrite( p_intf, l++, 1, "     P           Show/Hide playlist box" );        MainBoxWrite( p_intf, l++, 1, "     B           Show/Hide filebrowser" );        MainBoxWrite( p_intf, l++, 1, "" );        MainBoxWrite( p_intf, l++, 1, "[Global]" );        MainBoxWrite( p_intf, l++, 1, "     q, Q        Quit" );        MainBoxWrite( p_intf, l++, 1, "     s           Stop" );        MainBoxWrite( p_intf, l++, 1, "     <space>     Pause/Play" );        MainBoxWrite( p_intf, l++, 1, "     f           Toggle Fullscreen" );        MainBoxWrite( p_intf, l++, 1, "     n, p        Next/Previous playlist item" );        MainBoxWrite( p_intf, l++, 1, "     [, ]        Next/Previous title" );        MainBoxWrite( p_intf, l++, 1, "     <, >        Next/Previous chapter" );        MainBoxWrite( p_intf, l++, 1, "     <right>     Seek +1%%" );        MainBoxWrite( p_intf, l++, 1, "     <left>      Seek -1%%" );        MainBoxWrite( p_intf, l++, 1, "     a           Volume Up" );        MainBoxWrite( p_intf, l++, 1, "     z           Volume Down" );        MainBoxWrite( p_intf, l++, 1, "" );        MainBoxWrite( p_intf, l++, 1, "[Playlist]" );        MainBoxWrite( p_intf, l++, 1, "     r           Random" );        MainBoxWrite( p_intf, l++, 1, "     l           Loop Playlist" );        MainBoxWrite( p_intf, l++, 1, "     R           Repeat item" );        MainBoxWrite( p_intf, l++, 1, "     o           Order Playlist by title" );        MainBoxWrite( p_intf, l++, 1, "     O           Reverse order Playlist by title" );        MainBoxWrite( p_intf, l++, 1, "     /           Look for an item" );        MainBoxWrite( p_intf, l++, 1, "     A           Add an entry" );        MainBoxWrite( p_intf, l++, 1, "     D, <del>    Delete an entry" );        MainBoxWrite( p_intf, l++, 1, "     <backspace> Delete an entry" );        MainBoxWrite( p_intf, l++, 1, "" );        MainBoxWrite( p_intf, l++, 1, "[Boxes]" );        MainBoxWrite( p_intf, l++, 1, "     <up>,<down>     Navigate through the box line by line" );        MainBoxWrite( p_intf, l++, 1, "     <pgup>,<pgdown> Navigate through the box page by page" );        MainBoxWrite( p_intf, l++, 1, "" );        MainBoxWrite( p_intf, l++, 1, "[Player]" );        MainBoxWrite( p_intf, l++, 1, "     <up>,<down>     Seek +/-5%%" );        MainBoxWrite( p_intf, l++, 1, "" );        MainBoxWrite( p_intf, l++, 1, "[Miscellaneous]" );        MainBoxWrite( p_intf, l++, 1, "     Ctrl-l          Refresh the screen" );        p_sys->i_box_lines_total = l;        if( p_sys->i_box_start >= p_sys->i_box_lines_total )        {            p_sys->i_box_start = p_sys->i_box_lines_total - 1;        }        if( l - p_sys->i_box_start < p_sys->i_box_lines )        {            y += l - p_sys->i_box_start;        }        else        {            y += p_sys->i_box_lines;        }    }    else if( p_sys->i_box_type == BOX_INFO )    {        /* Info box */        int l = 0;        DrawBox( p_sys->w, y++, 0, h, COLS, " Information " );        if( p_input )        {            int i,j;            vlc_mutex_lock( &p_input->input.p_item->lock );            for( i = 0; i < p_input->input.p_item->i_categories; i++ )            {                info_category_t *p_category = p_input->input.p_item->pp_categories[i];                if( y >= y_end ) break;                MainBoxWrite( p_intf, l++, 1, "  [%s]", p_category->psz_name );                for( j = 0; j < p_category->i_infos; j++ )                {                    info_t *p_info = p_category->pp_infos[j];                    if( y >= y_end ) break;                    MainBoxWrite( p_intf, l++, 1, "      %s: %s", p_info->psz_name, p_info->psz_value );                }            }            vlc_mutex_unlock( &p_input->input.p_item->lock );        }        else        {            MainBoxWrite( p_intf, l++, 1, "No item currently playing" );        }        p_sys->i_box_lines_total = l;        if( p_sys->i_box_start >= p_sys->i_box_lines_total )        {            p_sys->i_box_start = p_sys->i_box_lines_total - 1;        }        if( l - p_sys->i_box_start < p_sys->i_box_lines )        {            y += l - p_sys->i_box_start;        }        else        {            y += p_sys->i_box_lines;        }    }    else if( p_sys->i_box_type == BOX_LOG )    {        int i_line = 0;        int i_stop;        int i_start;        DrawBox( p_sys->w, y++, 0, h, COLS, " Logs " );        i_start = p_intf->p_sys->p_sub->i_start;        vlc_mutex_lock( p_intf->p_sys->p_sub->p_lock );        i_stop = *p_intf->p_sys->p_sub->pi_stop;        vlc_mutex_unlock( p_intf->p_sys->p_sub->p_lock );        for( ;; )        {            static const char *ppsz_type[4] = { "", "error", "warning", "debug" };            if( i_line >= h - 2 )            {                break;            }            i_stop--;            i_line++;            if( i_stop < 0 ) i_stop += VLC_MSG_QSIZE;            if( i_stop == i_start )            {                break;            }            mvnprintw( y + h-2-i_line, 1, COLS - 2, "   [%s] %s",                      ppsz_type[p_sys->p_sub->p_msg[i_stop].i_type],                      p_sys->p_sub->p_msg[i_stop].psz_msg );        }        vlc_mutex_lock( p_intf->p_sys->p_sub->p_lock );        p_intf->p_sys->p_sub->i_start = i_stop;        vlc_mutex_unlock( p_intf->p_sys->p_sub->p_lock );        y = y_end;    }    else if( p_sys->i_box_type == BOX_BROWSE )    {        /* Filebrowser box */        int        i_start, i_stop;        int        i_item;        DrawBox( p_sys->w, y++, 0, h, COLS, " Browse " );        if( p_sys->i_box_bidx >= p_sys->i_dir_entries ) p_sys->i_box_plidx = p_sys->i_dir_entries - 1;        if( p_sys->i_box_bidx < 0 ) p_sys->i_box_bidx = 0;        if( p_sys->i_box_bidx < (h - 2)/2 )        {            i_start = 0;            i_stop = h - 2;        }        else if( p_sys->i_dir_entries - p_sys->i_box_bidx > (h - 2)/2 )        {            i_start = p_sys->i_box_bidx - (h - 2)/2;            i_stop = i_start + h - 2;        }        else        {            i_stop = p_sys->i_dir_entries;            i_start = p_sys->i_dir_entries - (h - 2);        }        if( i_start < 0 )        {            i_start = 0;        }        if( i_stop > p_sys->i_dir_entries )        {            i_stop = p_sys->i_dir_entries;        }        for( i_item = i_start; i_item < i_stop; i_item++ )        {            vlc_bool_t b_selected = ( p_sys->i_box_bidx == i_item );            if( y >= y_end ) break;            if( b_selected )            {                attrset( A_REVERSE );            }            mvnprintw( y++, 1, COLS - 2, "%c %s", p_sys->pp_dir_entries[i_item]->b_file == VLC_TRUE ? '-' : '+',                            p_sys->pp_dir_entries[i_item]->psz_path );            if( b_selected )            {                attroff( A_REVERSE );            }        }    }    else if( ( p_sys->i_box_type == BOX_PLAYLIST ||               p_sys->i_box_type == BOX_SEARCH ||               p_sys->i_box_type == BOX_OPEN  ) && p_sys->p_playlist )    {        /* Playlist box */        playlist_t *p_playlist = p_sys->p_playlist;        int        i_start, i_stop, i_max = p_sys->i_plist_entries;        int        i_item;        char       *psz_title;        switch( p_sys->i_current_view )        {            case VIEW_ALL:                psz_title = strdup( " Playlist (All, unsorted) " );                i_max = p_playlist->i_size;                break;            case VIEW_CATEGORY:                psz_title = strdup( " Playlist (By category) " );                break;            default:                psz_title = strdup( " Playlist (Manually added) " );        }        DrawBox( p_sys->w, y++, 0, h, COLS, psz_title );        if( p_sys->i_current_view != VIEW_ALL &&                ( p_sys->b_need_update || p_sys->pp_plist == NULL ) )        {            PlaylistRebuild( p_intf );        }        if( p_sys->b_box_plidx_follow )        {            FindIndex( p_intf );        }        if( p_sys->i_box_plidx < 0 ) p_sys->i_box_plidx = 0;        if( p_sys->i_box_plidx < (h - 2)/2 )        {            i_start = 0;            i_stop = h - 2;        }        else if( i_max - p_sys->i_box_plidx > (h - 2)/2 )        {            i_start = p_sys->i_box_plidx - (h - 2)/2;            i_stop = i_start + h - 2;        }        else        {            i_stop = i_max;            i_start = i_max - (h - 2);        }        if( i_start < 0 )        {            i_start = 0;        }        if( i_stop > i_max )        {            i_stop = i_max;        }       if( p_sys->i_current_view == VIEW_ALL )       {        for( i_item = i_start; i_item < i_stop; i_item++ )        {            vlc_bool_t b_selected = ( p_sys->i_box_plidx == i_item );

⌨️ 快捷键说明

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