Beispiel #1
0
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 );
      }
    }
}
Beispiel #2
0
void tree_draw_pos( ScrollPos &scroll, int opos )
{
  int z = scroll.pos() - scroll.page();
  if ( opos != -1 ) tree_draw_item( scroll.page(), opos );
  tree_draw_item( scroll.page(), z, 1 );
  VString str;
  str = dir_tree[scroll.pos()];
  str_tr( str,"\\", "/" );
  
  VString sz;
  sz.fi( size_cache_get( str ) );
  str_comma( sz );
  str_pad( sz, 14 );
  str = sz + " " + str;

  str = str_dot_reduce( str, con_max_x()-1 );
  
  say1( str, cINFO );
  say2( "         Help: R Rebuild, S Incremental search, Z Recalc directory size", cINFO );
  show_pos( scroll.pos()+1, scroll.max()+1 );
}
Beispiel #3
0
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;
};
Beispiel #4
0
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 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;
      }
    }
}
Beispiel #5
0
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;
}
Beispiel #6
0
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;
};
Beispiel #7
0
int TextInput( int x, int y, const char *prompt, int maxlen, int fieldlen, VString *strres, void (*handlekey)( int key, VString &s, int &pos ) )
{
  int res = 0;
  int insert = 1;
  VString str = *strres;
  VString tmp;
  int ch;

  ScrollPos scroll;
  scroll.set_min_max( 0, str_len( str ) );
  scroll.set_pagesize( fieldlen );
  scroll.go( str_len(str) );

  int show = 1;
  int firsthit = 1;
  int opage = -1;
  con_cshow();
  while(1)
    {
    if (opage != scroll.page()) show = 1;
    if (show)
      {
      str_copy( tmp, str, scroll.page(), scroll.pagesize() );
      str_pad( tmp, -scroll.pagesize() );
      tmp = " " + tmp + " ";
      if ( scroll.page() > 0 ) str_set_ch( tmp, 0, '<' );
      if ( scroll.page()+scroll.pagesize() < str_len(str) ) str_set_ch( tmp, str_len(tmp)-1, '>' );
      con_out(x, y, tmp, firsthit ? EditStrFH : EditStrBF );
      show = 0;
      opage = scroll.page();
      }
    con_xy( x + scroll.pos() - scroll.page() + 1 , y );
    ch = con_getch();
    if( ch >= 32 && ch <= 255 && ch != KEY_BACKSPACE && str_len(str) < maxlen - 1 )
      {
      if (firsthit)
        {
        str = "";
        scroll.go(0);
        firsthit = 0;
        }
        if (!insert) str_del( str, scroll.pos(), 1 );
        str_ins_ch( str, scroll.pos(), ch );
        scroll.set_min_max( 0, str_len( str ) );
        scroll.go( scroll.pos() );
        scroll.down();
      show = 1;
      };
    if (firsthit)
      {
      show = 1;
      firsthit = 0;
      }

    if( ch == 27 )
      {
      res = 0;
      break;
      } else
    if( ch == 13 )
      {
      *strres = str;
      res = 1;
      break;
      } else
    if( ch == KEY_CTRL_U )
      {
      scroll.go(0);
      str = "";
      show = 1;
      } else
    if( (ch == KEY_BACKSPACE || ch == 8 ) && (scroll.pos() > 0) )
      {
      scroll.up();
      str_del( str, scroll.pos(), 1 );
      show = 1;
      } else
    if ( ch == KEY_IC    ) insert = !insert; else
    if ( ch == KEY_LEFT  ) scroll.up(); else
    if ( ch == KEY_RIGHT ) scroll.down(); else
    /*
    if ( ch == KEY_PPAGE ) scroll.ppage(); else
    if ( ch == KEY_NPAGE ) scroll.npage(); else
    */
    if ( ch == KEY_HOME || ch == KEY_CTRL_A ) scroll.go(0); else
    if ( ch == KEY_END  || ch == KEY_CTRL_E ) scroll.go(str_len(str)); else
    if ( ( ch == KEY_DC || ch == KEY_CTRL_D ) && scroll.pos() < str_len(str) )
      {
      str_del( str, scroll.pos(), 1 );
      show = 1;
      } else
    if ( handlekey )
      {
      int npos = scroll.pos();
      handlekey( ch, str, npos );
      scroll.set_min_max( 0, str_len( str ) );
      scroll.go( scroll.pos() );
      if (scroll.pos() != npos) scroll.go( npos );
      show = 1;
      }

    scroll.set_min_max( 0, str_len( str ) );
    scroll.go( scroll.pos() );
    }
  con_chide();
  return res;
}