Jpp  17.0.0-rc.1
the software that should make you happy
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
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

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  }
then echo
JSYSTEM::JKeypress::~JKeypress ( )
inline

Destructor.

Definition at line 62 of file JKeypress.hh.

63  {
64  tcsetattr(STDIN_FILENO, TCSANOW, &termcap);
65  }
JSYSTEM::JKeypress::JKeypress ( const JKeypress )
private
JSYSTEM::JKeypress::JKeypress ( JKeypress &&  )
private

Member Function Documentation

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.
$WORKDIR ev_configure_domsimulator txt echo process $DOM_SIMULATOR $i $SOURCE_HOST[$index] csh c(setenv ROOTSYS $ROOTSYS &&source $JPP_DIR/setenv.csh $JPP_DIR &&($DOM_SIMULATOR\-u\$NAME\$\-H\$SERVER\$\-M\$LOGGER\$\-d $DEBUG</dev/null > &/dev/null &))'
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  }
bool timeout(JTimeval timeout)
Timeout method.
Definition: JKeypress.hh:92
void set(const int file_descriptor)
Set file descriptor.
JFileDescriptorMask mask
Definition: JKeypress.hh:102
bool in_avail(JTimeval timeout=JTimeval::min())
Check availability of input.
JKeypress& JSYSTEM::JKeypress::operator= ( const JKeypress )
private
JKeypress& JSYSTEM::JKeypress::operator= ( JKeypress &&  )
private

Member Data Documentation

termios JSYSTEM::JKeypress::termcap
private

Definition at line 101 of file JKeypress.hh.

JFileDescriptorMask JSYSTEM::JKeypress::mask
private

Definition at line 102 of file JKeypress.hh.


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