示例#1
0
void vfu_draw( int n )
{
  VFU_CHECK_LIST_POS( n );
  if ( n < FLP || n > FLP + PS )
    return; /* we are out of screen -- don't draw */

  TF* fi = files_list[n];

  int c = fi->color(); /* color to be used */
  VString view = fi->view();
  if ( fi->sel )
    {
    str_set_ch( view, sel_mark_pos, '#' );
    c = CONCOLOR(cBLACK,cWHITE);
    }
  if ( n == FLI )
    {
    str_set_ch( view, tag_mark_pos  , TAGMARKS[opt.tag_mark_type][0] );
    str_set_ch( view, tag_mark_pos+1, TAGMARKS[opt.tag_mark_type][1] );
    c += cBOLD;
    /* this is a hack, can be removed w/o warning :) -- more visibility */
    if ( c == 120 ) c = cTAG; // 116; // 123; // 63; // 123
    }
  con_out( 1, n - FLP + 4, view, c );
  //  con_ce( c );
}
示例#2
0
void tree_fix()
{
  int z;
  for( z = dir_tree.count() - 1; z >= 0; z-- )
    {
    VString s1 = dir_tree[z];
    VString s2;
    if (z < dir_tree.count() - 1)
      s2 = dir_tree[z+1];
    else
      s2 = "";
    int i = -1;
    int n = str_count( s1, "/" );
    int p = 0;
    while(n > 2)
      {
      i = str_find( s1, '/', i+1 );
      int q = 0;
      if ( str_len( s2 ) > i )
        q = s1[i] != s2[i];
      if ( q || ( str_count(s2,"/",i+1) < 2))
        {
          p = 1;
          str_set_ch(s1, i, '\\');
        }
      n--;
      }
    if ( p )
      dir_tree.set( z, s1 );
    }
}
示例#3
0
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 );
    }
}
示例#4
0
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;
} 
示例#5
0
文件: form_in.cpp 项目: bbonev/vslib
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;
}