Example #1
0
void ex_cmdinvert()
{
  int st = compl_root_pos();
  int ed = st;
  while (ex.line[ed++] == ' ');

  //FIXME: find compl_root_pos for curs position
  Token *cur = cmdline_tokbtwn(&ex.cmd, st, ed);
  Token *tok = (Token*)utarray_next(ex.cmd.tokens, cur);
  char *symb = token_val(tok, VAR_STRING);
  if (!cur)
    return;

  if (symb && *symb == '!') {
    str_ins(ex.line, "", tok->start, 1);
    ex.curofs--, ex.curpos--;
  }
  else {
    str_ins(ex.line, "!", cur->end, 0);
    ex.curofs++, ex.curpos++;
  }

  int old = ex.curofs;
  ex.curofs = 0;
  menu_rebuild(ex.menu);
  ex.curofs = old;
}
Example #2
0
static void ex_killword()
{
  if (ex.curofs < 1)
    return;

  /* strip trailing whitespace */
  if (ex_cmd_curch() == ' ') {
    int len = 0;
    while (ex.line[ex.curofs - (len + 1)] == ' ' && ex.curofs > 1)
      len++;

    str_ins(ex.line, "", ex.curofs - len, len);
    ex.curofs -= len;
    ex.curpos -= len;
    return ex_killchar();
  }

  /* remove word from line */
  int pos = rev_strchr_pos(ex.line, ex.curofs, TOKENCHARS);
  if (strchr(TOKENCHARS, ex.line[pos]) && ex.curofs - pos > 1)
    pos++;

  int len = ex.curofs - pos;
  str_ins(ex.line, "", pos, len);
  ex.curofs = pos;

  /* find cursor position */
  char buf[pos+1];
  strncpy(buf, ex.line, ex.curofs);
  buf[ex.curofs] = '\0';
  ex.curpos = cell_len(buf);

  ex_killchar();
}
Example #3
0
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_ */
}
Example #4
0
static void ex_bckspc()
{
  log_msg("EXCMD", "bkspc");

  if (ex.curofs > 0) {
    char *buf = linechar(ex.curofs, BACKWARD);
    int len = strlen(buf);
    int clen = cell_len(buf);

    str_ins(ex.line, "", ex.curofs - len, len);

    ex.curofs -= len;
    ex.curpos -= clen;
  }
  ex_killchar();
  log_err("MENU", "##%d %d", ex.curpos, compl_cur_pos());
}
Example #5
0
static void ex_tab(void *none, Keyarg *arg)
{
  log_msg("EXCMD", "TAB");
  if (ex.cmd.cmds && ex_cmd_state() & EX_EXEC)
    return;

  char *line = menu_next(ex.menu, arg->arg);
  if (!line)
    return;

  char *instr = escape_shell(line);
  int len = strlen(instr);
  int slen = strlen(ex.line);
  int st = compl_cur_pos() - 1;
  int ed = 0;

  if (st == -1)
    st = 0;
  if (ex.line[st] == ' ')
    st++;

  bool quote = false;
  char ch;
  while ((ch = ex.line[st+ed])) {
    if ((ch == '|' || ch == ' ') && !quote)
      break;
    if (ch == '\'' || ch == '\"')
      quote = !quote;
    ed++;
  }

  if (slen + len >= ex.maxpos)
    ex.line = realloc(ex.line, ex.maxpos = (2*ex.maxpos)+len);

  str_ins(ex.line, instr, st, ed);
  ex.curofs = st + len;
  ex.curpos = st + cell_len(instr);
  ex.state = EX_CYCLE;

  free(line);
  free(instr);
}
Example #6
0
static void ex_getchar(Keyarg *ca)
{
  if (IS_SPECIAL(ca->key))
    return;

  ex.state &= ~(EX_FRESH);

  char instr[7] = {0,0};
  if (!ca->utf8)
    instr[0] = ca->key;
  else
    strcpy(instr, ca->utf8);

  int len = strlen(instr);
  if (strlen(ex.line) + len >= ex.maxpos)
    ex.line = realloc(ex.line, ex.maxpos = (2*ex.maxpos)+len);

  str_ins(ex.line, instr, ex.curofs, 0);

  ex.curpos += cell_len(instr);
  ex.curofs += len;
}