Ejemplo n.º 1
0
/*
this function displays the current
history entry
*/
void _el_display_history()
{
  int line_len;
  int h_len;
  
  
  _el_set_cursor(-rl_point);
  if ((!(_el_hs.entries)) || (!_el_mb2w
    (_el_hs.entries[_el_hs.offset]->line, &_el_wide))) {
    return;
  }
  h_len = (int)wcslen(_el_wide);
  line_len = (int)wcslen(_el_line_buffer);
  if (h_len > (_EL_BUF_LEN - 1)) {
    h_len = _EL_BUF_LEN - 1;
    _el_wide[_EL_BUF_LEN - 1] = '\0';
  }
  wcscpy_s(_el_line_buffer, _el_line_buffer_size, _el_wide);
  wcscpy_s(_el_print, _el_line_buffer_size, _el_wide);
  wcscpy_s(_el_line_buffer, _el_line_buffer_size, _el_wide);
  rl_point = (int)h_len;
  if (h_len < line_len) {
    _el_add_char(_el_print, _T(' '), line_len - h_len);
  }
  _el_print_string(_el_print);
  _el_set_cursor(h_len);
}
Ejemplo n.º 2
0
/*
delete character(s) on the command line
*/
int _el_delete_char(UINT32 vk, int n)
{
  int c;
  int line_len;
  int eff_n;
  
  
  line_len = (int)wcslen(_el_line_buffer);
  eff_n = n;
  switch (vk) {
    case VK_DELETE:
    /*
    the character in correspondence
    of the cursor is to be deleted;
    check that we are not going to delete
    more characters than those which exist
    between the logical cursor position
    and the end of line
    */
    if ((line_len - rl_point) < n) {
      eff_n = line_len - rl_point;
    }

    break;
    
    case VK_BACK:
    /*
    the character before
    the cursor is to be deleted
    check that we are not going to delete
    more characters than those which exist
    between the logical cursor position
    and the beginning of line
    */
    if ((rl_point - n) >= 0) {
      rl_point -= n;
    }
    else {
      eff_n = rl_point;
      rl_point = 0;
    }
    /*
    with backspace we need to reposition
    the cursor as well
    */
    if (_el_set_cursor(-eff_n)) {
      return -1;
    }
    break;
    
    default:
    return -1;
  }
  c = (int)wcslen(&_el_line_buffer[rl_point]) + 1;
  /*
  cut out deleted characters
  */
  memmove(&_el_line_buffer[rl_point],
    &_el_line_buffer[rl_point + eff_n],
    (c - eff_n) * sizeof(wchar_t));
  /*
  copy the characters from the current cursor
  position to end of line in a string
  */
  memcpy(_el_print, &_el_line_buffer[rl_point],
    (c - eff_n) * sizeof(wchar_t));
  _el_print[c - eff_n] = '\0';
  /*
  add spaces to the string to be printed
  to clear out "tails" from the command line
  */
  _el_add_char(_el_print, _T(' '), n);
  if (!_el_w2mb(_el_line_buffer, &rl_line_buffer)) {
    return -1;
  }
  
  /*
  print out and goodbye
  */
  return _el_print_string(_el_print);
}