logo
Free, unlimited AI code reviews that run on commit
git-lrc git-lrc GitHub Install Now We'd appreciate a star git-lrc - Free, unlimited AI code reviews that run on commit | Product Hunt git-lrc - Free, unlimited AI code reviews that run on commit | Product Hunt

FBB::OneKey - Single keystroke input, not requiring `Return’

Author

       Frank B. Brokken (f.b.brokken@rug.nl).

libbobcat-dev_6.07.01                               2005-2025                               FBB::OneKey(3bobcat)

Bobcat

       Bobcat is an acronym of `Brokken’s Own Base Classes And Templates’.

Bobcat Project Files

       o      https://fbb-git.gitlab.io/bobcat/: gitlab project page;

       Debian Bobcat project files:

       o      libbobcat6: debian package containing the shared library, changelog and copyright note;

       o      libbobcat-dev: debian package containing the static library, headers, manual pages, and  developer
              info;

Bugs

       None Reported.

Constructors

       o      OneKey(OneKey::Modestate=OneKey::OFF):
              This  constructor  initializes  the  OneKey  input  object. By default, entered characters are not
              echoed. By constructing the object with the OneKey::ON argument, entered characters are echoed  to
              the standard output stream.

              This construct throws an Exception exception if it not properly complete. The constructor may fail
              for the following reasons:

       o      the  standard  input  stream is not a tty (e.g., when the standard input stream is redirected to a
              file);

       o      the current state of the standard input stream can’t be determined;

       o      the standard input stream’s state can’t be changed to the `direct keyboard input’ mode.

       Copy and move constructors (and assignment operators) are not available.

Description

OneKey  objects  may  be used to realize `direct keyboard input’: a pressed key becomes available without
       the need for pressing Enter. The characters are obtained from the standard input stream. Direct key entry
       remains in effect for as long as the OneKey object exists. Once the  object  is  destroyed  the  standard
       input  stream  will  return  to its default mode of operation, in which input is `confirmed’ by a newline
       character.

Enumeration

       The OneKey::Mode enumeration is used to control echoing of returned characters. It has two values:

       o      OFF: returned characters are not echoed to the standard output stream;

       o      ON: returned characters are echoed to the standard output stream.

Example

       /*
                                     driver.cc
       */

       #include <iostream>
       #include <string>
       #include <bobcat/onekey>

       using namespace std;
       using namespace FBB;

       int main()
       {
           try
           {
               OneKey onekey;

               cout << "Usage: 1: next chars are echoed, 0: no echo, q: quits\n";

               while (true)
               {
                   char c;

                   cout << "ready...\n";
                   cout << "Got character ’" << (c = onekey.get()) << "’\n";

                   switch (c)
                   {
                       case ’1’:
                           onekey.setEcho(OneKey::ON);
                       break;

                       case ’0’:
                           onekey.setEcho(OneKey::OFF);
                       break;

                       case ’q’:
                       return 0;
                   }
               }
           }
           catch (exception const &e)
           {
               cout << e.what() << endl;
               return 1;
           }
       }

Files

bobcat/onekey - defines the class interface

Inherits From

       -

Member Functions

       o      intget()const:
              Returns the next character from the standard input stream, without the need for pressing Enter.

       o      voidsetEcho(OneKey::Modestate):
              Changes the echo-state of the OneKey object. The argument may be either OneKey::ON or OneKey::OFF.

Name

       FBB::OneKey - Single keystroke input, not requiring `Return’

Namespace

FBB
       All constructors, members, operators and manipulators, mentioned in this man-page,  are  defined  in  the
       namespace FBB.

See Also

bobcat(7), tty(3bobcat)

Synopsis

#include<bobcat/onekey>
       Linking option: -lbobcat

See Also