CLI  2.9
ui_text.h
Go to the documentation of this file.
1 /*
2  Copyright (c) 2006-2018, Alexis Royer, http://alexis.royer.free.fr/CLI
3 
4  All rights reserved.
5 
6  Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:
7 
8  * Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.
9  * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation
10  and/or other materials provided with the distribution.
11  * Neither the name of the CLI library project nor the names of its contributors may be used to endorse or promote products derived from this software
12  without specific prior written permission.
13 
14  THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
15  "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
16  LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
17  A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
18  CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
19  EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
20  PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
21  PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
22  LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
23  NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
24  SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
25 */
26 
27 
31 
32 #ifndef _CLI_UI_TEXT_H_
33 #define _CLI_UI_TEXT_H_
34 
35 #include "cli/io_device.h"
36 
37 
39 
40  CLI_NS_BEGIN(ui)
41 
42  // Forward declarations.
43  class TextIterator;
44 
45 
47  class Text : public OutputDevice
48  {
49  public:
51  explicit Text(
52  const unsigned int UI_MaxLines,
53  const unsigned int UI_MaxLineLength
54  );
55 
57  virtual ~Text(void);
58 
59  private:
61  explicit Text(void);
63  Text(const Text&);
65  Text& operator=(const Text&);
66 
67  // cli::OutputDevice interface implementation.
68  protected:
69  virtual const bool OpenDevice(void);
70  virtual const bool CloseDevice(void);
71  public:
72  // Inherit doxygen comments from cli::OutputDevice interface documentation.
73  virtual void PutString(const char* const STR_Out) const;
74  // Inherit doxygen comments from cli::OutputDevice interface documentation.
75  virtual void Beep(void) const;
76  // Inherit doxygen comments from cli::OutputDevice interface documentation.
77  virtual void CleanScreen(void) const;
78  // Inherit doxygen comments from cli::OutputDevice interface documentation.
79  virtual const bool WouldOutput(const OutputDevice& CLI_Device) const;
80 
81  public:
83  void Begin(
84  TextIterator& it
85  ) const;
86 
89  const bool PageUp(
90  TextIterator& it
91  ) const;
92 
95  const bool LineUp(
96  TextIterator& it
97  ) const;
98 
101  const bool LineDown(
102  TextIterator& it,
103  const OutputDevice* const PCLI_Out
104  ) const;
105 
108  const bool PageDown(
109  TextIterator& it,
110  const OutputDevice* const PCLI_Out
111  ) const;
112 
114  void End(
115  TextIterator& it,
116  const OutputDevice* const PCLI_Out
117  ) const;
118 
119  public:
123  void PrintPage(
124  TextIterator& it,
125  const OutputDevice& CLI_Out,
126  const bool B_FillPageWithBlankLines
127  ) const;
128 
129  private:
133  void PrintBottomLine(
134  TextIterator& it,
135  const OutputDevice& CLI_Out
136  ) const;
137 
138  private:
139  mutable tk::Queue<tk::String> m_tkLines;
140  mutable bool m_bNewLineRequired;
141  const unsigned int m_uiMaxLineLength;
142  };
143 
146  {
147  private:
149  explicit TextIterator(void);
150 
151  public:
153  explicit TextIterator(
154  const OutputDevice::ScreenInfo& CLI_ScreenInfo,
155  const unsigned int UI_PageHeight
156  );
157 
159  explicit TextIterator(
160  const TextIterator& it
161  );
162 
166  const TextIterator& it
167  );
168 
169  private:
170  const OutputDevice::ScreenInfo m_cliScreenInfo;
171  const unsigned int m_uiPageHeight;
172 
173  tk::Queue<tk::String>::Iterator m_tkTopLine;
174  unsigned int m_uiTopChar;
175  tk::Queue<tk::String>::Iterator m_tkBottomLine;
176  unsigned int m_uiBottomChar;
177  bool m_bBottomIsUpToDate;
178 
179  friend class Text;
180  };
181 
182  CLI_NS_END(ui)
183 
185 
186 #endif // _CLI_UI_TEXT_H_
Main namespace of the CLI library.
TextIterator & operator=(const TextIterator &it)
Assignment operator.
void Begin(TextIterator &it) const
Retrieves a text head iterator.
Definition: ui_text.cpp:105
virtual const bool WouldOutput(const OutputDevice &CLI_Device) const
Stack overflow protection.
Definition: ui_text.cpp:95
#define CLI_NS_END(__ns)
End a namespace definition.
Definition: namespace.h:45
virtual const bool CloseDevice(void)
Device closure handler.
Definition: ui_text.cpp:53
virtual void Beep(void) const
Beep handler.
Definition: ui_text.cpp:83
virtual void CleanScreen(void) const
Clean screen.
Definition: ui_text.cpp:88
Screen information.
Definition: io_device.h:461
const bool PageUp(TextIterator &it) const
Moves iterator one page up.
Definition: ui_text.cpp:113
virtual void PutString(const char *const STR_Out) const
Output handler.
Definition: ui_text.cpp:58
virtual const bool OpenDevice(void)
Device opening handler.
Definition: ui_text.cpp:48
Generic output device.
Definition: io_device.h:256
void End(TextIterator &it, const OutputDevice *const PCLI_Out) const
Retrieves a text end iterator.
Definition: ui_text.cpp:235
#define CLI_NS_BEGIN(__ns)
Begin a namespace definition.
Definition: namespace.h:38
const bool LineDown(TextIterator &it, const OutputDevice *const PCLI_Out) const
Moves iterator one line down.
Definition: ui_text.cpp:177
OutputDevice, IODevice and IOEndl classes defintion.
const bool LineUp(TextIterator &it) const
Moves iterator one line up.
Definition: ui_text.cpp:128
const bool PageDown(TextIterator &it, const OutputDevice *const PCLI_Out) const
Moves iterator one page down.
Definition: ui_text.cpp:220
Text iterator class.
Definition: ui_text.h:145
virtual ~Text(void)
Destructor.
Definition: ui_text.cpp:44
Simple line user interface object.
Definition: ui_text.h:47
void PrintPage(TextIterator &it, const OutputDevice &CLI_Out, const bool B_FillPageWithBlankLines) const
Print out a page of text.
Definition: ui_text.cpp:241