Show
Ignore:
Timestamp:
02/10/08 16:20:40 (6 years ago)
Author:
Theo Schlossnagle <jesus@omniti.com>
git-committer:
Theo Schlossnagle <jesus@omniti.com> 1202660440 +0000
git-parent:

[efa89659d10da4930e2af74b0d0a6ca18c4c74b2]

git-author:
Theo Schlossnagle <jesus@omniti.com> 1202660440 +0000
Message:

userdata for states, track a path and prompt

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • src/noit_conf.c

    r7192210 r1fe89bb  
    274274} 
    275275 
    276  
     276static void 
     277conf_t_userdata_free(void *data) { 
     278  noit_conf_t_userdata_t *info = data; 
     279  if(info) { 
     280    if(info->path) free(info->path); 
     281    free(info); 
     282  } 
     283
    277284static int 
    278285noit_console_state_conf_terminal(noit_console_closure_t ncct, 
    279286                                 int argc, char **argv, void *state) { 
     287  noit_conf_t_userdata_t *info; 
    280288  if(argc) { 
    281289    nc_printf(ncct, "extra arguments not expected.\n"); 
    282290    return -1; 
    283291  } 
     292  info = calloc(1, sizeof(*info)); 
     293  info->path = strdup("/"); 
     294  noit_console_userdata_set(ncct, NOIT_CONF_T_USERDATA, info, 
     295                            conf_t_userdata_free); 
    284296  noit_console_state_push_state(ncct, state); 
    285297  noit_console_state_init(ncct); 
     
    289301static char * 
    290302conf_t_prompt(EditLine *el) { 
     303  noit_console_closure_t ncct; 
     304  noit_conf_t_userdata_t *info; 
    291305  static char *tl = "noit(conf)# "; 
    292   return tl; 
     306  static char *pfmt = "noit(conf:%s%s)# "; 
     307  int path_len, max_len; 
     308 
     309  el_get(el, EL_USERDATA, (void *)&ncct); 
     310  if(!ncct) return tl; 
     311  info = noit_console_userdata_get(ncct, NOIT_CONF_T_USERDATA); 
     312  if(!info) return tl; 
     313 
     314  path_len = strlen(info->path); 
     315  max_len = strlen(pfmt) - 4 /* %s%s */ - 1 /* \0 */; 
     316  if(path_len > max_len) 
     317    snprintf(info->prompt, sizeof(info->prompt), 
     318             pfmt, "...", info->path + max_len - 3 /* ... */); 
     319  else 
     320    snprintf(info->prompt, sizeof(info->prompt), pfmt, "", info->path); 
     321  return info->prompt; 
    293322} 
    294323