Parse key escape sequences. More...

#include <senf/Utils/Termlib/Terminfo.hh>

Public Types

enum  KeyCode {
  Space = ' ', Tab = '\t', Return = '\r', First = 0xE000,
  Esc = First, Backspace, Backtab, Begin,
  CATab, CTab, Cancel, Center,
  Clear, ClearToEOL, ClearToEOS, Close,
  Command, Copy, Create, Delete,
  DeleteLine, Down, DownLeft, DownRight,
  End, Enter, Exit, F0,
  F1, F2, F3, F4,
  F5, F6, F7, F8,
  F9, F10, F11, F12,
  F13, F14, F15, F16,
  F17, F18, F19, F20,
  F21, F22, F23, F24,
  F25, F26, F27, F28,
  F29, F30, F31, F32,
  F33, F34, F35, F36,
  F37, F38, F39, F40,
  F41, F42, F43, F44,
  F45, F46, F47, F48,
  F49, F50, F51, F52,
  F53, F54, F55, F56,
  F57, F58, F59, F60,
  F61, F62, F63, Find,
  Help, Home, Insert, InsertLine,
  Left, Mark, Message, Mouse,
  Move, Next, Open, Options,
  PageDown, PageUp, Previous, Print,
  Redo, Reference, Refresh, Replace,
  Restart, Resume, Right, Save,
  Select, ShiftBegin, ShiftCancel, ShiftCommand,
  ShiftCopy, ShiftCreate, ShiftDelete, ShiftDeleteLine,
  ShiftEnd, ShiftClearToEOL, ShiftExit, ShiftFind,
  ShiftHelp, ShiftHome, ShiftInsert, ShiftLeft,
  ShiftMessage, ShiftMove, ShiftNext, ShiftOptions,
  ShiftPrevious, ShiftPrint, ShiftRedo, ShiftReplace,
  ShiftResume, ShiftRight, ShiftSave, ShiftSuspend,
  ShiftTab, ShiftUndo, Suspend, Undo,
  Up, UpLeft, UpRight, Incomplete = 0xE0FF
}
 Special keyboard key codes. More...
 
typedef wchar_t keycode_t
 Key code data type. More...
 
typedef std::string::size_type size_type
 String length type. More...
 

Public Member Functions

 KeyParser ()
 
 KeyParser (Terminfo const &ti)
 Load keymap information from ti. More...
 
void load (Terminfo const &ti)
 Load keymap information from ti. More...
 
std::pair< keycode_t, size_typelookup (std::string const &key) const
 Lookup up string key. More...
 
void dump (std::ostream &os) const
 Dump keymap for debug purposes. More...
 

Static Public Member Functions

static keycode_t Ctrl (char ch)
 Helper to convert uppercase char to Control key code. More...
 
static std::string describe (keycode_t key)
 Return descriptive, printable key name. More...
 

Static Public Attributes

static char const *const KeyNames []
 Special key code names. More...
 

Detailed Description

Parse key escape sequences.

The KeyParser will read the relevant properties from a terminfo entry and then provides functions to parser keyboard escape sequences.

All keys are returned as keyboard code's. Values 0 to 255 represent ordinary ASCII characters, larger values are special keys taken from the KeyCode enum

Definition at line 236 of file Terminfo.hh.

Member Typedef Documentation

◆ keycode_t

Key code data type.

Definition at line 263 of file Terminfo.hh.

◆ size_type

typedef std::string::size_type senf::term::KeyParser::size_type

String length type.

Definition at line 264 of file Terminfo.hh.

Member Enumeration Documentation

◆ KeyCode

Special keyboard key codes.

