Jpp  19.1.0-rc.1
the software that should make you happy
Public Member Functions | Private Member Functions | Private Attributes | List of all members
JSYSTEM::JKeypress Class Reference

Enable unbuffered terminal input. More...

#include <JKeypress.hh>

Public Member Functions

 JKeypress (const bool echo=true)
 Constructor. More...
 
 ~JKeypress ()
 Destructor. More...
 
char get ()
 Get single character. More...
 
bool timeout (JTimeval timeout)
 Timeout method. More...
 

Private Member Functions

 JKeypress (const JKeypress &)
 
 JKeypress (JKeypress &&)
 
JKeypressoperator= (const JKeypress &)
 
JKeypressoperator= (JKeypress &&)
 

Private Attributes

termios termcap
 
JFileDescriptorMask mask
 

Detailed Description

Enable unbuffered terminal input.

Definition at line 32 of file JKeypress.hh.

Constructor & Destructor Documentation

◆ JKeypress() [1/3]

JSYSTEM::JKeypress::JKeypress ( const bool  echo = true)
inline

Constructor.

The settings are modified by the constructor and the original settings are reset by the destructor.

Parameters
echoenable/disable echo of input character

Definition at line 42 of file JKeypress.hh.

43  {
44  tcgetattr(STDIN_FILENO, &termcap);
45 
46  termios buffer = termcap;
47 
48  // Disable canonical mode, and set buffer size to 1 byte.
49 
50  buffer.c_lflag &= ~ICANON;
51  buffer.c_lflag &= (echo ? ECHO : ~ECHO);
52  buffer.c_cc[VTIME] = 0;
53  buffer.c_cc[VMIN] = 1;
54 
55  tcsetattr(STDIN_FILENO, TCSANOW, &buffer);
56  }

◆ ~JKeypress()

JSYSTEM::JKeypress::~JKeypress ( )
inline

Destructor.

Definition at line 62 of file JKeypress.hh.

63  {
64  tcsetattr(STDIN_FILENO, TCSANOW, &termcap);
65  }

◆ JKeypress() [2/3]

JSYSTEM::JKeypress::JKeypress ( const JKeypress )
private

◆ JKeypress() [3/3]

JSYSTEM::JKeypress::JKeypress ( JKeypress &&  )
private

Member Function Documentation

◆ get()

char JSYSTEM::JKeypress::get ( )
inline

Get single character.

This method returns as soon as input from terminal is available.

Returns
character

Definition at line 74 of file JKeypress.hh.

75  {
76  char c;
77 
78  ::read(STDIN_FILENO, &c, 1);
79 
80  return c;
81  }
std::istream & read(std::istream &in, JTestSummary &summary, const char delimiter=' ')
Read test summary.

◆ timeout()

bool JSYSTEM::JKeypress::timeout ( JTimeval  timeout)
inline

Timeout method.

This method returns immediatly if input from terminal is available, else after the specified timeout period.

Parameters
timeouttimeout
Returns
true if input available; else false

Definition at line 92 of file JKeypress.hh.

93  {
94  mask.set(STDIN_FILENO);
95 
96  return mask.in_avail(timeout);
97  }
void set(const int file_descriptor)
Set file descriptor.
bool in_avail(JTimeval timeout=JTimeval::min())
Check availability of input.
bool timeout(JTimeval timeout)
Timeout method.
Definition: JKeypress.hh:92
JFileDescriptorMask mask
Definition: JKeypress.hh:102

◆ operator=() [1/2]

JKeypress& JSYSTEM::JKeypress::operator= ( const JKeypress )
private

◆ operator=() [2/2]

JKeypress& JSYSTEM::JKeypress::operator= ( JKeypress &&  )
private

Member Data Documentation

◆ termcap

termios JSYSTEM::JKeypress::termcap
private

Definition at line 101 of file JKeypress.hh.

◆ mask

JFileDescriptorMask JSYSTEM::JKeypress::mask
private

Definition at line 102 of file JKeypress.hh.


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