int con_full_box( int x, int y, const char *title, VArray *va, ConMenuInfo *menu_info ) { ScrollPos scroll; scroll.wrap = 0; scroll.set_min_max( 0, va->count()-1 ); scroll.set_pagesize( con_max_y() - 3 ); /* one title and two status */ scroll.go( 0 ); char pos_str[32]; con_xy( 1, 1 ); con_puts( title, menu_info->ti ); con_ce( menu_info->ti ); while(4) { VString str; int z; for( z = 0; z < scroll.pagesize(); z++ ) { if ( scroll.page() + z < va->count() ) str = va->get( scroll.page() + z ); else str = "~"; str = str_dot_reduce( str, con_max_x()-1 ); con_xy( 1, z + 2 ); int c = ( scroll.page() + z == scroll.pos() ) ? menu_info->ch : menu_info->cn; con_puts( str, c ); con_ce( c ); } sprintf( pos_str, " %5d of %5d", scroll.pos()+1, scroll.max()+1 ); con_out( con_max_x() - 15, 1, pos_str, menu_info->ti ); int ch; switch( (ch = con_getch()) ) { case 27 : menu_info->ec = 27; return -1; break; case 8 : menu_info->ec = 8; return -1; break; case KEY_BACKSPACE : menu_info->ec = KEY_BACKSPACE; return -1; break; case 13 : menu_info->ec = 13; return scroll.pos(); break; case KEY_UP : scroll.up(); break; case KEY_DOWN : scroll.down(); break; case KEY_NPAGE : scroll.npage(); break; case KEY_PPAGE : scroll.ppage(); break; case KEY_HOME : scroll.home(); break; case KEY_END : scroll.end(); break; default: if ( tolower(ch) == tolower(menu_info->ac) ) { menu_info->ec = menu_info->ac; return -2; } break; } } }
void tree_view() { VString str; if (dir_tree.count() == 0) { tree_load(); if (dir_tree.count() == 0) tree_rebuild(); } say1( " " ); int new_pos = tree_index( work_path ); if ( new_pos == -1 ) new_pos = 0; BSet set; /* used for searching */ set.set_range1( 'a', 'z' ); set.set_range1( 'A', 'Z' ); set.set_range1( '0', '9' ); set.set_str1( "._-~" ); set.set_str1( "?*>[]" ); ScrollPos scroll; scroll.set_min_max( 0, dir_tree.count()-1 ); scroll.set_pagesize( PS+2 ); scroll.go( new_pos ); int key = 0; int opos = -1; int opage = -1; while( key != 27 && key != 13 && key != '-' && toupper( key ) != 'Q' && toupper( key ) != 'X' && key != KEY_ALT_X ) { if ( key >= 'A' && key <= 'Z' ) key = tolower( key ); if ( key == 's' ) { str = ""; say1( "Enter search pattern: ( use TAB to advance )" ); key = con_getch(); while( set.in( key ) || key == 8 || key == KEY_BACKSPACE || key == 9 ) { if ( key == 8 || key == KEY_BACKSPACE ) str_trim_right( str, 1 ); else if ( key != 9 ) str_add_ch( str, key ); say2( str ); if ( dir_tree.count() == 0 ) { key = con_getch(); continue; } int z; if ( key == 9 ) { z = scroll.pos() + 1; if (z > scroll.max() ) z = scroll.min(); } else z = scroll.pos(); int direction = 1; int found = 0; int loops = 0; VString s_mask = str; vfu_expand_mask( s_mask ); while(1) { if ( z > scroll.max() ) z = scroll.min(); if ( z < scroll.min() ) z = scroll.max(); VString str1 = dir_tree[z]; str_trim_right( str1, 1 ); int j = str_rfind(str1,'/'); if (j < 0) str1 = ""; else str_trim_left( str1, j+1 ); found = ( FNMATCH( s_mask, str1 ) == 0 ); if ( found ) break; z += direction; if ( loops++ > dir_tree.count() ) break; } if (found) { scroll.go(z); tree_draw_page( scroll ); tree_draw_pos( scroll, opos ); } key = con_getch(); } say1( "" ); say2( "" ); } else switch( key ) { case KEY_UP : scroll.up(); break; case KEY_DOWN : scroll.down(); break; case KEY_PPAGE : scroll.ppage(); break; case KEY_NPAGE : scroll.npage(); break; case KEY_HOME : scroll.home(); break; case KEY_END : scroll.end(); break; case 'r' : tree_rebuild(); scroll.set_min_max( 0, dir_tree.count()-1 ); scroll.home(); say1( "Rebuild done." ); break; case 'w' : tree_save(); break; case 'l' : tree_load(); scroll.set_min_max( 0, dir_tree.count()-1 ); scroll.home(); break; case 'z' : case KEY_CTRL_Z : str = dir_tree[scroll.pos()]; str_tr( str, "\\", "/" ); size_cache_set( str, vfu_dir_size( str ) ); tree_draw_page( scroll ); tree_draw_pos( scroll, opos ); say1( "Done." ); break; } if (opage != scroll.page()) tree_draw_page( scroll ); if (opos != scroll.pos() - scroll.page() || opage != scroll.page()) tree_draw_pos( scroll, opos ); opos = scroll.pos() - scroll.page(); opage = scroll.page(); key = con_getch(); } if ( key == 13 ) { str = dir_tree[scroll.pos()]; str_tr( str, "\\", "/" ); vfu_chdir( str ); } do_draw = 2; };
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; };