示例#1
0
static void draw_error(char *cur, char *msg) {
  int width = wincols-5;
  nccreate(7, width, "Error!");

  attron(A_BOLD);
  ncaddstr(2, 2, "Error:");
  attroff(A_BOLD);

  ncprint(2, 9, "could not open %s", cropstr(cur, width-26));
  ncprint(3, 4, "%s", cropstr(msg, width-8));
  ncaddstr(5, width-30, "press any key to continue...");
}
示例#2
0
文件: browser.c 项目: drwebb/ncdu
static void browse_draw_info(struct dir *dr) {
  struct dir *t;
  int i;

  nccreate(11, 60, "Item info");

  if(dr->hlnk) {
    if(info_page == 0)
      attron(A_REVERSE);
    ncaddstr(0, 41, "1:Info");
    attroff(A_REVERSE);
    if(info_page == 1)
      attron(A_REVERSE);
    ncaddstr(0, 50, "2:Links");
    attroff(A_REVERSE);
  }

  switch(info_page) {
  case 0:
    attron(A_BOLD);
    ncaddstr(2, 3, "Name:");
    ncaddstr(3, 3, "Path:");
    ncaddstr(4, 3, "Type:");
    ncaddstr(6, 3, "   Disk usage:");
    ncaddstr(7, 3, "Apparent size:");
    attroff(A_BOLD);

    ncaddstr(2,  9, cropstr(dr->name, 49));
    ncaddstr(3,  9, cropstr(getpath(dr->parent), 49));
    ncaddstr(4,  9, dr->flags & FF_DIR ? "Directory"
        : dr->flags & FF_FILE ? "File" : "Other (link, device, socket, ..)");
    ncprint(6, 18, "%s (%s B)", formatsize(dr->size),  fullsize(dr->size));
    ncprint(7, 18, "%s (%s B)", formatsize(dr->asize), fullsize(dr->asize));
    break;

  case 1:
    for(i=0,t=dr->hlnk; t!=dr; t=t->hlnk,i++) {
      if(info_start > i)
        continue;
      if(i-info_start > 5)
        break;
      ncaddstr(2+i-info_start, 3, cropstr(getpath(t), 54));
    }
    if(t!=dr)
      ncaddstr(8, 25, "-- more --");
    break;
  }

  ncaddstr(9, 32, "Press i to hide this window");
}
示例#3
0
文件: browser.c 项目: drwebb/ncdu
void browse_draw() {
  struct dir *t;
  char fmtsize[9], *tmp;
  int selected, i;

  erase();
  t = dirlist_get(0);

  /* top line - basic info */
  attron(A_REVERSE);
  mvhline(0, 0, ' ', wincols);
  mvhline(winrows-1, 0, ' ', wincols);
  mvprintw(0,0,"%s %s ~ Use the arrow keys to navigate, press ? for help", PACKAGE_NAME, PACKAGE_VERSION);
  if(read_only)
    mvaddstr(0, wincols-11, "[read-only]");
  attroff(A_REVERSE);

  /* second line - the path */
  mvhline(1, 0, '-', wincols);
  if(t) {
    mvaddch(1, 3, ' ');
    tmp = getpath(t->parent);
    mvaddstr(1, 4, cropstr(tmp, wincols-8));
    mvaddch(1, 4+((int)strlen(tmp) > wincols-8 ? wincols-8 : (int)strlen(tmp)), ' ');
  }

  /* bottom line - stats */
  attron(A_REVERSE);
  if(t) {
    strcpy(fmtsize, formatsize(t->parent->size));
    mvprintw(winrows-1, 0, " Total disk usage: %s  Apparent size: %s  Items: %d",
      fmtsize, formatsize(t->parent->asize), t->parent->items);
  } else
    mvaddstr(winrows-1, 0, " No items to display.");
  attroff(A_REVERSE);

  /* nothing to display? stop here. */
  if(!t)
    return;

  /* get start position */
  t = dirlist_top(0);

  /* print the list to the screen */
  for(i=0; t && i<winrows-3; t=dirlist_next(t),i++) {
    browse_draw_item(t, 2+i);
    /* save the selected row number for later */
    if(t->flags & FF_BSEL)
      selected = i;
  }

  /* draw information window */
  t = dirlist_get(0);
  if(info_show && t != dirlist_parent)
    browse_draw_info(t);

  /* move cursor to selected row for accessibility */
  move(selected+2, 0);
}
示例#4
0
static void draw_progress() {
  static const char scantext[] = "Scanning...";
  static const char loadtext[] = "Loading...";
  static size_t anpos = 0;
  const char *antext = dir_import_active ? loadtext : scantext;
  char ani[16] = {};
  size_t i;
  int width = wincols-5;

  nccreate(10, width, antext);

  ncprint(2, 2, "Total items: %-8d", dir_output.items);
  if(dir_output.size)
    ncprint(2, 23, "size: %s", formatsize(dir_output.size));
  ncprint(3, 2, "Current item: %s", cropstr(dir_curpath, width-18));
  if (confirm_quit_while_scanning_stage_1_passed)
    ncaddstr(8, width-26, "Press y to confirm abort");
  else
    ncaddstr(8, width-18, "Press q to abort");

  /* show warning if we couldn't open a dir */
  if(lasterr) {
     attron(A_BOLD);
     ncaddstr(5, 2, "Warning:");
     attroff(A_BOLD);
     ncprint(5, 11, "error scanning %-32s", cropstr(lasterr, width-28));
     ncaddstr(6, 3, "some directory sizes may not be correct");
  }

  /* animation - but only if the screen refreshes more than or once every second */
  if(update_delay <= 1000) {
    if(++anpos == strlen(antext)*2)
       anpos = 0;
    memset(ani, ' ', strlen(antext));
    if(anpos < strlen(antext))
      for(i=0; i<=anpos; i++)
        ani[i] = antext[i];
    else
      for(i=strlen(antext)-1; i>anpos-strlen(antext); i--)
        ani[i] = antext[i];
  } else
    strcpy(ani, antext);
  ncaddstr(8, 3, ani);
}
示例#5
0
void dir_draw() {
  switch(dir_ui) {
  case 0:
    if(dir_fatalerr)
      fprintf(stderr, "%s.\n", dir_fatalerr);
    break;
  case 1:
    if(dir_fatalerr)
      fprintf(stderr, "\r%s.\n", dir_fatalerr);
    else if(dir_output.size)
      fprintf(stderr, "\r%-55s %8d files /%s",
        cropstr(dir_curpath, 55), dir_output.items, formatsize(dir_output.size));
    else
      fprintf(stderr, "\r%-65s %8d files", cropstr(dir_curpath, 65), dir_output.items);
    break;
  case 2:
    browse_draw();
    if(dir_fatalerr)
      draw_error(dir_curpath, dir_fatalerr);
    else
      draw_progress();
    break;
  }
}
示例#6
0
文件: browser.c 项目: drwebb/ncdu
static void browse_draw_item(struct dir *n, int row) {
  char ct, dt, *size, gr[11];
  int i, o;
  float pc;

  if(n->flags & FF_BSEL)
    attron(A_REVERSE);

  /* reference to parent dir has a different format */
  if(n == dirlist_parent) {
    mvhline(row, 0, ' ', wincols);
    o = graph == 0 ? 12 :
        graph == 1 ? 24 :
        graph == 2 ? 20 :
                     31 ;
    mvaddstr(row, o, "/..");
    if(n->flags & FF_BSEL)
      attroff(A_REVERSE);
    return;
  }

  /* determine indication character */
  ct =  n->flags & FF_EXL ? '<' :
        n->flags & FF_ERR ? '!' :
       n->flags & FF_SERR ? '.' :
      n->flags & FF_OTHFS ? '>' :
      n->flags & FF_HLNKC ? 'H' :
     !(n->flags & FF_FILE
    || n->flags & FF_DIR) ? '@' :
        n->flags & FF_DIR
        && n->sub == NULL ? 'e' :
                            ' ' ;
  dt = n->flags & FF_DIR ? '/' : ' ';
  size = formatsize(show_as ? n->asize : n->size);

  /* create graph (if necessary) */
  if(graph) {
    /* percentage */
    if((pc = (float)(show_as ? n->parent->asize : n->parent->size)) < 1)
      pc = 1.0f;
    pc = ((float)(show_as ? n->asize : n->size) / pc) * 100.0f;
    /* graph */
    if(graph == 1 || graph == 3) {
      o = (int)(10.0f*(float)(show_as ? n->asize : n->size) / (float)(show_as ? dirlist_maxa : dirlist_maxs));
      for(i=0; i<10; i++)
        gr[i] = i < o ? '#' : ' ';
      gr[10] = '\0';
    }
  }

  /* format and add item to the list */
  switch(graph) {
    case 0: mvprintw(row, 0, "%c %8s  %c%-*s",               ct, size,         dt, wincols-13, cropstr(n->name, wincols-13)); break;
    case 1: mvprintw(row, 0, "%c %8s [%10s] %c%-*s",         ct, size,     gr, dt, wincols-25, cropstr(n->name, wincols-25)); break;
    case 2: mvprintw(row, 0, "%c %8s [%5.1f%%] %c%-*s",      ct, size, pc,     dt, wincols-21, cropstr(n->name, wincols-21)); break;
    case 3: mvprintw(row, 0, "%c %8s [%5.1f%% %10s] %c%-*s", ct, size, pc, gr, dt, wincols-32, cropstr(n->name, wincols-32));
  }

  if(n->flags & FF_BSEL)
    attroff(A_REVERSE);
}