Esempio n. 1
0
File: test.c Progetto: clibs/term
int
main(int argc, char **argv){
  term_bold();
  term_underline();
  printf("bold and underlined\n");

  term_reset();
  printf("reset\n");

  term_color("green");
  printf("ok\n");

  term_bold();
  term_color("red");
  term_background("red");
  printf("fail");
  term_reset();

  term_move_to(50, 10);
  printf("hey");
  term_move_by(1, 1);
  printf("there");
  term_move_to(0, 15);

  int w = 0, h = 0;
  term_size(&w, &h);
  printf("%dx%d\n", w, h);

  return 0;
}
Esempio n. 2
0
/* render all windows */
static void
render_screens (void)
{
  int row, col, chg = 0;

  getmaxyx (stdscr, row, col);
  term_size (main_win);

  generate_time ();
  chg = logger->process - logger->offset;

  draw_header (stdscr, "", "%s", row - 1, 0, col, 0, 0);
  wattron (stdscr, COLOR_PAIR (COL_WHITE));
  mvaddstr (row - 1, 1, "[F1]Help [O]pen detail view");
  mvprintw (row - 1, 30, "%d - %s", chg, asctime (now_tm));
  mvaddstr (row - 1, col - 21, "[Q]uit GoAccess");
  mvprintw (row - 1, col - 5, "%s", GO_VERSION);
  wattroff (stdscr, COLOR_PAIR (COL_WHITE));
  refresh ();

  /* call general stats header */
  display_general (header_win, conf.ifile, logger);
  wrefresh (header_win);

  /* display active label based on current module */
  update_active_module (header_win, gscroll.current);

  display_content (main_win, logger, dash, &gscroll);
}
Esempio n. 3
0
/* render all windows */
static void
render_screens (void)
{
  GColors *color = get_color (COLOR_DEFAULT);
  int row, col, chg = 0;

  getmaxyx (stdscr, row, col);
  term_size (main_win);

  generate_time ();
  chg = logger->processed - logger->offset;

  draw_header (stdscr, "", "%s", row - 1, 0, col, color_default);

  wattron (stdscr, color->attr | COLOR_PAIR (color->pair->idx));
  mvaddstr (row - 1, 1, "[F1]Help [Enter] Exp. Panel");
  mvprintw (row - 1, 30, "%d - %s", chg, asctime (now_tm));
  mvaddstr (row - 1, col - 21, "[Q]uit GoAccess");
  mvprintw (row - 1, col - 5, "%s", GO_VERSION);
  wattroff (stdscr, color->attr | COLOR_PAIR (color->pair->idx));

  refresh ();

  /* call general stats header */
  display_general (header_win, conf.ifile, logger);
  wrefresh (header_win);

  /* display active label based on current module */
  update_active_module (header_win, gscroll.current);

  display_content (main_win, logger, dash, &gscroll);
}
Esempio n. 4
0
static void
window_resize (void)
{
  endwin ();
  refresh ();
  werase (header_win);
  werase (main_win);
  werase (stdscr);
  term_size (main_win);
  refresh ();
  render_screens ();
}
void redraw (int w, int h, int mx, int my)
{
  vapi_clear ();

  rulers (w, h);
  instructions (w, h);
  mouse_pos (w, h, mx, my);
  term_size (w, h);

  vapi_moveto (1, 1);
  vapi_refresh ();
}
Esempio n. 6
0
void GuiMainWindow::setupTerminalSize(GuiTerminalWindow *newTerm)
{
    // resize according to config if window is smaller
    if ( !(windowState() & Qt::WindowMaximized) &&
          (tabArea->count()==1) /* only for 1st window */ &&
         ( newTerm->viewport()->width() < newTerm->cfg.width*newTerm->getFontWidth() ||
            newTerm->viewport()->height() < newTerm->cfg.height*newTerm->getFontHeight())) {
        this->resize(newTerm->cfg.width*newTerm->getFontWidth() + width() - newTerm->viewport()->width(),
                     newTerm->cfg.height*newTerm->getFontHeight() + height() - newTerm->viewport()->height());
        term_size(newTerm->term, newTerm->cfg.height, newTerm->cfg.width, newTerm->cfg.savelines);
    }
}
Esempio n. 7
0
static void
perform_tail_follow (uint64_t * size1)
{
  uint64_t size2 = 0;
  char buf[LINE_BUFFER];
  FILE *fp = NULL;

  if (logger->piping)
    return;

  size2 = file_size (conf.ifile);

  /* file hasn't changed */
  if (size2 == *size1)
    return;

  if (!(fp = fopen (conf.ifile, "r")))
    FATAL ("Unable to read log file %s.", strerror (errno));
  if (!fseeko (fp, *size1, SEEK_SET))
    while (fgets (buf, LINE_BUFFER, fp) != NULL)
      parse_log (&logger, buf, -1);
  fclose (fp);

  *size1 = size2;
  pthread_mutex_lock (&gdns_thread.mutex);
  free_holder (&holder);
  pthread_cond_broadcast (&gdns_thread.not_empty);
  pthread_mutex_unlock (&gdns_thread.mutex);

  free_dashboard (dash);
  allocate_holder ();
  allocate_data ();

  term_size (main_win);
  render_screens ();
  usleep (200000);      /* 0.2 seconds */
}
Esempio n. 8
0
static void
get_keys (void)
{
  int search;
  int c, quit = 1, scrll, offset, ok_mouse;
  int *scroll_ptr, *offset_ptr;
  int exp_size = DASH_EXPANDED - DASH_NON_DATA;
  MEVENT event;

  char buf[LINE_BUFFER];
  FILE *fp = NULL;
  unsigned long long size1 = 0, size2 = 0;

  if (!logger->piping)
    size1 = file_size (conf.ifile);
  while (quit) {
    c = wgetch (stdscr);
    switch (c) {
    case 'q':  /* quit */
      if (!scrolling.expanded) {
        quit = 0;
        break;
      }
      collapse_current_module ();
      break;
    case KEY_F (1):
    case '?':
    case 'h':
      load_help_popup (main_win);
      render_screens ();
      break;
    case 49:   /* 1 */
      /* reset expanded module */
      set_module_to (&scrolling, VISITORS);
      break;
    case 50:   /* 2 */
      /* reset expanded module */
      set_module_to (&scrolling, REQUESTS);
      break;
    case 51:   /* 3 */
      /* reset expanded module */
      set_module_to (&scrolling, REQUESTS_STATIC);
      break;
    case 52:   /* 4 */
      /* reset expanded module */
      set_module_to (&scrolling, NOT_FOUND);
      break;
    case 53:   /* 5 */
      /* reset expanded module */
      set_module_to (&scrolling, HOSTS);
      break;
    case 54:   /* 6 */
      /* reset expanded module */
      set_module_to (&scrolling, OS);
      break;
    case 55:   /* 7 */
      /* reset expanded module */
      set_module_to (&scrolling, BROWSERS);
      break;
    case 56:   /* 8 */
      /* reset expanded module */
      set_module_to (&scrolling, REFERRERS);
      break;
    case 57:   /* 9 */
      /* reset expanded module */
      set_module_to (&scrolling, REFERRING_SITES);
      break;
    case 48:   /* 0 */
      /* reset expanded module */
      set_module_to (&scrolling, KEYPHRASES);
      break;
    case 33:   /* Shift+1 */
      /* reset expanded module */
#ifdef HAVE_LIBGEOIP
      set_module_to (&scrolling, GEO_LOCATION);
#else
      set_module_to (&scrolling, STATUS_CODES);
#endif
      break;
#ifdef HAVE_LIBGEOIP
    case 64:   /* Shift+2 */
      /* reset expanded module */
      set_module_to (&scrolling, STATUS_CODES);
      break;
#endif
    case 9:    /* TAB */
      /* reset expanded module */
      collapse_current_module ();
      scrolling.current++;
      if (scrolling.current == TOTAL_MODULES)
        scrolling.current = 0;
      render_screens ();
      break;
    case 353:  /* Shift TAB */
      /* reset expanded module */
      collapse_current_module ();
      if (scrolling.current == 0)
        scrolling.current = TOTAL_MODULES - 1;
      else
        scrolling.current--;
      render_screens ();
      break;
    case 'g':  /* g = top */
      if (!scrolling.expanded)
        scrolling.dash = 0;
      else {
        scrolling.module[scrolling.current].scroll = 0;
        scrolling.module[scrolling.current].offset = 0;
      }
      display_content (main_win, logger, dash, &scrolling);
      break;
    case 'G':  /* G = down */
      if (!scrolling.expanded)
        scrolling.dash = dash->total_alloc - real_size_y;
      else {
        scrll = offset = 0;
        scrll = dash->module[scrolling.current].idx_data - 1;
        if (scrll >= exp_size && scrll >= offset + exp_size)
          offset = scrll < exp_size - 1 ? 0 : scrll - exp_size + 1;
        scrolling.module[scrolling.current].scroll = scrll;
        scrolling.module[scrolling.current].offset = offset;
      }
      display_content (main_win, logger, dash, &scrolling);
      break;
      /* expand dashboard module */
    case KEY_RIGHT:
    case 0x0a:
    case 0x0d:
    case 32:   /* ENTER */
    case 79:   /* o */
    case 111:  /* O */
    case KEY_ENTER:
      if (scrolling.expanded && scrolling.current == HOSTS) {
        /* make sure we have a valid IP */
        int sel = scrolling.module[scrolling.current].scroll;
        if (!invalid_ipaddr (dash->module[HOSTS].data[sel].data))
          load_agent_list (main_win, dash->module[HOSTS].data[sel].data);
        break;
      }
      if (scrolling.expanded)
        break;
      reset_scroll_offsets (&scrolling);
      scrolling.expanded = 1;

      free_holder_by_module (&holder, scrolling.current);
      free_dashboard (dash);
      allocate_holder_by_module (scrolling.current);
      allocate_data ();

      display_content (main_win, logger, dash, &scrolling);
      break;
    case KEY_DOWN:     /* scroll main dashboard */
      if ((scrolling.dash + real_size_y) < (unsigned) dash->total_alloc) {
        scrolling.dash++;
        display_content (main_win, logger, dash, &scrolling);
      }
      break;
    case KEY_MOUSE:    /* handles mouse events */
      ok_mouse = getmouse (&event);
      if (conf.mouse_support && ok_mouse == OK) {
        if (event.bstate & BUTTON1_CLICKED) {
          /* ignore header/footer clicks */
          if (event.y < MAX_HEIGHT_HEADER || event.y == LINES - 1)
            break;

          if (set_module_from_mouse_event (&scrolling, dash, event.y))
            break;
          reset_scroll_offsets (&scrolling);
          scrolling.expanded = 1;

          free_holder_by_module (&holder, scrolling.current);
          free_dashboard (dash);
          allocate_holder_by_module (scrolling.current);
          allocate_data ();

          render_screens ();
        }
      }
      break;
    case 106:  /* j - DOWN expanded module */
      scroll_ptr = &scrolling.module[scrolling.current].scroll;
      offset_ptr = &scrolling.module[scrolling.current].offset;

      if (!scrolling.expanded)
        break;
      if (*scroll_ptr >= dash->module[scrolling.current].idx_data - 1)
        break;
      ++(*scroll_ptr);
      if (*scroll_ptr >= exp_size && *scroll_ptr >= *offset_ptr + exp_size)
        ++(*offset_ptr);
      display_content (main_win, logger, dash, &scrolling);
      break;
      /* scroll up main_win */
    case KEY_UP:
      if (scrolling.dash > 0) {
        scrolling.dash--;
        display_content (main_win, logger, dash, &scrolling);
      }
      break;
    case 2:    /* ^ b - page up */
    case 339:  /* ^ PG UP */
      scroll_ptr = &scrolling.module[scrolling.current].scroll;
      offset_ptr = &scrolling.module[scrolling.current].offset;

      if (!scrolling.expanded)
        break;
      /* decrease scroll and offset by exp_size */
      *scroll_ptr -= exp_size;
      if (*scroll_ptr < 0)
        *scroll_ptr = 0;

      if (*scroll_ptr < *offset_ptr)
        *offset_ptr -= exp_size;
      if (*offset_ptr <= 0)
        *offset_ptr = 0;
      display_content (main_win, logger, dash, &scrolling);
      break;
    case 6:    /* ^ f - page down */
    case 338:  /* ^ PG DOWN */
      scroll_ptr = &scrolling.module[scrolling.current].scroll;
      offset_ptr = &scrolling.module[scrolling.current].offset;

      if (!scrolling.expanded)
        break;

      *scroll_ptr += exp_size;
      if (*scroll_ptr >= dash->module[scrolling.current].idx_data - 1)
        *scroll_ptr = dash->module[scrolling.current].idx_data - 1;
      if (*scroll_ptr >= exp_size && *scroll_ptr >= *offset_ptr + exp_size)
        *offset_ptr += exp_size;
      if (*offset_ptr + exp_size >=
          dash->module[scrolling.current].idx_data - 1)
        *offset_ptr = dash->module[scrolling.current].idx_data - exp_size;
      if (*scroll_ptr < exp_size - 1)
        *offset_ptr = 0;

      display_content (main_win, logger, dash, &scrolling);
      break;
    case 107:  /* k - UP expanded module */
      scroll_ptr = &scrolling.module[scrolling.current].scroll;
      offset_ptr = &scrolling.module[scrolling.current].offset;

      if (!scrolling.expanded)
        break;
      if (*scroll_ptr <= 0)
        break;
      --(*scroll_ptr);
      if (*scroll_ptr < *offset_ptr)
        --(*offset_ptr);
      display_content (main_win, logger, dash, &scrolling);
      break;
    case 'n':
      pthread_mutex_lock (&gdns_thread.mutex);
      search = perform_next_find (holder, &scrolling);
      pthread_mutex_unlock (&gdns_thread.mutex);
      if (search == 0) {
        free_dashboard (dash);
        allocate_data ();
        render_screens ();
      }
      break;
    case '/':
      if (render_find_dialog (main_win, &scrolling))
        break;
      pthread_mutex_lock (&gdns_thread.mutex);
      search = perform_next_find (holder, &scrolling);
      pthread_mutex_unlock (&gdns_thread.mutex);
      if (search == 0) {
        free_dashboard (dash);
        allocate_data ();
        render_screens ();
      }
      break;
    case 99:   /* c */
      if (conf.no_color)
        break;
      load_schemes_win (main_win);
      free_dashboard (dash);
      allocate_data ();
      render_screens ();
      break;
    case 115:  /* s */
      load_sort_win (main_win, scrolling.current,
                     &module_sort[scrolling.current]);
      pthread_mutex_lock (&gdns_thread.mutex);
      free_holder (&holder);
      pthread_cond_broadcast (&gdns_thread.not_empty);
      pthread_mutex_unlock (&gdns_thread.mutex);
      free_dashboard (dash);
      allocate_holder ();
      allocate_data ();
      render_screens ();
      break;
    case 269:
    case KEY_RESIZE:
      endwin ();
      refresh ();
      werase (header_win);
      werase (main_win);
      werase (stdscr);
      term_size (main_win);
      refresh ();
      render_screens ();
      break;
    default:
      if (logger->piping)
        break;
      size2 = file_size (conf.ifile);

      /* file has changed */
      if (size2 != size1) {
        if (!(fp = fopen (conf.ifile, "r")))
          FATAL ("Unable to read log file %s.", strerror (errno));
        if (!fseeko (fp, size1, SEEK_SET))
          while (fgets (buf, LINE_BUFFER, fp) != NULL)
            parse_log (&logger, buf, -1);
        fclose (fp);

        size1 = size2;
        pthread_mutex_lock (&gdns_thread.mutex);
        free_holder (&holder);
        pthread_cond_broadcast (&gdns_thread.not_empty);
        pthread_mutex_unlock (&gdns_thread.mutex);

        free_dashboard (dash);
        allocate_holder ();
        allocate_data ();

        term_size (main_win);
        render_screens ();
        usleep (200000);        /* 0.2 seconds */
      }
      break;
    }
  }
}
Esempio n. 9
0
int main(int argc, char *argv[])
{
	int o;
	unsigned short old_rows;
	struct slab_info *slab_list = NULL;
	int run_once = 0, retval = EXIT_SUCCESS;

	static const struct option longopts[] = {
		{ "delay",	required_argument, NULL, 'd' },
		{ "sort",	required_argument, NULL, 's' },
		{ "once",	no_argument,	   NULL, 'o' },
		{ "help",	no_argument,	   NULL, 'h' },
		{ "version",	no_argument,	   NULL, 'V' },
		{  NULL, 0, NULL, 0 }
	};

#ifdef HAVE_PROGRAM_INVOCATION_NAME
	program_invocation_name = program_invocation_short_name;
#endif
	setlocale (LC_ALL, "");
	bindtextdomain(PACKAGE, LOCALEDIR);
	textdomain(PACKAGE);
	atexit(close_stdout);

	sort_func = DEF_SORT_FUNC;

	while ((o = getopt_long(argc, argv, "d:s:ohV", longopts, NULL)) != -1) {
		switch (o) {
		case 'd':
			errno = 0;
			delay = strtol_or_err(optarg, _("illegal delay"));
			if (delay < 1)
				xerrx(EXIT_FAILURE,
					_("delay must be positive integer"));
			break;
		case 's':
			sort_func = (int (*)(const struct slab_info*,
				const struct slab_info *)) set_sort_func(optarg[0]);
			break;
		case 'o':
			run_once=1;
			delay = 0;
			break;
		case 'V':
			printf(PROCPS_NG_VERSION);
			return EXIT_SUCCESS;
		case 'h':
			usage(stdout);
		default:
			usage(stderr);
		}
	}

	if (tcgetattr(STDIN_FILENO, &saved_tty) == -1)
		xwarn(_("terminal setting retrieval"));

	old_rows = rows;
	term_size(0);
	if (!run_once) {
		initscr();
		resizeterm(rows, cols);
		signal(SIGWINCH, term_size);
	}
	signal(SIGINT, sigint_handler);

	do {
		struct slab_info *curr;
		struct slab_stat stats;
		struct timeval tv;
		fd_set readfds;
		char c;
		int i;
		memset(&stats, 0, sizeof(struct slab_stat));

		if (get_slabinfo(&slab_list, &stats)) {
			retval = EXIT_FAILURE;
			break;
		}

		if (!run_once && old_rows != rows) {
			resizeterm(rows, cols);
			old_rows = rows;
		}

		move(0, 0);
		print_line(" %-35s: %d / %d (%.1f%%)\n"
		       " %-35s: %d / %d (%.1f%%)\n"
		       " %-35s: %d / %d (%.1f%%)\n"
		       " %-35s: %.2fK / %.2fK (%.1f%%)\n"
		       " %-35s: %.2fK / %.2fK / %.2fK\n\n",
		       /* Translation Hint: Next five strings must not
			* exceed 35 length in characters.  */
		       /* xgettext:no-c-format */
		       _("Active / Total Objects (% used)"),
		       stats.nr_active_objs, stats.nr_objs,
		       100.0 * stats.nr_active_objs / stats.nr_objs,
	               /* xgettext:no-c-format */
		       _("Active / Total Slabs (% used)"),
		       stats.nr_active_slabs, stats.nr_slabs,
		       100.0 * stats.nr_active_slabs / stats.nr_slabs,
	               /* xgettext:no-c-format */
		       _("Active / Total Caches (% used)"),
		       stats.nr_active_caches, stats.nr_caches,
		       100.0 * stats.nr_active_caches / stats.nr_caches,
	               /* xgettext:no-c-format */
		       _("Active / Total Size (% used)"),
		       stats.active_size / 1024.0, stats.total_size / 1024.0,
		       100.0 * stats.active_size / stats.total_size,
		       _("Minimum / Average / Maximum Object"),
		       stats.min_obj_size / 1024.0, stats.avg_obj_size / 1024.0,
		       stats.max_obj_size / 1024.0);

		slab_list = slabsort(slab_list);

		attron(A_REVERSE);
		/* Translation Hint: Please keep alignment of the
		 * following intact. */
		print_line("%-78s\n", _("  OBJS ACTIVE  USE OBJ SIZE  SLABS OBJ/SLAB CACHE SIZE NAME"));
		attroff(A_REVERSE);

		curr = slab_list;
		for (i = 0; i < rows - 8 && curr->next; i++) {
			print_line("%6u %6u %3u%% %7.2fK %6u %8u %9uK %-23s\n",
				curr->nr_objs, curr->nr_active_objs, curr->use,
				curr->obj_size / 1024.0, curr->nr_slabs,
				curr->objs_per_slab, (unsigned)(curr->cache_size / 1024),
				curr->name);
			curr = curr->next;
		}

		put_slabinfo(slab_list);
		if (!run_once) {
			refresh();
			FD_ZERO(&readfds);
			FD_SET(STDIN_FILENO, &readfds);
			tv.tv_sec = delay;
			tv.tv_usec = 0;
			if (select(STDOUT_FILENO, &readfds, NULL, NULL, &tv) > 0) {
				if (read(STDIN_FILENO, &c, 1) != 1)
					break;
				parse_input(c);
			}
		}
	} while (delay);

	tcsetattr(STDIN_FILENO, TCSAFLUSH, &saved_tty);
	free_slabinfo(slab_list);
	if (!run_once)
		endwin();
	return retval;
}