Commit b427c72613ceb9097f68ab69a0bc152c7199615b

Authored by ths
1 parent 9ff6755b

Improve completion in monitor, by Pascal Terjan.


git-svn-id: svn://svn.savannah.nongnu.org/qemu/trunk@3233 c046a42c-6fe2-441c-8c8c-71466251a162
Showing 1 changed file with 16 additions and 1 deletions
readline.c
... ... @@ -300,7 +300,7 @@ void add_completion(const char *str)
300 300  
301 301 static void term_completion(void)
302 302 {
303   - int len, i, j, max_width, nb_cols;
  303 + int len, i, j, max_width, nb_cols, max_prefix;
304 304 char *cmdline;
305 305  
306 306 nb_completions = 0;
... ... @@ -327,11 +327,26 @@ static void term_completion(void)
327 327 } else {
328 328 term_printf("\n");
329 329 max_width = 0;
  330 + max_prefix = 0;
330 331 for(i = 0; i < nb_completions; i++) {
331 332 len = strlen(completions[i]);
  333 + if (i==0) {
  334 + max_prefix = len;
  335 + } else {
  336 + if (len < max_prefix)
  337 + max_prefix = len;
  338 + for(j=0; j<max_prefix; j++) {
  339 + if (completions[i][j] != completions[0][j])
  340 + max_prefix = j;
  341 + }
  342 + }
332 343 if (len > max_width)
333 344 max_width = len;
334 345 }
  346 + if (max_prefix > 0)
  347 + for(i = completion_index; i < max_prefix; i++) {
  348 + term_insert_char(completions[0][i]);
  349 + }
335 350 max_width += 2;
336 351 if (max_width < 10)
337 352 max_width = 10;
... ...