void vfu_load_dir_colors() { #ifdef _TARGET_UNIX_ VArray va; va.fload( "/etc/DIR_COLORS" ); if (va.count() == 0) return; while( va.count() ) { VString str = va[0]; va.del( 0 ); int comment = str_find( str, '#' ); if ( comment != -1 ) str_sleft( str, comment ); str_cut( str, " \t" ); if ( str_len( str ) == 0 ) continue; if ( strncmp( str, "TERM " , 5 ) == 0 ) continue; if ( strncmp( str, "COLOR " , 6 ) == 0 ) continue; if ( strncmp( str, "OPTIONS ", 8 ) == 0 ) continue; int pos = -1; if ( str_find( str, "31" ) != -1 ) pos = cRED; else if ( str_find( str, "32" ) != -1 ) pos = cGREEN; else if ( str_find( str, "33" ) != -1 ) pos = cYELLOW; else if ( str_find( str, "34" ) != -1 ) pos = cBLUE; else if ( str_find( str, "35" ) != -1 ) pos = cMAGENTA; else if ( str_find( str, "36" ) != -1 ) pos = cCYAN; else if ( str_find( str, "37" ) != -1 ) pos = cWHITE; else ; int spc = str_find( str, ' ' ); if ( spc == -1 || pos == -1 ) continue; str_sleft( str, spc ); str_replace( str, "DIR", ".[].<>" ); str_replace( str, "LINK", ".->" ); str_replace( str, "FIFO", ".()" ); str_replace( str, "SOCK", ".##" ); str_replace( str, "BLK", ".==" ); str_replace( str, "CHR", ".++" ); str_replace( str, "EXEC", ".**" ); str_ins( ext_colors[pos], 0, str ); }; for ( int z = 0; z < 16; z++ ) if( str_len( ext_colors[z] ) > 0 ) { ext_colors[z] += "."; if ( opt.lower_case_ext_config ) str_low( ext_colors[z] ); } #endif /* _TARGET_UNIX_ */ }
fsize_t size_cache_get( const char *s ) { int z = size_cache_index( s ); if ( z != -1 ) { VString str = size_cache[z]; str_sleft( str, SIZE_CACHE_OFFSET ); return atof( str ); } else return -1; }
void tree_draw_page( ScrollPos &scroll ) { VString str = " "; str_mul( str, con_max_x() ); str = " SiZE DiRECTORY" + str; str_sleft( str, con_max_x()-16 ); con_out(1,3, str, cHEADER ); int z = 0; for(z = 0; z < scroll.pagesize(); z++) { if (scroll.page() + z <= scroll.max()) { tree_draw_item( scroll.page(), z ); } else { con_xy( 1, 3+1+z ); con_puts( "~", cCYAN ); con_ce( cCYAN ); } } }
void tree_draw_item( int page, int index, int hilite ) { if ( page + index >= dir_tree.count() ) return; VString s1 = dir_tree[page+index]; str_trim_right(s1,1); VString s2 = s1; int j = str_rfind( s1,'/'); str_trim_right(s1,str_len(s2)-j-1); str_trim_left(s2,j+1); for(j = 0; j < str_len(s1); j++) { if (s1[j] == '/') str_set_ch(s1,j, '|'); else if (s1[j] == '\\') str_set_ch(s1,j, '\\'); else str_set_ch(s1,j, '+'); } if (opt.tree_compact) { str_replace(s1,"+", ""); str_replace(s1,"|", "| "); str_replace(s1,"\\"," "); str_trim_right(s1,2); s1 += "--"; } else { str_replace(s1,"+", " "); str_replace(s1,"\\", " "); s1 += "--"; } VString str = dir_tree[page+index]; str_tr( str,"\\", "/" ); VString sz; sz.fi( size_cache_get( str ) ); if ( sz == "-1" ) sz = "n/a"; else str_comma( sz ); str_pad( sz, 14 ); s1 = sz + " " + s1; int m = con_max_x() - 1; /* doesn't speed the code... :) */ if ( str_len( s1 ) > m ) { str_sleft( s1, m ); s2 = ""; } else if ( str_len( s1 ) + str_len( s2 ) > m ) { str_sleft( s2, m - str_len( s1 ) ); } con_xy(1,3+1+index); if (hilite) { con_puts( s1, cBAR ); con_puts( s2, cBAR ); con_ce( cBAR ); } else { con_puts( s1, cSTATUS ); con_puts( s2, cMESSAGE ); con_ce( cSTATUS ); } }
int vfu_get_dir_name( const char *prompt, VString &target, int should_exist ) { int res = -1; /* #ifdef _TARGET_UNIX_ leaveok(stdscr, FALSE); #endif */ VArray dir_list; say1(prompt); say2(""); int pos = 0; int page = 0; int ch = 0; int insert = 1; int firsthit = 1; pos = str_len( target ); //------------------------------------------------------------------ con_cshow(); say2( target, firsthit ? cINPUT2 : cINPUT ); while(1) { int mx = con_max_x() - 1; VString target_out = target; if ( (pos < page) || (pos+1 > page + mx) || (page > 0 && pos == page) ) page = pos - mx / 2; if ( page < 0 ) page = 0; str_trim_left( target_out, page ); str_sleft( target_out, mx ); str_pad( target_out, -mx ); if ( page > 0 ) str_set_ch( target_out, 0, '<' ); if ( str_len( target ) - page > mx ) str_set_ch( target_out, mx-1, '>' ); say2( target_out, firsthit ? cINPUT2 : cINPUT ); con_xy( pos-page+1, con_max_y() ); if (ch == 0) ch = con_getch(); if (ch == '\\') ch = '/'; /* dos hack :)) */ if ( ch == '/' && str_find( target, '/' ) == -1 && target[0] == '~' ) { target = tilde_expand( target ); str_fix_path( target ); pos = str_len( target ); ch = 0; } if ((ch == 8 || ch == KEY_BACKSPACE) && pos > 0) { pos--; str_del( target, pos, 1 ); } else if (ch == KEY_CTRL_A && str_len( target ) > 0) { int z = str_len( target )-1; if ( str_get_ch(target, z) == '/' ) z--; while ( z > 0 && str_get_ch(target,z) != '/' ) z--; z++; str_sleft(target,z); pos = z; } else if ( ch == 9 && str_len( target ) > 0) { int z; dir_list.undef(); VString dmain; /* main/base path */ VString dtail; /* item that should be expanded/glob */ dmain = str_file_path( target ); dtail = str_file_name_ext( target ); /* int lastslash = str_rfind(target, '/'); if ( lastslash == -1 ) { dmain = ""; dtail = target; } else { dmain = target; dtail = target; str_sleft( dmain, lastslash+1 ); str_trim_left( dtail, lastslash+1 ); } */ __glob_gdn( dmain, dtail, dir_list ); z = dir_list.count()-1; if (dir_list.count()) { if ( dir_list.count() > 1) { int mc = 0; /* match count */ int mi = 0; /* match letter index */ while(4) { mc = 0; int li; /* counter */ for ( li = 0; li < dir_list.count(); li++ ) { if ( str_get_ch( dir_list[ 0], mi ) == str_get_ch( dir_list[li], mi ) ) mc++; } if ( mc != dir_list.count() ) break; mi++; } target.setn( dmain + dir_list[0], str_len( dmain ) + mi ); pos = str_len( target ); say2( target, cINPUT ); con_xy( pos+1, con_max_y() ); vfu_beep(); ch = con_getch(); if ( ch != 9 ) { dir_list.undef(); continue; } dir_list.sort(); con_chide(); z = vfu_menu_box( 10, 5, "Complete...", &dir_list ); con_cshow(); ch = 0; } else ch = 0; if ( z != -1 ) { while( str_len( target ) > 0 && target[-1] != '/' ) str_chop( target ); target += dir_list[z]; } pos = str_len( target ); dir_list.undef(); if (ch != 0) continue; } else { /* no match found -- cannot complete */ vfu_beep(); } } else if (ch == 13) { res = 1; break; } else if (ch == 27) { target = ""; res = 0; break; } if (ch == KEY_CTRL_U) { target = ""; pos = 0; } else if (ch == KEY_CTRL_X) { char t[MAX_PATH]; if ( target[0] == '~' ) target = tilde_expand( target ); expand_path( target, t ); str_fix_path( t ); target = t; pos = str_len( target ); } else if (ch >= 32 && ch <= 255 ) // && pos < 70) { if (firsthit) { target = ""; pos = 0; } if (!insert) str_del( target, pos, 1 ); str_ins_ch( target, pos, ch ); pos++; } else if( ch == KEY_LEFT ) { if (pos > 0) pos--; } else if( ch == KEY_RIGHT ) { if (pos < str_len( target )) pos++; } else if ( ch == KEY_IC ) insert = !insert; else if ( ch == KEY_HOME ) pos = 0; else if ( ch == KEY_END ) pos = str_len(target); else if ( ch == KEY_DC && pos < str_len(target) ) str_del( target, pos, 1 ); else if ( ch == KEY_NPAGE || ch == KEY_PPAGE ) { con_chide(); int zz = vfu_hist_menu( 5, 5, ( ch == KEY_PPAGE ) ? "Dir Entry History" : "ChDir History", ( ch == KEY_PPAGE ) ? HID_GETDIR : HID_CHDIR ); con_cshow(); if (zz != -1) { const char* pc = vfu_hist_get( ( ch == KEY_PPAGE ) ? HID_GETDIR : HID_CHDIR, zz ); if ( pc ) { target = pc; pos = str_len( target ); } } } ch = 0; firsthit = 0; } con_chide(); //------------------------------------------------------------------ str_cut_spc( target ); if ( res == 1 && target[0] == '~' ) { target = tilde_expand( target ); str_fix_path( target ); } /* if ( target.len() > 0 ) { // well this tmp is kind of s... ama k'vo da pravi chovek :) // FIXME: dos version? if ( __ExpandGetDirName && target[0] != '/' #ifdef _TARGET_GO32_ && !( target[1] == ':' && target[2] == '/' ) #endif ) target = CPath + target; StrFixPath( target ); // add trailing slash if not exist } */ /* #ifdef _TARGET_UNIX_ leaveok(stdscr, TRUE); #endif */ if ( res == 1 && str_len( target ) > 0 && should_exist && !dir_exist( target )) { vfu_beep(); int ch = tolower( vfu_ask( "Directory does not exist! Create? " "( ENTER=Yes, ESC=cancel )", "\033\rcC" )); if ( ch == 27 ) { res = 0; target = ""; } else if ( ch == 13 ) if (make_path( target )) { if(tolower( vfu_ask( "Cannot create path! ( ESC=cancel, C=continue-anyway )", "\033Cc" )) == 27) { res = 0; target = ""; } } } say1(" "); say2(" "); if ( str_len( target ) > 0) { str_fix_path( target ); vfu_hist_add( HID_GETDIR, target ); } str_cut_spc( target ); ASSERT( res == 0 || res == 1 ); return res; }
int con_toggle_box( int x, int y, const char *title, ToggleEntry* toggles, ConMenuInfo *menu_info ) { ScrollPos scroll; int z; int w = -1; int h = -1; int maxlen = 0; int count = 0; while( toggles[count].key != -1 ) { int sl = strlen( toggles[count].name ); if (sl > maxlen) maxlen = sl; count++; } maxlen += 6+3; // 6 for state string and 3 for " key " string in the front if (w == -1) w = maxlen; if (h == -1) h = count; z = strlen(title); if (w < z) w = z; if (h > count) h = count; if (h == 0) h = 1; // FIXME: those should be fixed!!! if (x + w > con_max_x()) w = con_max_x() - x - 1; if (y + h > con_max_y()-4) h = con_max_y() - y - 5; VString str; VString str1; VString hots = ""; for(z = 0; z < count; z++) if (strncmp("--", toggles[z].name, 2)) str_add_ch( hots, toggles[z].key ); else str_add_ch( hots,' ' ); con_xy(x,y); int ch = 0; str = ""; str = title; str_pad( str,-w, menu_info->bo ? '-' : ' ' ); if (str_len(str) > w) str_sleft(str,w); if (menu_info->bo) str = ".-" + str + "-."; else str = " " + str + " "; con_out(x,y,str,menu_info->ti); y++; scroll.wrap = 1; scroll.set_min_max( 0, count-1 ); scroll.set_pagesize( h ); scroll.go( 0 ); while(1) { for( z = 0; z < scroll.pagesize(); z++ ) { if (scroll.page() + z >= count) { str = " ~"; str_pad( str, -(w+2), ' '); } else { int sep = (strncmp("--", toggles[scroll.page()+z].name, 2) == 0); if (sep) { str = ""; str += toggles[scroll.page()+z].name; str_pad( str, -w, '-'); str += "--"; } else { str = " "; str_add_ch( str, toggles[scroll.page()+z].key ); str += " "; str += toggles[scroll.page()+z].name; str_pad( str, -(w-6), ' '); str1 = toggles[scroll.page()+z].states[*(toggles[scroll.page()+z].data)]; str_pad( str1, 6, ' '); str1 += " "; str += " " + str1; } } if (menu_info->bo) str = "|" + str + "|"; else str = " " + str + " "; // if (str.len() > w) StrSLeft(str,w); // str = " " + str + " "; con_out( x, y+z, str, ( scroll.page()+z != scroll.pos() ) ? menu_info->cn : menu_info->ch ); } if (menu_info->bo) { str = ""; str_pad( str, w+2, '-' ); str = "`" + str + "'"; con_out( x, y+scroll.pagesize(), str, menu_info->cn ); } ch = con_getch(); menu_info->ec = ch; if ( ch == KEY_UP ) scroll.up(); if ( ch == KEY_DOWN ) scroll.down(); if ( ch == KEY_NPAGE ) scroll.npage(); if ( ch == KEY_PPAGE ) scroll.ppage(); if ( ch == KEY_HOME ) scroll.home(); if ( ch == KEY_END ) scroll.end(); if ( ch < 0 || ch > 255 ) continue; if ( ch == 27 ) return 0; if ( ch == 13 /* && strncmp("--", toggles[scroll.pos].name, 2) */ ) return 1; z = ( ch == ' ' ) ? scroll.pos() : z = str_find( hots, ch ); if (z > -1 && strncmp("--", toggles[z].name, 2) ) { int state = *(toggles[z].data) + 1; if (toggles[z].states[state] == NULL) state = 0; *(toggles[z].data) = state; } } return -1; }
int con_menu_box( int x, int y, const char *title, VArray *va, int hotkeys, ConMenuInfo *menu_info ) { ScrollPos scroll; int z; int w = -1; int h = -1; if (w == -1) w = va->max_len(); if (h == -1) h = va->count(); z = strlen(title); if (w < z) w = z; if (h > va->count()) h = va->count(); if (h == 0) h = 1; // FIXME: those should be fixed!!! if (x + w > con_max_x()) w = con_max_x() - x - 4; if (y + h > con_max_y()-4) h = con_max_y() - y - 4; VString str; VString hots = ""; if ( hotkeys > -1 ) { for(z = 0; z < va->count(); z++) if (strncmp("--", va->get(z), 2)) str_add_ch( hots, char(((const char*)(va->get(z)))[hotkeys]) ); else str_add_ch( hots,' ' ); str_up(hots); } con_xy(x,y); int ch = 0; str = " "; str += title; str += " "; str_pad( str,-(w), menu_info->bo ? '-' : ' ' ); if (str_len(str) > w) str_sleft(str,w); if (menu_info->bo) str = ".-" + str + "-."; else str = " " + str + " "; con_out(x,y,str,menu_info->ti); y++; scroll.wrap = 1; scroll.set_min_max( 0, va->count()-1 ); scroll.set_pagesize( h ); scroll.go( 0 ); while(1) { for( z = 0; z < scroll.pagesize(); z++ ) { str = (scroll.page()+z >= va->count())? "~" : va->get(scroll.page()+z); if ( menu_info->hide_magic[0] ) { int i = str_rfind( str, menu_info->hide_magic ); if ( i != -1) str_sleft( str, i ); } str_pad( str,-w , (strncmp("--", str, 2) == 0)?'-':' '); if (str_len(str) > w) str = str_dot_reduce( str, w ); if (menu_info->bo) str = "| " + str + " |"; else str = " " + str + " "; con_out( x, y+z, str, ( scroll.page()+z != scroll.pos() ) ? menu_info->cn : menu_info->ch ); } if (menu_info->bo) { str = ""; str_pad( str, w+2, '-' ); str = "`" + str + "'"; con_out( x, y+scroll.pagesize(), str, menu_info->cn ); } ch = con_getch(); menu_info->ec = ch; if ( ch == KEY_UP ) scroll.up(); if ( ch == KEY_DOWN ) scroll.down(); if ( ch == KEY_NPAGE ) scroll.npage(); if ( ch == KEY_PPAGE ) scroll.ppage(); if ( ch == KEY_HOME ) scroll.home(); if ( ch == KEY_END ) scroll.end(); if ( ch < 0 || ch > 255 ) continue; if ( ch == 27 ) { menu_info->ac = 0; return -1; } if ( ch == 13 ) { if (strncmp("--", va->get(scroll.pos()), 2) != 0) // ako e "--" e separator { menu_info->ec = hots[scroll.pos()]; menu_info->ac = -1; return scroll.pos(); } } if ( menu_info->ac > -1 && ch == menu_info->ac ) { if (strncmp("--", va->get(scroll.pos()), 2) != 0) // ako e "--" e separator { menu_info->ec = hots[scroll.pos()]; menu_info->ac = -2; return scroll.pos(); } } z = str_find( hots, toupper(ch) ); if (z > -1) { menu_info->ec = hots[z]; menu_info->ac = -1; return z; } } menu_info->ac = -1; return -1; };
/*#######################################################################*/ extern const char *FTIMETYPE[]; /* in vfuopt.cpp */ void vfu_redraw() /* redraw file list and header */ { char t[MAX_PATH]; VString str; str = "Mask: "; str += files_mask; con_out(1,1,str,cINFO); con_ce(cINFO); if ( work_mode == WM_ARCHIVE ) con_out( con_max_x()-34, 1, " [-ARCHIVE-] ", cWARNING ); con_out(con_max_x()-17,1,"Press H for help",cINFO); con_out(con_max_x()-20,1,"VFU " VFU_VERSION " <H> for help",cINFO); str = "Path: "; str += work_path; if ( work_mode == WM_ARCHIVE ) { str += "["; str += archive_name; str += "]/"; /* NOTE: to simulate root dir visually */ str += archive_path; } str = str_dot_reduce( str, con_max_x()-1 ); con_out(1,2,str,cINFO); con_ce(cINFO); str = ""; if ( opt.sort_order == 'N' ) str = "NAME"; if ( opt.sort_order == 'M' ) str = "NAME#"; if ( opt.sort_order == 'E' ) str = "EXT"; if ( opt.sort_order == 'A' ) str = "MODE"; if ( opt.sort_order == 'O' ) str = "OWNER"; if ( opt.sort_order == 'G' ) str = "GROUP"; if ( opt.sort_order == 'T' ) str = "MTIME"; if ( opt.sort_order == 'H' ) str = "CTIME"; if ( opt.sort_order == 'C' ) str = "ATIME"; if ( opt.sort_order == 'S' ) str = "SIZE"; if ( opt.sort_order == 'Y' ) str = "TYPE"; str += opt.sort_direction == 'A' ? "+" : "-"; str = "(SORT:" + str + ")"; con_out( con_max_x() - str_len( str ) + 1, 2, str, cHEADER ); str = ""; t[0] = 0; char *spos = t; if (opt.sort_order == 'D') opt.sort_order = 'T'; /* hack anyway */ if (!opt.long_name_view) { if (opt.f_mode ) spos += sprintf( spos, "%10s ", MODE_STRING ); if (opt.f_owner ) spos += sprintf( spos, " OWNER " ); if (opt.f_group ) spos += sprintf( spos, " GROUP " ); if (opt.f_time ) spos += sprintf( spos, "%s TiME ", FTIMETYPE[opt.f_time_type] ); if (opt.f_size ) spos += sprintf( spos, filesize_fmt, "SiZE" ); }; if ( opt.f_mode + opt.f_owner + opt.f_group + opt.f_time + opt.f_size + opt.f_type == 0 ) opt.f_type = 1; /* a hack really :) if all fields are off -- turn on type one */ if (opt.f_type || opt.long_name_view) spos += sprintf( spos, "TP" ); tag_mark_pos = strlen( t ); sel_mark_pos = tag_mark_pos + 2; spos += sprintf( spos, " #NAME %s", opt.long_name_view ? "( long name view )" : "" ); str_pad( t, - con_max_x() ); str_sleft( t, con_max_x() ); con_out(1,3, t, cHEADER ); show_pos( FLI+1, files_count ); int z; for ( z = 0; z < PS; z++ ) { ASSERT( FLP + z >= 0 ); if ( FLP + z >= files_count ) { con_out( 1, z+4, "~", cPLAIN ); con_ce( cPLAIN ); } else if ( files_list[FLP+z] == NULL ) /* FIXME: if NULL?! */ { con_out( 1, z+4, "~", cPLAIN ); con_ce( cPLAIN ); } else vfu_draw( FLP + z ); } if ( files_count <= 0 ) con_out( ( con_max_x() - 20 ) / 2, 10, " *** No files found *** ", cHEADER); }