Enumerator
Space 
Tab 
Return 
First 
Esc 
Backspace 
Backtab 
Begin 
CATab 
CTab 
Cancel 
Center 
Clear 
ClearToEOL 
ClearToEOS 
Close 
Command 
Copy 
Create 
Delete 
DeleteLine 
Down 
DownLeft 
DownRight 
End 
Enter 
Exit 
F0 
F1 
F2 
F3 
F4 
F5 
F6 
F7 
F8 
F9 
F10 
F11 
F12 
F13 
F14 
F15 
F16 
F17 
F18 
F19 
F20 
F21 
F22 
F23 
F24 
F25 
F26 
F27 
F28 
F29 
F30 
F31 
F32 
F33 
F34 
F35 
F36 
F37 
F38 
F39 
F40 
F41 
F42 
F43 
F44 
F45 
F46 
F47 
F48 
F49 
F50 
F51 
F52 
F53 
F54 
F55 
F56 
F57 
F58 
F59 
F60 
F61 
F62 
F63 
Find 
Help 
Home 
Insert 
InsertLine 
Left 
Mark 
Message 
Mouse 
Move 
Next 
Open 
Options 
PageDown 
PageUp 
Previous 
Print 
Redo 
Reference 
Refresh 
Replace 
Restart 
Resume 
Right 
Save 
Select 
ShiftBegin 
ShiftCancel 
ShiftCommand 
ShiftCopy 
ShiftCreate 
ShiftDelete 
ShiftDeleteLine 
ShiftEnd 
ShiftClearToEOL 
ShiftExit 
ShiftFind 
ShiftHelp 
ShiftHome 
ShiftInsert 
ShiftLeft 
ShiftMessage 
ShiftMove 
ShiftNext 
ShiftOptions 
ShiftPrevious 
ShiftPrint 
ShiftRedo 
ShiftReplace 
ShiftResume 
ShiftRight 
ShiftSave 
ShiftSuspend 
ShiftTab 
ShiftUndo 
Suspend 
Undo 
Up 
UpLeft 
UpRight 
Incomplete 

Definition at line 243 of file Terminfo.hh.

Constructor & Destructor Documentation

◆ KeyParser() [1/2]

senf::term::KeyParser::KeyParser ( )

Definition at line 501 of file Terminfo.cc.

◆ KeyParser() [2/2]

senf::term::KeyParser::KeyParser ( Terminfo const &  ti)
explicit

Load keymap information from ti.

Definition at line 504 of file Terminfo.cc.

Member Function Documentation

◆ Ctrl()

static keycode_t senf::term::KeyParser::Ctrl ( char  ch)
inlinestatic

Helper to convert uppercase char to Control key code.

Definition at line 267 of file Terminfo.hh.

◆ describe()

std::string senf::term::KeyParser::describe ( keycode_t  key)
static

Return descriptive, printable key name.

Definition at line 604 of file Terminfo.cc.

◆ dump()

void senf::term::KeyParser::dump ( std::ostream &  os) const

Dump keymap for debug purposes.

Definition at line 616 of file Terminfo.cc.

◆ load()

void senf::term::KeyParser::load ( Terminfo const &  ti)

Load keymap information from ti.

Definition at line 509 of file Terminfo.cc.

◆ lookup()

std::pair< senf::term::KeyParser::keycode_t, std::string::size_type > senf::term::KeyParser::lookup ( std::string const &  key) const

Lookup up string key.

This call will look up the string in key in the keymap. The return value is a pair.

  • the first value is the key code
  • the second value is the number of characters in key which have been interpreted and returned in the first value

If key is not a complete key sequence, the return key code will be the Invalid value and the returned escape sequence size will be 0.

If key does not start with an escape sequence, the returned key code will be the first character from key and the escape sequence size will be 1.

Otherwise key starts with a complete escape sequence. The returned key code will be a value from the KeyCode enum and the escape sequence size will be returned accordingly.

Definition at line 579 of file Terminfo.cc.

Member Data Documentation

◆ KeyNames

char const *const senf::term::KeyParser::KeyNames
static

Special key code names.

Definition at line 261 of file Terminfo.hh.


The documentation for this class was generated from the following files: