示例#1
0
void
term_redisplay (void)
{
  /* Calculate the start column if the line at point has to be truncated. */
  Buffer bp = get_window_bp (cur_wp);
  size_t lastcol = 0, t = tab_width (bp);
  size_t o = window_o (cur_wp);
  size_t lineo = o - get_buffer_line_o (bp);

  col = 0;
  o -= lineo;
  set_window_start_column (cur_wp, 0);

  size_t ew = get_window_ewidth (cur_wp);
  for (size_t lp = lineo; lp != SIZE_MAX; --lp)
    {
      col = 0;
      for (size_t p = lp; p < lineo; ++p)
        {
          char c = get_buffer_char (bp, o + p);
          if (isprint (c))
            col++;
          else
            col += strlen (make_char_printable (get_buffer_char (bp, o + p), col, t));
        }

      if (col >= ew - 1 || (lp / (ew / 3)) + 2 < lineo / (ew / 3))
        {
          set_window_start_column (cur_wp, lp + 1);
          col = lastcol;
          break;
        }

      lastcol = col;
    }

  /* Draw the windows. */
  cur_topline = 0;
  size_t topline = 0;
  for (Window wp = head_wp; wp != NULL; wp = get_window_next (wp))
    {
      if (wp == cur_wp)
        cur_topline = topline;

      draw_window (topline, wp);

      topline += get_window_fheight (wp);
    }

  term_redraw_cursor ();
}
示例#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 outch(int c, Font font, size_t *x)
{
  int j, w;
  char *buf;

  if (*x >= term_width())
    return;

  term_attrset(1, font);

  if (c == '\t')
    for (w = cur_tab_width - *x % cur_tab_width; w > 0 && *x < term_width(); w--)
      term_addch(' '), ++(*x);
  else if (isprint(c))
    term_addch(c), ++(*x);
  else {
    j = make_char_printable(&buf, (size_t)c);
    for (w = 0; w < j && *x < term_width(); ++w)
      term_addch(buf[w]), ++(*x);
    free(buf);
  }

  term_attrset(1, FONT_NORMAL);
}
示例#4
0
/*
 * This function calculates the best start column to draw if the line
 * needs to get truncated.
 * Called only for the line where is the point.
 */
static void calculate_start_column(Window *wp)
{
  size_t col = 0, lastcol = 0, t = tab_width(wp->bp);
  int rpfact, lpfact;
  char *buf, *rp, *lp, *p;
  Point pt = window_pt(wp);

  rp = astr_char(pt.p->item, (ptrdiff_t)pt.o);
  rpfact = pt.o / (wp->ewidth / 3);

  for (lp = rp; lp >= astr_cstr(pt.p->item); --lp) {
    for (col = 0, p = lp; p < rp; ++p)
      if (*p == '\t') {
        col |= t - 1;
        ++col;
      } else if (isprint(*p))
        ++col;
      else {
        col += make_char_printable(&buf, (size_t)*p);
        free(buf);
      }

    lpfact = (lp - astr_cstr(pt.p->item)) / (wp->ewidth / 3);

    if (col >= wp->ewidth - 1 || lpfact < (rpfact - 2)) {
      wp->start_column = lp + 1 - astr_cstr(pt.p->item);
      point_screen_column = lastcol;
      return;
    }

    lastcol = col;
  }

  wp->start_column = 0;
  point_screen_column = col;
}