Example #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...");
}
Example #2
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);
}
Example #3
0
File: help.c Project: lagsalot/ncdu
void help_draw() {
  int i, line;

  browse_draw();

  nccreate(15, 60, "ncdu help");
  ncaddstr(13, 38, "Press q to continue");

  if(page == 1)
    attron(A_REVERSE);
  ncaddstr(0, 30, "1:Keys");
  attroff(A_REVERSE);
  if(page == 2)
    attron(A_REVERSE);
  ncaddstr(0, 39, "2:Format");
  attroff(A_REVERSE);
  if(page == 3)
    attron(A_REVERSE);
  ncaddstr(0, 50, "3:About");
  attroff(A_REVERSE);

  switch(page) {
    case 1:
      line = 1;
      for(i=start*2; i<start*2+20; i+=2) {
        attron(A_BOLD);
        ncaddstr(++line, 13-strlen(keys[i]), keys[i]);
        attroff(A_BOLD);
        ncaddstr(line, 15, keys[i+1]);
      }
      if(start != KEYS-10)
        ncaddstr(12, 25, "-- more --");
      break;
    case 2:
      attron(A_BOLD);
      ncaddstr(2, 3, "X  [size] [graph] [file or directory]");
      attroff(A_BOLD);
      ncaddstr(3, 4, "The X is only present in the following cases:");
      attron(A_BOLD);
      ncaddch( 5, 4, '!');
      ncaddch( 6, 4, '.');
      ncaddch( 7, 4, '<');
      ncaddch( 8, 4, '>');
      ncaddch( 9, 4, '@');
      ncaddch(10, 4, 'H');
      ncaddch(11, 4, 'e');
      attroff(A_BOLD);
      ncaddstr( 5, 7, "An error occured while reading this directory");
      ncaddstr( 6, 7, "An error occured while reading a subdirectory");
      ncaddstr( 7, 7, "File or directory is excluded from the statistics");
      ncaddstr( 8, 7, "Directory was on an other filesystem");
      ncaddstr( 9, 7, "This is not a file nor a dir (symlink, socket, ...)");
      ncaddstr(10, 7, "Same file was already counted (hard link)");
      ncaddstr(11, 7, "Empty directory");
      break;
    case 3:
      /* Indeed, too much spare time */
      attron(A_REVERSE);
#define x 12
#define y 3
      /* N */
      ncaddstr(y+0, x+0, "      ");
      ncaddstr(y+1, x+0, "  ");
      ncaddstr(y+2, x+0, "  ");
      ncaddstr(y+3, x+0, "  ");
      ncaddstr(y+4, x+0, "  ");
      ncaddstr(y+1, x+4, "  ");
      ncaddstr(y+2, x+4, "  ");
      ncaddstr(y+3, x+4, "  ");
      ncaddstr(y+4, x+4, "  ");
      /* C */
      ncaddstr(y+0, x+8, "     ");
      ncaddstr(y+1, x+8, "  ");
      ncaddstr(y+2, x+8, "  ");
      ncaddstr(y+3, x+8, "  ");
      ncaddstr(y+4, x+8, "     ");
      /* D */
      ncaddstr(y+0, x+19, "  ");
      ncaddstr(y+1, x+19, "  ");
      ncaddstr(y+2, x+15, "      ");
      ncaddstr(y+3, x+15, "  ");
      ncaddstr(y+3, x+19, "  ");
      ncaddstr(y+4, x+15, "      ");
      /* U */
      ncaddstr(y+0, x+23, "  ");
      ncaddstr(y+1, x+23, "  ");
      ncaddstr(y+2, x+23, "  ");
      ncaddstr(y+3, x+23, "  ");
      ncaddstr(y+0, x+27, "  ");
      ncaddstr(y+1, x+27, "  ");
      ncaddstr(y+2, x+27, "  ");
      ncaddstr(y+3, x+27, "  ");
      ncaddstr(y+4, x+23, "      ");
      attroff(A_REVERSE);
      ncaddstr(y+0, x+30, "NCurses");
      ncaddstr(y+1, x+30, "Disk");
      ncaddstr(y+2, x+30, "Usage");
      ncprint( y+4, x+30, "%s", PACKAGE_VERSION);
      ncaddstr( 9,  7, "Written by Yoran Heling <*****@*****.**>");
      ncaddstr(10, 16, "http://dev.yorhel.nl/ncdu/");
      break;
  }
}
Example #4
0
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");
}
Example #5
0
File: quit.c Project: gitkaste/ncdu
void quit_draw() {
  browse_draw();

  nccreate(4,30, "ncdu confirm quit");
  ncaddstr(2,2, "Really quit? (y/N)");
}
Example #6
0
void browse_draw() {
  struct dir *t;
  char fmtsize[9], *tmp;
  int selected = 0, 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(dir_import_active)
    mvaddstr(0, wincols-10, "[imported]");
  else 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 message window */
  if(message) {
    nccreate(6, 60, "Message");
    ncaddstr(2, 2, message);
    ncaddstr(4, 34, "Press any key to continue");
  }

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

  /* move cursor to selected row for accessibility */
  move(selected+2, 0);
}