2 * COPYRIGHT: See COPYING in the top level directory
3 * PROJECT: ReactOS Console Utilities Library
4 * FILE: sdk/lib/conutils/pager.c
5 * PURPOSE: Console/terminal paging functionality.
6 * PROGRAMMERS: - Hermes Belusca-Maito (for the library);
7 * - All programmers who wrote the different console applications
8 * from which I took those functions and improved them.
11 /* FIXME: Temporary HACK before we cleanly support UNICODE functions */
15 #include <stdlib.h> // limits.h // For MB_LEN_MAX
19 // #include <winnls.h>
20 #include <wincon.h> // Console APIs (only if kernel32 support included)
29 #define CON_STREAM_WRITE ConStreamWrite
33 /* Returns TRUE when all the text is displayed, and FALSE if display is stopped */
37 IN PAGE_PROMPT PagePrompt
,
42 CONSOLE_SCREEN_BUFFER_INFO csbi
;
44 /* Used to see how big the screen is */
45 DWORD ScreenLines
= 0;
47 /* Chars since start of line */
50 DWORD from
= 0, i
= 0;
52 /* Parameters validation */
56 /* Reset LineCount and return if no string has been given */
57 if (StartPaging
== TRUE
)
62 /* Get the size of the visual screen that can be printed to */
63 if (!ConGetScreenInfo(Pager
->Screen
, &csbi
))
65 /* We assume it's a file handle */
66 CON_STREAM_WRITE(Pager
->Screen
->Stream
, szStr
, len
);
71 * Get the number of lines currently displayed on screen, minus 1
72 * to account for the "press any key..." prompt from PagePrompt().
74 ScreenLines
= (csbi
.srWindow
.Bottom
- csbi
.srWindow
.Top
);
75 CharSL
= csbi
.dwCursorPosition
.X
;
77 /* Make sure the user doesn't have the screen too small */
80 CON_STREAM_WRITE(Pager
->Screen
->Stream
, szStr
, len
);
86 /* Search until the end of a line is reached */
87 if (szStr
[i
++] != TEXT('\n') && ++CharSL
< csbi
.dwSize
.X
)
93 if (Pager
->LineCount
>= ScreenLines
)
95 CON_STREAM_WRITE(Pager
->Screen
->Stream
, &szStr
[from
], i
-from
);
98 /* Prompt the user; give him some values for statistics */
99 // FIXME TODO: The prompt proc can also take ScreenLines ??
100 if (!PagePrompt(Pager
, from
, len
))
103 // TODO: Recalculate 'ScreenLines' in case the user redimensions
104 // the window during the prompt.
106 /* Reset the number of lines being printed */
107 Pager
->LineCount
= 0;
111 CON_STREAM_WRITE(Pager
->Screen
->Stream
, &szStr
[from
], i
-from
);
119 IN PAGE_PROMPT PagePrompt
,
125 /* Return if no string has been given */
130 return ConWritePaging(Pager
, PagePrompt
, StartPaging
, szStr
, len
);
136 IN PAGE_PROMPT PagePrompt
,
143 Len
= K32LoadStringW(GetModuleHandleW(NULL
), uID
, (PWSTR
)&szStr
, 0);
145 return ConWritePaging(Pager
, PagePrompt
, StartPaging
, szStr
, Len
);