2 * PROJECT: ReactOS Console Utilities Library
3 * LICENSE: GPL-2.0+ (https://spdx.org/licenses/GPL-2.0+)
4 * PURPOSE: Console/terminal paging functionality.
5 * COPYRIGHT: Copyright 2017-2018 ReactOS Team
6 * Copyright 2017-2018 Hermes Belusca-Maito
13 * @brief Console/terminal paging functionality.
16 /* FIXME: Temporary HACK before we cleanly support UNICODE functions */
22 // #include <winnls.h>
23 #include <wincon.h> // Console APIs (only if kernel32 support included)
32 #define CON_STREAM_WRITE ConStreamWrite
36 /* Returns TRUE when all the text is displayed, and FALSE if display is stopped */
40 IN PAGE_PROMPT PagePrompt
,
45 CONSOLE_SCREEN_BUFFER_INFO csbi
;
47 /* Used to see how big the screen is */
48 DWORD ScreenLines
= 0;
50 /* Chars since start of line */
53 DWORD from
= 0, i
= 0;
55 /* Parameters validation */
59 /* Reset LineCount and return if no string has been given */
60 if (StartPaging
== TRUE
)
65 /* Get the size of the visual screen that can be printed to */
66 if (!ConGetScreenInfo(Pager
->Screen
, &csbi
))
68 /* We assume it's a file handle */
69 CON_STREAM_WRITE(Pager
->Screen
->Stream
, szStr
, len
);
74 * Get the number of lines currently displayed on screen, minus 1
75 * to account for the "press any key..." prompt from PagePrompt().
77 ScreenLines
= (csbi
.srWindow
.Bottom
- csbi
.srWindow
.Top
);
78 CharSL
= csbi
.dwCursorPosition
.X
;
80 /* Make sure the user doesn't have the screen too small */
83 CON_STREAM_WRITE(Pager
->Screen
->Stream
, szStr
, len
);
89 /* Search until the end of a line is reached */
90 if (szStr
[i
++] != TEXT('\n') && ++CharSL
< csbi
.dwSize
.X
)
96 if (Pager
->LineCount
>= ScreenLines
)
98 CON_STREAM_WRITE(Pager
->Screen
->Stream
, &szStr
[from
], i
-from
);
101 /* Prompt the user; give him some values for statistics */
102 // FIXME TODO: The prompt proc can also take ScreenLines ??
103 if (!PagePrompt(Pager
, from
, len
))
106 // TODO: Recalculate 'ScreenLines' in case the user redimensions
107 // the window during the prompt.
109 /* Reset the number of lines being printed */
110 Pager
->LineCount
= 0;
114 CON_STREAM_WRITE(Pager
->Screen
->Stream
, &szStr
[from
], i
-from
);
122 IN PAGE_PROMPT PagePrompt
,
128 /* Return if no string has been given */
133 return ConWritePaging(Pager
, PagePrompt
, StartPaging
, szStr
, len
);
139 IN PAGE_PROMPT PagePrompt
,
141 IN HINSTANCE hInstance OPTIONAL
,
147 Len
= K32LoadStringW(hInstance
, uID
, (PWSTR
)&szStr
, 0);
149 return ConWritePaging(Pager
, PagePrompt
, StartPaging
, szStr
, Len
);
157 IN PAGE_PROMPT PagePrompt
,
161 return ConResPagingEx(Pager
, PagePrompt
, StartPaging
,
162 NULL
/*GetModuleHandleW(NULL)*/, uID
);