Reactos
1/*
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-2021 Hermes Belusca-Maito
6 * Copyright 2021 Katayama Hirofumi MZ
7 */
8
9/**
10 * @file pager.h
11 * @ingroup ConUtils
12 *
13 * @brief Console/terminal paging functionality.
14 **/
15
16#ifndef __PAGER_H__
17#define __PAGER_H__
18
19#pragma once
20
21#ifndef _UNICODE
22#error The ConUtils library at the moment only supports compilation with _UNICODE defined!
23#endif
24
25#ifdef __cplusplus
26extern "C" {
27#endif
28
29// #include <wincon.h>
30
31struct _CON_PAGER;
32
33typedef BOOL
34(__stdcall *CON_PAGER_LINE_FN)(
35 IN OUT struct _CON_PAGER *Pager,
36 IN PCTCH line,
37 IN DWORD cch);
38
39/* Flags for CON_PAGER */
40#define CON_PAGER_EXPAND_TABS (1 << 0)
41#define CON_PAGER_EXPAND_FF (1 << 1)
42// Whether or not the pager will cache the line if it's incomplete (not NEWLINE-terminated).
43#define CON_PAGER_CACHE_INCOMPLETE_LINE (1 << 2)
44
45typedef struct _CON_PAGER
46{
47 /* Console screen properties */
48 PCON_SCREEN Screen;
49 DWORD PageColumns;
50 DWORD PageRows;
51
52 /* Paging parameters */
53 CON_PAGER_LINE_FN PagerLine; /* The line function */
54 DWORD dwFlags; /* The CON_PAGER_... flags */
55 LONG nTabWidth;
56 DWORD ScrollRows;
57
58 /* Data buffer */
59 PCTCH CachedLine; /* Cached line, HeapAlloc'ated */
60 SIZE_T cchCachedLine; /* Its length (number of characters) */
61 SIZE_T ich; /* The current index of character in TextBuff (a user-provided source buffer) */
62
63 /* Paging state */
64 PCTCH CurrentLine; /* Pointer to the current line (either within a user-provided source buffer, or to CachedLine) */
65 SIZE_T ichCurr; /* The current index of character in CurrentLine */
66 SIZE_T iEndLine; /* End (length) of CurrentLine */
67 DWORD nSpacePending; /* Pending spaces for TAB expansion */
68 DWORD iColumn; /* The current index of column */
69 DWORD iLine; /* The physical output line count of screen */
70 DWORD lineno; /* The logical line number */
71} CON_PAGER, *PCON_PAGER;
72
73#define INIT_CON_PAGER(pScreen) {(pScreen), 0}
74
75#define InitializeConPager(pPager, pScreen) \
76do { \
77 ZeroMemory((pPager), sizeof(*(pPager))); \
78 (pPager)->Screen = (pScreen); \
79} while (0)
80
81
82typedef BOOL
83(__stdcall *PAGE_PROMPT)(
84 IN PCON_PAGER Pager,
85 IN DWORD Done,
86 IN DWORD Total);
87
88BOOL
89ConWritePaging(
90 IN PCON_PAGER Pager,
91 IN PAGE_PROMPT PagePrompt,
92 IN BOOL StartPaging,
93 IN PCTCH szStr,
94 IN DWORD len);
95
96BOOL
97ConPutsPaging(
98 IN PCON_PAGER Pager,
99 IN PAGE_PROMPT PagePrompt,
100 IN BOOL StartPaging,
101 IN PCTSTR szStr);
102
103BOOL
104ConResPagingEx(
105 IN PCON_PAGER Pager,
106 IN PAGE_PROMPT PagePrompt,
107 IN BOOL StartPaging,
108 IN HINSTANCE hInstance OPTIONAL,
109 IN UINT uID);
110
111BOOL
112ConResPaging(
113 IN PCON_PAGER Pager,
114 IN PAGE_PROMPT PagePrompt,
115 IN BOOL StartPaging,
116 IN UINT uID);
117
118#ifdef __cplusplus
119}
120#endif
121
122#endif /* __PAGER_H__ */
123
124/* EOF */