Changes in / [8b293ea:1c01cdf7]


Ignore:
Files:
5 edited

Legend:

Unmodified
Added
Removed
  • commands.c

    rd427f08 r7c80ea42  
    26322632  ptr = skiptokens(buff, 1);
    26332633  hist = owl_global_get_cmd_history(&g);
    2634   owl_history_store(hist, ptr);
    2635   owl_history_reset(hist);
     2634  owl_history_store(hist, ptr, false);
    26362635  /* owl_function_makemsg("History '%s' stored successfully", ptr+1); */
    26372636  return NULL;
     
    26552654
    26562655  hist = owl_global_get_cmd_history(&g);
    2657   owl_history_store(hist, ptr);
    2658   owl_history_reset(hist);
     2656  owl_history_store(hist, ptr, false);
    26592657  return owl_function_command(ptr);
    26602658}
     
    27392737
    27402738  hist = owl_editwin_get_history(e);
    2741   if (hist) {
    2742     owl_history_store(hist, owl_editwin_get_text(e));
    2743     owl_history_reset(hist);
    2744   }
     2739  if (hist)
     2740    owl_history_store(hist, owl_editwin_get_text(e), false);
    27452741
    27462742  owl_global_pop_context(&g);
     
    27552751  if (!hist)
    27562752    return;
    2757   if (!owl_history_is_touched(hist)) {
    2758     owl_history_store(hist, owl_editwin_get_text(e));
    2759     owl_history_set_partial(hist);
    2760   }
     2753  if (!owl_history_is_touched(hist))
     2754    owl_history_store(hist, owl_editwin_get_text(e), true);
    27612755  ptr=owl_history_get_prev(hist);
    27622756  if (ptr) {
     
    27962790  owl_history *hist=owl_editwin_get_history(e);
    27972791
    2798   if (hist) {
    2799     owl_history_store(hist, owl_editwin_get_text(e));
    2800     owl_history_reset(hist);
    2801   }
     2792  if (hist)
     2793    owl_history_store(hist, owl_editwin_get_text(e), false);
    28022794
    28032795  /* Take a reference to the editwin, so that it survives the pop
  • functions.c

    r8b293ea r7c80ea42  
    18411841    if (enter) {
    18421842      owl_history *hist = owl_global_get_cmd_history(&g);
    1843       owl_history_store(hist, buff);
    1844       owl_history_reset(hist);
     1843      owl_history_store(hist, buff, false);
    18451844      owl_function_command_norv(buff);
    18461845    } else {
  • global.c

    rd427f08 rd427f08  
    6565  owl_history_init(&(g->msghist));
    6666  owl_history_init(&(g->cmdhist));
    67   owl_history_set_norepeats(&(g->cmdhist));
    6867  g->nextmsgid=0;
    6968
  • history.c

    rd4927a7 r2bc6bb16  
    33void owl_history_init(owl_history *h)
    44{
    5   owl_list_create(&(h->hist));
    6   h->cur=0;                     /* current position in history */
    7   h->touched=0;                 /* whether we've gone into history */
    8   h->partial=0;                 /* is the 0th element is partially composed? */
    9   h->repeats=1;                 /* by default we'll allow repeat entries */
    10 }
    11 
    12 void owl_history_set_norepeats(owl_history *h)
    13 {
    14   h->repeats=0;
     5  g_queue_init(&h->hist);
     6  h->cur = h->hist.tail;        /* current position in history */
     7  h->partial = false;           /* is the 0th element is partially composed? */
    158}
    169
    1710const char *owl_history_get_prev(owl_history *h)
    1811{
     12  if (!h) return NULL;
    1913
    20   if (!h) return NULL;
    21   h->touched=1;
     14  if (h->cur == NULL || g_list_previous(h->cur) == NULL) return NULL;
    2215
    23   if (owl_list_get_size(&(h->hist))==0) return(NULL);
    24 
    25   if (h->cur == owl_list_get_size(&(h->hist))-1) {
    26     return(NULL);
    27   }
    28 
    29   h->cur++;
    30 
    31   return(owl_list_get_element(&(h->hist), h->cur));
     16  h->cur = g_list_previous(h->cur);
     17  return h->cur->data;
    3218}
    3319
     
    3521{
    3622  if (!h) return NULL;
    37   if (owl_list_get_size(&(h->hist))==0) return(NULL);
    38   if (h->cur==0) {
    39     return(NULL);
    40   }
    4123
    42   h->cur--;
    43   return(owl_list_get_element(&(h->hist), h->cur));
     24  if (h->cur == NULL || g_list_next(h->cur) == NULL) return NULL;
     25
     26  h->cur = g_list_next(h->cur);
     27  return h->cur->data;
    4428}
    4529
    46 void owl_history_store(owl_history *h, const char *line)
     30void owl_history_store(owl_history *h, const char *line, bool partial)
    4731{
    48   int size;
     32  if (!h) return;
    4933
    50   if (!h) return;
    51   size=owl_list_get_size(&(h->hist));
     34  owl_history_reset(h);
    5235
    53   /* if partial is set, remove the first entry first */
    54   if (h->partial) {
    55     g_free(owl_list_get_element(&(h->hist), 0));
    56     owl_list_remove_element(&(h->hist), 0);
    57   }
    58 
    59   /* if repeats are disallowed, check if the line is the same as the last */
    60   if (owl_list_get_size(&(h->hist))>0) {
    61     if (!strcmp(line, owl_list_get_element(&(h->hist), 0))) return;
    62   }
     36  /* check if the line is the same as the last */
     37  if (!partial && !g_queue_is_empty(&h->hist) &&
     38      strcmp(line, g_queue_peek_tail(&h->hist)) == 0)
     39    return;
    6340
    6441  /* if we've reached the max history size, pop off the last element */
    65   if (size>OWL_HISTORYSIZE) {
    66     g_free(owl_list_get_element(&(h->hist), size-1));
    67     owl_list_remove_element(&(h->hist), size-1);
    68   }
     42  if (g_queue_get_length(&h->hist) > OWL_HISTORYSIZE)
     43    g_free(g_queue_pop_head(&h->hist));
    6944
    7045  /* add the new line */
    71   owl_list_prepend_element(&(h->hist), g_strdup(line));
    72 }
    73 
    74 void owl_history_set_partial(owl_history *h)
    75 {
    76   if (!h) return;
    77   h->partial=1;
     46  g_queue_push_tail(&h->hist, g_strdup(line));
     47  h->partial = partial;
     48  h->cur = h->hist.tail;
    7849}
    7950
     
    8152{
    8253  if (!h) return;
    83   h->cur=0;
    84   h->touched=0;
    85   h->partial=0;
     54
     55  /* if partial is set, remove the first entry first */
     56  if (h->partial) {
     57    g_free(g_queue_pop_tail(&h->hist));
     58    h->partial = false;
     59  }
     60
     61  h->cur = h->hist.tail;
    8662}
    8763
     
    8965{
    9066  if (!h) return(0);
    91   if (h->touched) return(1);
    92   return(0);
     67  return h->cur != NULL && g_list_next(h->cur) != NULL;
    9368}
  • owl.h

    rd427f08 r2bc6bb16  
    455455
    456456typedef struct _owl_history {
    457   owl_list hist;
    458   int cur;
    459   int touched;
    460   int partial;
    461   int repeats;
     457  GQueue hist;
     458  GList *cur;
     459  bool partial;
    462460} owl_history;
    463461
Note: See TracChangeset for help on using the changeset viewer.