Disk ARchive  2.5.2
Full featured and portable backup and archiving tool
shell_interaction.hpp
Go to the documentation of this file.
00001 /*********************************************************************/
00002 // dar - disk archive - a backup/restoration program
00003 // Copyright (C) 2002-2052 Denis Corbin
00004 //
00005 // This program is free software; you can redistribute it and/or
00006 // modify it under the terms of the GNU General Public License
00007 // as published by the Free Software Foundation; either version 2
00008 // of the License, or (at your option) any later version.
00009 //
00010 // This program is distributed in the hope that it will be useful,
00011 // but WITHOUT ANY WARRANTY; without even the implied warranty of
00012 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00013 // GNU General Public License for more details.
00014 //
00015 // You should have received a copy of the GNU General Public License
00016 // along with this program; if not, write to the Free Software
00017 // Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
00018 //
00019 // to contact the author : http://dar.linux.free.fr/email.html
00020 /*********************************************************************/
00021 
00025 
00026 
00027 #ifndef SHELL_INTERACTION_HPP
00028 #define SHELL_INTERACTION_HPP
00029 
00030 extern "C"
00031 {
00032 #if HAVE_TERMIOS_H
00033 #include <termios.h>
00034 #endif
00035 } // end extern "C"
00036 
00037 #include "../my_config.h"
00038 #include <iostream>
00039 
00040 #include "user_interaction.hpp"
00041 
00042 using namespace std;
00043 using namespace libdar;
00044 
00047 
00048 class shell_interaction : public user_interaction_callback
00049 {
00050 public:
00058     shell_interaction(ostream *out, ostream *interact, bool silent);
00059 
00061     shell_interaction(const shell_interaction & ref);
00062 
00064     ~shell_interaction();
00065 
00066     void change_non_interactive_output(ostream *out);
00067     void read_char(char & a);
00068     void set_beep(bool mode) { beep = mode; };
00069 
00070 
00072     virtual user_interaction *clone() const { user_interaction *ret = new (get_pool()) shell_interaction(*this); if(ret == nullptr) throw Ememory("shell_interaction::clone"); return ret; };
00073 
00074 private:
00075     // data type
00076 
00077     enum mode { m_initial, m_inter, m_noecho };
00078 
00079     // object fields and methods
00080 
00081     S_I input;               //< filedescriptor to read from the user's answers
00082     ostream *output;         //< holds the destination for non interactive messages
00083     ostream *inter;          //< holds the destination for interactive messages
00084     bool beep;               //< whether to issue bell char before displaying a new interactive message
00085     termios initial;         //< controlling terminal configuration when the object has been created
00086     termios interaction;     //< controlling terminal configuration to use when requiring user interaction
00087     termios initial_noecho;  //< controlling terminal configuration to use when noecho has been requested
00088     bool has_terminal;       //< true if a terminal could be found
00089 
00090     void set_term_mod(mode m);
00091 
00092     // class fields and methods
00093 
00094     static const U_I bufsize;
00095 
00096     static bool interaction_pause(const string &message, void *context);
00097     static void interaction_warning(const string & message, void *context);
00098     static string interaction_string(const string & message, bool echo, void *context);
00099     static secu_string interaction_secu_string(const string & message, bool echo, void *context);
00100 };
00101 
00103 
00104 #endif
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Defines