[CONUTILS:PAGER][MORE] Implement text line caching + fix some bugs.

- Implement caching of individual (newline-separated) text lines; this
  behaviour can be enabled with a flag (enabled by MORE):
  CON_PAGER_CACHE_INCOMPLETE_LINE.
  This feature is necessary when reading a text file, whose text lines
  may span across two or more successive temporary read buffers, and is
  required for correctly determining whether the lines being read are
  blank and may be squeezed.

- When squeezing blank lines, the blank-line check must be done for each
  line segment corresponding to the screen line (and following) that
  need to be displayed. This matches the behaviour of MS MORE.COM.

- Fix the IsBlankLine() check to not consider FORM-FEEDs as being blank
  characters: This is necessary for correctly handling FORM-FEED
  expansion. Also note that MS MORE.COM only checks for spaces and TABs,
  so we are slightly overdoing these checks (considering other types of
  whitespace).

- Get rid of ConCallPagerLine() and the intermediate CON_PAGER_DONT_OUTPUT
  state flag that were used repeatedly for each and every small line
  chunks. Instead, call directly the user-specified 'PagerLine' callback
  when we are about to start treating the next line segment to be
  displayed (see comment above).

- Fix the exit return condition of ConPagerWorker(): it should return
  TRUE whenever we displayed all the required lines, and FALSE otherwise.
  Otherwise, the previous (buggy) condition on the data being read from
  the text file, may lead to the prompt not showing when a screenful of
  text has been displayed, if it happened that the current text buffer
  becomes empty at the same time (even if, overall, the text file hasn't
  been fully displayed).

- In MorePagerLine(), when we encounter for the first time a blank line
  that will be squeezed with other successive ones, display a single
  blank line. But for that, just display one space and a newline: this
  single space is especially needed in order to force line wrapping when
  the ENABLE_VIRTUAL_TERMINAL_PROCESSING or DISABLE_NEWLINE_AUTO_RETURN
  console modes are enabled. Otherwise the cursor remains at the
  previous line (without wrapping), and just outputting one newline will
  not make it move past 2 lines as one would naively expect.
This commit is contained in:
Hermès Bélusca-Maïto 2021-06-28 20:08:38 +02:00
parent aff90f530c
commit 31322f5df9
No known key found for this signature in database
GPG key ID: 3B2539C65E7B93D0
3 changed files with 363 additions and 109 deletions

View file

@ -37,9 +37,10 @@ typedef BOOL
IN DWORD cch);
/* Flags for CON_PAGER */
#define CON_PAGER_DONT_OUTPUT (1 << 0)
#define CON_PAGER_EXPAND_TABS (1 << 1)
#define CON_PAGER_EXPAND_FF (1 << 2)
#define CON_PAGER_EXPAND_TABS (1 << 0)
#define CON_PAGER_EXPAND_FF (1 << 1)
// Whether or not the pager will cache the line if it's incomplete (not NEWLINE-terminated).
#define CON_PAGER_CACHE_INCOMPLETE_LINE (1 << 2)
typedef struct _CON_PAGER
{
@ -55,12 +56,15 @@ typedef struct _CON_PAGER
DWORD ScrollRows;
/* Data buffer */
PCTCH TextBuff; /* The text buffer */
DWORD cch; /* The total number of characters */
PCTCH CachedLine; /* Cached line, HeapAlloc'ated */
SIZE_T cchCachedLine; /* Its length (number of characters) */
SIZE_T ich; /* The current index of character in TextBuff (a user-provided source buffer) */
/* Paging state */
DWORD ich; /* The current index of character */
DWORD nSpacePending; /* Pending spaces for TAB expansion */
PCTCH CurrentLine; /* Pointer to the current line (either within a user-provided source buffer, or to CachedLine) */
SIZE_T ichCurr; /* The current index of character in CurrentLine */
SIZE_T iEndLine; /* End (length) of CurrentLine */
DWORD nSpacePending; /* Pending spaces for TAB expansion */
DWORD iColumn; /* The current index of column */
DWORD iLine; /* The physical output line count of screen */
DWORD lineno; /* The logical line number */