xref: /reactos/sdk/lib/conutils/pager.h (revision 31322f5d)
1c2c66affSColin Finck /*
2c2c66affSColin Finck  * PROJECT:     ReactOS Console Utilities Library
34e697feeSHermès Bélusca-Maïto  * LICENSE:     GPL-2.0+ (https://spdx.org/licenses/GPL-2.0+)
4c2c66affSColin Finck  * PURPOSE:     Console/terminal paging functionality.
5b552901dSKatayama Hirofumi MZ  * COPYRIGHT:   Copyright 2017-2021 Hermes Belusca-Maito
6b552901dSKatayama Hirofumi MZ  *              Copyright 2021 Katayama Hirofumi MZ
7c2c66affSColin Finck  */
8c2c66affSColin Finck 
9f982d77bSHermès Bélusca-Maïto /**
10f982d77bSHermès Bélusca-Maïto  * @file    pager.h
11f982d77bSHermès Bélusca-Maïto  * @ingroup ConUtils
12f982d77bSHermès Bélusca-Maïto  *
13f982d77bSHermès Bélusca-Maïto  * @brief   Console/terminal paging functionality.
14f982d77bSHermès Bélusca-Maïto  **/
15f982d77bSHermès Bélusca-Maïto 
16c2c66affSColin Finck #ifndef __PAGER_H__
17c2c66affSColin Finck #define __PAGER_H__
18c2c66affSColin Finck 
194e697feeSHermès Bélusca-Maïto #pragma once
204e697feeSHermès Bélusca-Maïto 
21c2c66affSColin Finck #ifndef _UNICODE
22c2c66affSColin Finck #error The ConUtils library at the moment only supports compilation with _UNICODE defined!
23c2c66affSColin Finck #endif
24c2c66affSColin Finck 
251e87e2faSHermès Bélusca-Maïto #ifdef __cplusplus
261e87e2faSHermès Bélusca-Maïto extern "C" {
271e87e2faSHermès Bélusca-Maïto #endif
281e87e2faSHermès Bélusca-Maïto 
29c2c66affSColin Finck // #include <wincon.h>
30c2c66affSColin Finck 
31b552901dSKatayama Hirofumi MZ struct _CON_PAGER;
32f74a3f6eSHermès Bélusca-Maïto 
33f74a3f6eSHermès Bélusca-Maïto typedef BOOL
34f74a3f6eSHermès Bélusca-Maïto (__stdcall *CON_PAGER_LINE_FN)(
35b552901dSKatayama Hirofumi MZ     IN OUT struct _CON_PAGER *Pager,
36b552901dSKatayama Hirofumi MZ     IN PCTCH line,
37b552901dSKatayama Hirofumi MZ     IN DWORD cch);
38b552901dSKatayama Hirofumi MZ 
39b552901dSKatayama Hirofumi MZ /* Flags for CON_PAGER */
40*31322f5dSHermès Bélusca-Maïto #define CON_PAGER_EXPAND_TABS   (1 << 0)
41*31322f5dSHermès Bélusca-Maïto #define CON_PAGER_EXPAND_FF     (1 << 1)
42*31322f5dSHermès Bélusca-Maïto // Whether or not the pager will cache the line if it's incomplete (not NEWLINE-terminated).
43*31322f5dSHermès Bélusca-Maïto #define CON_PAGER_CACHE_INCOMPLETE_LINE (1 << 2)
44c2c66affSColin Finck 
45c2c66affSColin Finck typedef struct _CON_PAGER
46c2c66affSColin Finck {
47b552901dSKatayama Hirofumi MZ     /* Console screen properties */
48c2c66affSColin Finck     PCON_SCREEN Screen;
49f74a3f6eSHermès Bélusca-Maïto     DWORD PageColumns;
50f74a3f6eSHermès Bélusca-Maïto     DWORD PageRows;
51c2c66affSColin Finck 
52b552901dSKatayama Hirofumi MZ     /* Paging parameters */
53b552901dSKatayama Hirofumi MZ     CON_PAGER_LINE_FN PagerLine; /* The line function */
54f74a3f6eSHermès Bélusca-Maïto     DWORD dwFlags;  /* The CON_PAGER_... flags */
55b552901dSKatayama Hirofumi MZ     LONG  nTabWidth;
56b552901dSKatayama Hirofumi MZ     DWORD ScrollRows;
57c2c66affSColin Finck 
58b552901dSKatayama Hirofumi MZ     /* Data buffer */
59*31322f5dSHermès Bélusca-Maïto     PCTCH  CachedLine;    /* Cached line, HeapAlloc'ated */
60*31322f5dSHermès Bélusca-Maïto     SIZE_T cchCachedLine; /* Its length (number of characters) */
61*31322f5dSHermès Bélusca-Maïto     SIZE_T ich;           /* The current index of character in TextBuff (a user-provided source buffer) */
62b552901dSKatayama Hirofumi MZ 
63b552901dSKatayama Hirofumi MZ     /* Paging state */
64*31322f5dSHermès Bélusca-Maïto     PCTCH  CurrentLine;   /* Pointer to the current line (either within a user-provided source buffer, or to CachedLine) */
65*31322f5dSHermès Bélusca-Maïto     SIZE_T ichCurr;       /* The current index of character in CurrentLine */
66*31322f5dSHermès Bélusca-Maïto     SIZE_T iEndLine;      /* End (length) of CurrentLine */
67f74a3f6eSHermès Bélusca-Maïto     DWORD  nSpacePending; /* Pending spaces for TAB expansion */
68b552901dSKatayama Hirofumi MZ     DWORD iColumn;  /* The current index of column */
69b552901dSKatayama Hirofumi MZ     DWORD iLine;    /* The physical output line count of screen */
70b552901dSKatayama Hirofumi MZ     DWORD lineno;   /* The logical line number */
71c2c66affSColin Finck } CON_PAGER, *PCON_PAGER;
72c2c66affSColin Finck 
73c2c66affSColin Finck #define INIT_CON_PAGER(pScreen)     {(pScreen), 0}
74c2c66affSColin Finck 
75c2c66affSColin Finck #define InitializeConPager(pPager, pScreen)  \
76c2c66affSColin Finck do { \
77b552901dSKatayama Hirofumi MZ     ZeroMemory((pPager), sizeof(*(pPager))); \
78c2c66affSColin Finck     (pPager)->Screen = (pScreen);            \
79c2c66affSColin Finck } while (0)
80c2c66affSColin Finck 
814e697feeSHermès Bélusca-Maïto 
82f74a3f6eSHermès Bélusca-Maïto typedef BOOL
83f74a3f6eSHermès Bélusca-Maïto (__stdcall *PAGE_PROMPT)(
844aaf54e0SHermès Bélusca-Maïto     IN PCON_PAGER Pager,
854aaf54e0SHermès Bélusca-Maïto     IN DWORD Done,
864aaf54e0SHermès Bélusca-Maïto     IN DWORD Total);
87c2c66affSColin Finck 
88c2c66affSColin Finck BOOL
89c2c66affSColin Finck ConWritePaging(
90c2c66affSColin Finck     IN PCON_PAGER Pager,
91c2c66affSColin Finck     IN PAGE_PROMPT PagePrompt,
92c2c66affSColin Finck     IN BOOL StartPaging,
934aaf54e0SHermès Bélusca-Maïto     IN PCTCH szStr,
94c2c66affSColin Finck     IN DWORD len);
95c2c66affSColin Finck 
96c2c66affSColin Finck BOOL
97c2c66affSColin Finck ConPutsPaging(
98c2c66affSColin Finck     IN PCON_PAGER Pager,
99c2c66affSColin Finck     IN PAGE_PROMPT PagePrompt,
100c2c66affSColin Finck     IN BOOL StartPaging,
1014aaf54e0SHermès Bélusca-Maïto     IN PCTSTR szStr);
102c2c66affSColin Finck 
103c2c66affSColin Finck BOOL
104c2c66affSColin Finck ConResPagingEx(
105c2c66affSColin Finck     IN PCON_PAGER Pager,
106c2c66affSColin Finck     IN PAGE_PROMPT PagePrompt,
107c2c66affSColin Finck     IN BOOL StartPaging,
108c2c66affSColin Finck     IN HINSTANCE hInstance OPTIONAL,
109c2c66affSColin Finck     IN UINT uID);
110c2c66affSColin Finck 
111c2c66affSColin Finck BOOL
112c2c66affSColin Finck ConResPaging(
113c2c66affSColin Finck     IN PCON_PAGER Pager,
114c2c66affSColin Finck     IN PAGE_PROMPT PagePrompt,
115c2c66affSColin Finck     IN BOOL StartPaging,
116c2c66affSColin Finck     IN UINT uID);
117c2c66affSColin Finck 
1181e87e2faSHermès Bélusca-Maïto #ifdef __cplusplus
1191e87e2faSHermès Bélusca-Maïto }
1201e87e2faSHermès Bélusca-Maïto #endif
1214e697feeSHermès Bélusca-Maïto 
122c2c66affSColin Finck #endif  /* __PAGER_H__ */
1234e697feeSHermès Bélusca-Maïto 
1244e697feeSHermès Bélusca-Maïto /* EOF */
125