⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 display.c

📁 在非GUI环境下
💻 C
📖 第 1 页 / 共 5 页
字号:
    }  /* If someone thought that the redisplay was handled, but the currently     visible line has a different modification state than the one about     to become visible, then correct the caller's misconception. */  if (visible_line[0] != invisible_line[0])    rl_display_fixed = 0;  /* If the prompt to be displayed is the `primary' readline prompt (the     one passed to readline()), use the values we have already expanded.     If not, use what's already in rl_display_prompt.  WRAP_OFFSET is the     number of non-visible characters in the prompt string. */  if (rl_display_prompt == rl_prompt || local_prompt)    {      int local_len = local_prompt ? strlen (local_prompt) : 0;      if (local_prompt_prefix && forced_display)	_rl_output_some_chars (local_prompt_prefix, strlen (local_prompt_prefix));      if (local_len > 0)	{	  temp = local_len + out + 2;	  if (temp >= line_size)	    {	      line_size = (temp + 1024) - (temp % 1024);	      visible_line = (char *)xrealloc (visible_line, line_size);	      line = invisible_line = (char *)xrealloc (invisible_line, line_size);	    }	  strncpy (line + out, local_prompt, local_len);	  out += local_len;	}      line[out] = '\0';      wrap_offset = local_len - prompt_visible_length;    }  else    {      int pmtlen;      prompt_this_line = strrchr (rl_display_prompt, '\n');      if (!prompt_this_line)	prompt_this_line = rl_display_prompt;      else	{	  prompt_this_line++;	  pmtlen = prompt_this_line - rl_display_prompt;	/* temp var */	  if (forced_display)	    {	      _rl_output_some_chars (rl_display_prompt, pmtlen);	      /* Make sure we are at column zero even after a newline,		 regardless of the state of terminal output processing. */	      if (pmtlen < 2 || prompt_this_line[-2] != '\r')		cr ();	    }	}      prompt_physical_chars = pmtlen = strlen (prompt_this_line);      temp = pmtlen + out + 2;      if (temp >= line_size)	{	  line_size = (temp + 1024) - (temp % 1024);	  visible_line = (char *)xrealloc (visible_line, line_size);	  line = invisible_line = (char *)xrealloc (invisible_line, line_size);	}      strncpy (line + out,  prompt_this_line, pmtlen);      out += pmtlen;      line[out] = '\0';      wrap_offset = prompt_invis_chars_first_line = 0;    }#define CHECK_INV_LBREAKS() \      do { \	if (newlines >= (inv_lbsize - 2)) \	  { \	    inv_lbsize *= 2; \	    inv_lbreaks = (int *)xrealloc (inv_lbreaks, inv_lbsize * sizeof (int)); \	  } \      } while (0)#if defined (HANDLE_MULTIBYTE)	  #define CHECK_LPOS() \      do { \	lpos++; \	if (lpos >= _rl_screenwidth) \	  { \	    if (newlines >= (inv_lbsize - 2)) \	      { \		inv_lbsize *= 2; \		inv_lbreaks = (int *)xrealloc (inv_lbreaks, inv_lbsize * sizeof (int)); \		_rl_wrapped_line = (int *)xrealloc (_rl_wrapped_line, inv_lbsize * sizeof (int)); \	      } \	    inv_lbreaks[++newlines] = out; \	    _rl_wrapped_line[newlines] = _rl_wrapped_multicolumn; \	    lpos = 0; \	  } \      } while (0)#else#define CHECK_LPOS() \      do { \	lpos++; \	if (lpos >= _rl_screenwidth) \	  { \	    if (newlines >= (inv_lbsize - 2)) \	      { \		inv_lbsize *= 2; \		inv_lbreaks = (int *)xrealloc (inv_lbreaks, inv_lbsize * sizeof (int)); \	      } \	    inv_lbreaks[++newlines] = out; \	    lpos = 0; \	  } \      } while (0)#endif  /* inv_lbreaks[i] is where line i starts in the buffer. */  inv_lbreaks[newlines = 0] = 0;#if 0  lpos = out - wrap_offset;#else  lpos = prompt_physical_chars + modmark;#endif#if defined (HANDLE_MULTIBYTE)  memset (_rl_wrapped_line, 0, vis_lbsize);#endif  /* prompt_invis_chars_first_line is the number of invisible characters in     the first physical line of the prompt.     wrap_offset - prompt_invis_chars_first_line is the number of invis     chars on the second line. */  /* what if lpos is already >= _rl_screenwidth before we start drawing the     contents of the command line? */  while (lpos >= _rl_screenwidth)    {      /* fix from Darin Johnson <darin@acuson.com> for prompt string with         invisible characters that is longer than the screen width.  The         prompt_invis_chars_first_line variable could be made into an array         saying how many invisible characters there are per line, but that's         probably too much work for the benefit gained.  How many people have         prompts that exceed two physical lines?         Additional logic fix from Edward Catmur <ed@catmur.co.uk> */      temp = ((newlines + 1) * _rl_screenwidth) +             ((local_prompt_prefix == 0) ? ((newlines == 0) ? prompt_invis_chars_first_line							    : ((newlines == 1) ? wrap_offset : 0))					 : ((newlines == 0) ? wrap_offset :0));                   inv_lbreaks[++newlines] = temp;      lpos -= _rl_screenwidth;    }  prompt_last_screen_line = newlines;  /* Draw the rest of the line (after the prompt) into invisible_line, keeping     track of where the cursor is (c_pos), the number of the line containing     the cursor (lb_linenum), the last line number (lb_botlin and inv_botlin).     It maintains an array of line breaks for display (inv_lbreaks).     This handles expanding tabs for display and displaying meta characters. */  lb_linenum = 0;#if defined (HANDLE_MULTIBYTE)  in = 0;  if (MB_CUR_MAX > 1 && rl_byte_oriented == 0)    {      memset (&ps, 0, sizeof (mbstate_t));      wc_bytes = mbrtowc (&wc, rl_line_buffer, rl_end, &ps);    }  else    wc_bytes = 1;  while (in < rl_end)#else  for (in = 0; in < rl_end; in++)#endif    {      c = (unsigned char)rl_line_buffer[in];#if defined (HANDLE_MULTIBYTE)      if (MB_CUR_MAX > 1 && rl_byte_oriented == 0)	{	  if (MB_INVALIDCH (wc_bytes))	    {	      /* Byte sequence is invalid or shortened.  Assume that the	         first byte represents a character. */	      wc_bytes = 1;	      /* Assume that a character occupies a single column. */	      wc_width = 1;	      memset (&ps, 0, sizeof (mbstate_t));	    }	  else if (MB_NULLWCH (wc_bytes))	    break;			/* Found '\0' */	  else	    {	      temp = wcwidth (wc);	      wc_width = (temp >= 0) ? temp : 1;	    }	}#endif      if (out + 8 >= line_size)		/* XXX - 8 for \t */	{	  line_size *= 2;	  visible_line = (char *)xrealloc (visible_line, line_size);	  invisible_line = (char *)xrealloc (invisible_line, line_size);	  line = invisible_line;	}      if (in == rl_point)	{	  c_pos = out;	  lb_linenum = newlines;	}#if defined (HANDLE_MULTIBYTE)      if (META_CHAR (c) && _rl_output_meta_chars == 0)	/* XXX - clean up */#else      if (META_CHAR (c))#endif	{	  if (_rl_output_meta_chars == 0)	    {	      sprintf (line + out, "\\%o", c);	      if (lpos + 4 >= _rl_screenwidth)		{		  temp = _rl_screenwidth - lpos;		  CHECK_INV_LBREAKS ();		  inv_lbreaks[++newlines] = out + temp;		  lpos = 4 - temp;		}	      else		lpos += 4;	      out += 4;	    }	  else	    {	      line[out++] = c;	      CHECK_LPOS();	    }	}#if defined (DISPLAY_TABS)      else if (c == '\t')	{	  register int newout;#if 0	  newout = (out | (int)7) + 1;#else	  newout = out + 8 - lpos % 8;#endif	  temp = newout - out;	  if (lpos + temp >= _rl_screenwidth)	    {	      register int temp2;	      temp2 = _rl_screenwidth - lpos;	      CHECK_INV_LBREAKS ();	      inv_lbreaks[++newlines] = out + temp2;	      lpos = temp - temp2;	      while (out < newout)		line[out++] = ' ';	    }	  else	    {	      while (out < newout)		line[out++] = ' ';	      lpos += temp;	    }	}#endif      else if (c == '\n' && _rl_horizontal_scroll_mode == 0 && _rl_term_up && *_rl_term_up)	{	  line[out++] = '\0';	/* XXX - sentinel */	  CHECK_INV_LBREAKS ();	  inv_lbreaks[++newlines] = out;	  lpos = 0;	}      else if (CTRL_CHAR (c) || c == RUBOUT)	{	  line[out++] = '^';	  CHECK_LPOS();	  line[out++] = CTRL_CHAR (c) ? UNCTRL (c) : '?';	  CHECK_LPOS();	}      else	{#if defined (HANDLE_MULTIBYTE)	  if (MB_CUR_MAX > 1 && rl_byte_oriented == 0)	    {	      register int i;	      _rl_wrapped_multicolumn = 0;	      if (_rl_screenwidth < lpos + wc_width)		for (i = lpos; i < _rl_screenwidth; i++)		  {		    /* The space will be removed in update_line() */		    line[out++] = ' ';		    _rl_wrapped_multicolumn++;		    CHECK_LPOS();		  }	      if (in == rl_point)		{		  c_pos = out;		  lb_linenum = newlines;		}	      for (i = in; i < in+wc_bytes; i++)		line[out++] = rl_line_buffer[i];	      for (i = 0; i < wc_width; i++)		CHECK_LPOS();	    }	  else	    {	      line[out++] = c;	      CHECK_LPOS();	    }#else	  line[out++] = c;	  CHECK_LPOS();#endif	}#if defined (HANDLE_MULTIBYTE)      if (MB_CUR_MAX > 1 && rl_byte_oriented == 0)	{	  in += wc_bytes;	  wc_bytes = mbrtowc (&wc, rl_line_buffer + in, rl_end - in, &ps);	}      else        in++;#endif    }  line[out] = '\0';  if (c_pos < 0)    {      c_pos = out;      lb_linenum = newlines;    }  inv_botlin = lb_botlin = newlines;  CHECK_INV_LBREAKS ();  inv_lbreaks[newlines+1] = out;  cursor_linenum = lb_linenum;  /* C_POS == position in buffer where cursor should be placed.     CURSOR_LINENUM == line number where the cursor should be placed. */  /* PWP: now is when things get a bit hairy.  The visible and invisible     line buffers are really multiple lines, which would wrap every     (screenwidth - 1) characters.  Go through each in turn, finding     the changed region and updating it.  The line order is top to bottom. */  /* If we can move the cursor up and down, then use multiple lines,     otherwise, let long lines display in a single terminal line, and     horizontally scroll it. */  if (_rl_horizontal_scroll_mode == 0 && _rl_term_up && *_rl_term_up)    {      int nleft, pos, changed_screen_line;      if (!rl_display_fixed || forced_display)	{	  forced_display = 0;	  /* If we have more than a screenful of material to display, then	     only display a screenful.  We should display the last screen,	     not the first.  */	  if (out >= _rl_screenchars)	    {	      if (MB_CUR_MAX > 1 && rl_byte_oriented == 0)		out = _rl_find_prev_mbchar (line, _rl_screenchars, MB_FIND_ANY);	      else		out = _rl_screenchars - 1;	    }	  /* The first line is at character position 0 in the buffer.  The	     second and subsequent lines start at inv_lbreaks[N], offset by	     OFFSET (which has already been calculated above).  */#define W_OFFSET(line, offset) ((line) == 0 ? offset : 0)#define VIS_LLEN(l)	((l) > _rl_vis_botlin ? 0 : (vis_lbreaks[l+1] - vis_lbreaks[l]))#define INV_LLEN(l)	(inv_lbreaks[l+1] - inv_lbreaks[l])#define VIS_CHARS(line) (visible_line + vis_lbreaks[line])#define VIS_LINE(line) ((line) > _rl_vis_botlin) ? "" : VIS_CHARS(line)#define INV_LINE(line) (invisible_line + inv_lbreaks[line])	  /* For each line in the buffer, do the updating display. */	  for (linenum = 0; linenum <= inv_botlin; linenum++)	    {	      update_line (VIS_LINE(linenum), INV_LINE(linenum), linenum,			   VIS_LLEN(linenum), INV_LLEN(linenum), inv_botlin);	      /* If this is the line with the prompt, we might need to		 compensate for invisible characters in the new line. Do		 this only if there is not more than one new line (which		 implies that we completely overwrite the old visible line)		 and the new line is shorter than the old.  Make sure we are		 at the end of the new line before clearing. */	      if (linenum == 0 &&		  inv_botlin == 0 && _rl_last_c_pos == out &&		  (wrap_offset > visible_wrap_offset) &&		  (_rl_last_c_pos < visible_first_line_len))		{		  nleft = _rl_screenwidth + wrap_offset - _rl_last_c_pos;		  if (nleft)		    _rl_clear_to_eol (nleft);		}	      /* Since the new first line is now visible, save its length. */	      if (linenum == 0)		visible_first_line_len = (inv_botlin > 0) ? inv_lbreaks[1] : out - wrap_offset;	    }	  /* We may have deleted some lines.  If so, clear the left over	     blank ones at the bottom out. */	  if (_rl_vis_botlin > inv_botlin)	    {	      char *tt;	      for (; linenum <= _rl_vis_botlin; linenum++)		{		  tt = VIS_CHARS (linenum);		  _rl_move_vert (linenum);		  _rl_move_cursor_relative (0, tt);		  _rl_clear_to_eol		    ((linenum == _rl_vis_botlin) ? strlen (tt) : _rl_screenwidth);		}	    }	  _rl_vis_botlin = inv_botlin;	  /* CHANGED_SCREEN_LINE is set to 1 if we have moved to a	     different screen line during this redisplay. */	  changed_screen_line = _rl_last_v_pos != cursor_linenum;	  if (changed_screen_line)	    {	      _rl_move_vert (cursor_linenum);	      /* If we moved up to the line with the prompt using _rl_term_up,		 the physical cursor position on the screen stays the same,		 but the buffer position needs to be adjusted to account		 for invisible characters. */	      if (cursor_linenum == 0 && wrap_offset)		_rl_last_c_pos += wrap_offset;	    }	  /* We have to reprint the prompt if it contains invisible	     characters, since it's not generally OK to just reprint	     the characters from the current cursor position.  But we	     only need to reprint it if the cursor is before the last	     invisible character in the prompt string. */	  nleft = prompt_visible_length + wrap_offset;	  if (cursor_linenum == 0 && wrap_offset > 0 && _rl_last_c_pos > 0 &&	      _rl_last_c_pos <= prompt_last_invisible && local_prompt)	    {#if defined (__MSDOS__)	      putc ('\r', rl_outstream);#else	      if (_rl_term_cr)		tputs (_rl_term_cr, 1, _rl_output_character_function);#endif	      _rl_output_some_chars (local_prompt, nleft);	      if (MB_CUR_MAX > 1 && rl_byte_oriented == 0)

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -