Fixed the terminal not fully functional error
[utio.git] / kb.h
blob4efffb5eea7edb585d0954ea517465495e415ed4
1 // This file is part of the utio library, a terminal I/O library.
2 //
3 // Copyright (C) 2004 by Mike Sharov <msharov@users.sourceforge.net>
4 // This file is free software, distributed under the MIT License.
5 //
6 // kb.h
7 //
9 #ifndef KB_H_70C9E93B05A3B0D527D942E351FEEE4B
10 #define KB_H_70C9E93B05A3B0D527D942E351FEEE4B
12 #include "ti.h"
13 #include <termios.h>
15 namespace utio {
17 /// \class CKeyboard kb.h utio/kb.h
18 ///
19 /// \brief Keyboard code preprocessor for terminals.
20 ///
21 /// Takes raw codes from the input port and translates them into keycode events.
22 ///
23 class CKeyboard {
24 public:
25 typedef CTerminfo::keystrings_t keymap_t;
26 public:
27 CKeyboard (void);
28 ~CKeyboard (void);
29 void Open (const CTerminfo& rti);
30 void Close (void);
31 void EnterUIMode (void);
32 void LeaveUIMode (void);
33 wchar_t DecodeKey (istream& is) const;
34 inline bool IsInUIMode (void) const { return (s_bTermInUIMode); }
35 inline void LoadKeymap (const CTerminfo& rti) { rti.LoadKeystrings (m_Keymap); }
36 wchar_t GetKey (bool bBlock = true) const;
37 bool WaitForKeyData (long timeout = 0) const;
38 private:
39 void ReadKeyData (void) const;
40 private:
41 keymap_t m_Keymap; ///< Currently loaded keymap.
42 mutable string m_Keydata; ///< Buffered keydata.
43 struct termios m_InitialTermios; ///< What it was before we munged it.
44 static bool s_bTermInUIMode; ///< Current terminal state, static because the terminal is process-global.
47 } // namespace utio
49 #endif