Пример #1
0
static void sig_gui_print_text(WINDOW_REC *window, void *fgcolor,
			       void *bgcolor, void *pflags,
			       char *str, void *level)
{
        GUI_WINDOW_REC *gui;
        TEXT_BUFFER_VIEW_REC *view;
	LINE_REC *insert_after;
        LINE_INFO_REC lineinfo;
	int fg, bg, flags, attr;

	flags = GPOINTER_TO_INT(pflags);
	fg = GPOINTER_TO_INT(fgcolor);
	bg = GPOINTER_TO_INT(bgcolor);
	get_colors(flags, &fg, &bg, &attr);

	if (window == NULL) {
                g_return_if_fail(next_xpos != -1);

		attr |= fg >= 0 ? fg : ATTR_RESETFG;
		attr |= bg >= 0 ? (bg << 4) : ATTR_RESETBG;
		term_set_color(root_window, attr);

		term_move(root_window, next_xpos, next_ypos);
		if (flags & GUI_PRINT_FLAG_CLRTOEOL)
			term_clrtoeol(root_window);
		term_addstr(root_window, str);
		next_xpos += strlen(str);
                return;
	}

	lineinfo.level = GPOINTER_TO_INT(level);
        lineinfo.time = time(NULL);

        gui = WINDOW_GUI(window);
	view = gui->view;
	insert_after = gui->use_insert_after ?
		gui->insert_after : view->buffer->cur_line;

	if (flags & GUI_PRINT_FLAG_NEWLINE)
                view_add_eol(view, &insert_after);
	line_add_colors(view->buffer, &insert_after, fg, bg, flags);

	if (flags & GUI_PRINT_FLAG_INDENT_FUNC) {
		/* specify the indentation function */
                line_add_indent_func(view->buffer, &insert_after, str);
	} else {
		insert_after = textbuffer_insert(view->buffer, insert_after,
						 (unsigned char *) str,
						 strlen(str), &lineinfo);
	}
	if (gui->use_insert_after)
                gui->insert_after = insert_after;
}
Пример #2
0
static void
draw_line (size_t line, size_t startcol, Window wp,
           size_t o, Region r, int highlight, size_t cur_tab_width)
{
  term_move (line, 0);

  /* Draw body of line. */
  size_t x, i, line_len = buffer_line_len (get_window_bp (wp), o);
  for (x = 0, i = startcol;; i++)
    {
      term_attrset (highlight && region_contains (r, o + i) ? FONT_REVERSE : FONT_NORMAL);
      if (i >= line_len || x >= get_window_ewidth (wp))
        break;
      char c = get_buffer_char (get_window_bp (wp), o + i);
      if (isprint (c))
        {
          term_addch (c);
          x++;
        }
      else
        {
          const char *s = make_char_printable (c, x, cur_tab_width);
          term_addstr (s);
          x += strlen (s);
        }
    }

  /* Draw end of line. */
  if (x >= term_width ())
    {
      term_move (line, term_width () - 1);
      term_attrset (FONT_NORMAL);
      term_addstr ("$");
    }
  else
    term_addstr (xasprintf ("%*s", (int) (get_window_ewidth (wp) - x), ""));
  term_attrset (FONT_NORMAL);
}
Пример #3
0
static void
draw_status_line (size_t line, Window wp)
{
  term_attrset (FONT_REVERSE);

  term_move (line, 0);
  for (size_t i = 0; i < get_window_ewidth (wp); ++i)
    term_addstr ("-");

  const char *eol_type;
  if (get_buffer_eol (cur_bp) == coding_eol_cr)
    eol_type = "(Mac)";
  else if (get_buffer_eol (cur_bp) == coding_eol_crlf)
    eol_type = "(DOS)";
  else
    eol_type = ":";

  term_move (line, 0);
  size_t n = offset_to_line (get_window_bp (wp), window_o (wp));
  astr as = astr_fmt ("--%s%2s  %-15s   %s %-9s (Fundamental",
                      eol_type, make_mode_line_flags (wp), get_buffer_name (get_window_bp (wp)),
                      make_screen_pos (wp), astr_cstr (astr_fmt ("(%zu,%zu)", n + 1,
                                                                 get_goalc_bp (get_window_bp (wp), window_o (wp)))));

  if (get_buffer_autofill (get_window_bp (wp)))
    astr_cat_cstr (as, " Fill");
  if (thisflag & FLAG_DEFINING_MACRO)
    astr_cat_cstr (as, " Def");
  if (get_buffer_isearch (get_window_bp (wp)))
    astr_cat_cstr (as, " Isearch");

  astr_cat_char (as, ')');
  term_addstr (astr_cstr (as));

  term_attrset (FONT_NORMAL);
}
Пример #4
0
static void sig_gui_print_text(WINDOW_REC *window, void *fgcolor,
			       void *bgcolor, void *pflags,
			       char *str, TEXT_DEST_REC *dest)
{
        GUI_WINDOW_REC *gui;
        TEXT_BUFFER_VIEW_REC *view;
	LINE_REC *insert_after;
        LINE_INFO_REC lineinfo;
	int fg, bg, flags, attr;

	flags = GPOINTER_TO_INT(pflags);
	fg = GPOINTER_TO_INT(fgcolor);
	bg = GPOINTER_TO_INT(bgcolor);
	get_colors(flags, &fg, &bg, &attr);

	if (window == NULL) {
                g_return_if_fail(next_xpos != -1);

		term_set_color2(root_window, attr, fg, bg);

		term_move(root_window, next_xpos, next_ypos);
		if (flags & GUI_PRINT_FLAG_CLRTOEOL)
			term_clrtoeol(root_window);
		term_addstr(root_window, str);
		next_xpos += strlen(str); /* FIXME utf8 or big5 */
                return;
	}

	lineinfo.level = dest == NULL ? 0 : dest->level;
        gui = WINDOW_GUI(window);
        lineinfo.time = (gui->use_insert_after && gui->insert_after_time) ?
		gui->insert_after_time : time(NULL);

	view = gui->view;
	insert_after = gui->use_insert_after ?
		gui->insert_after : view->buffer->cur_line;

	if (flags & GUI_PRINT_FLAG_NEWLINE) {
                view_add_eol(view, &insert_after);
	}
	textbuffer_line_add_colors(view->buffer, &insert_after, fg, bg, flags);

	insert_after = textbuffer_insert(view->buffer, insert_after,
					 (unsigned char *) str,
					 strlen(str), &lineinfo);
	if (gui->use_insert_after)
                gui->insert_after = insert_after;
}
Пример #5
0
static void
draw_window (size_t topline, Window wp)
{
  size_t i, o;
  Region r;
  int highlight = calculate_highlight_region (wp, &r);

  /* Find the first line to display on the first screen line. */
  for (o = buffer_start_of_line (get_window_bp (wp), window_o (wp)), i = get_window_topdelta (wp);
       i > 0 && o > 0;
       assert ((o = buffer_prev_line (get_window_bp (wp), o)) != SIZE_MAX), --i)
    ;

  /* Draw the window lines. */
  size_t cur_tab_width = tab_width (get_window_bp (wp));
  for (i = topline; i < get_window_eheight (wp) + topline; ++i)
    {
      /* Clear the line. */
      term_move (i, 0);
      term_clrtoeol ();

      /* If at the end of the buffer, don't write any text. */
      if (o == SIZE_MAX)
        continue;

      draw_line (i, get_window_start_column (wp), wp, o, r, highlight, cur_tab_width);

      if (get_window_start_column (wp) > 0)
        {
          term_move (i, 0);
          term_addstr("$");
        }

      o = buffer_next_line (get_window_bp (wp), o);
    }

  set_window_all_displayed (wp, o >= get_buffer_size (get_window_bp (wp)));

  /* Draw the status line only if there is available space after the
     buffer text space. */
  if (get_window_fheight (wp) - get_window_eheight (wp) > 0)
    draw_status_line (topline + get_window_eheight (wp), wp);
}