Line data Source code
1 : /* 2 : Mosh: the mobile shell 3 : Copyright 2012 Keith Winstein 4 : 5 : This program is free software: you can redistribute it and/or modify 6 : it under the terms of the GNU General Public License as published by 7 : the Free Software Foundation, either version 3 of the License, or 8 : (at your option) any later version. 9 : 10 : This program is distributed in the hope that it will be useful, 11 : but WITHOUT ANY WARRANTY; without even the implied warranty of 12 : MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 : GNU General Public License for more details. 14 : 15 : You should have received a copy of the GNU General Public License 16 : along with this program. If not, see <http://www.gnu.org/licenses/>. 17 : 18 : In addition, as a special exception, the copyright holders give 19 : permission to link the code of portions of this program with the 20 : OpenSSL library under certain conditions as described in each 21 : individual source file, and distribute linked combinations including 22 : the two. 23 : 24 : You must obey the GNU General Public License in all respects for all 25 : of the code used other than OpenSSL. If you modify file(s) with this 26 : exception, you may extend this exception to your version of the 27 : file(s), but you are not obligated to do so. If you do not wish to do 28 : so, delete this exception statement from your version. If you delete 29 : this exception statement from all source files in the program, then 30 : also delete it here. 31 : */ 32 : 33 : #ifndef COMPLETE_TERMINAL_HPP 34 : #define COMPLETE_TERMINAL_HPP 35 : 36 : #include <list> 37 : #include <stdint.h> 38 : 39 : #include "parser.h" 40 : #include "terminal.h" 41 : 42 : /* This class represents the complete terminal -- a UTF8Parser feeding Actions to an Emulator. */ 43 : 44 : namespace Terminal { 45 : class Complete { 46 : private: 47 : Parser::UTF8Parser parser; 48 : Terminal::Emulator terminal; 49 : Terminal::Display display; 50 : 51 : // Only used locally by act(), but kept here as a performance optimization, 52 : // to avoid construction/destruction. It must always be empty 53 : // outside calls to act() to keep horrible things from happening. 54 : Parser::Actions actions; 55 : 56 : typedef std::list< std::pair<uint64_t, uint64_t> > input_history_type; 57 : input_history_type input_history; 58 : uint64_t echo_ack; 59 : 60 : static const int ECHO_TIMEOUT = 50; /* for late ack */ 61 : 62 : public: 63 11654 : Complete( size_t width, size_t height ) : parser(), terminal( width, height ), display( false ), 64 11654 : actions(), input_history(), echo_ack( 0 ) {} 65 : 66 : std::string act( const std::string &str ); 67 : std::string act( const Parser::Action &act ); 68 : 69 35569 : const Framebuffer & get_fb( void ) const { return terminal.get_fb(); } 70 23153 : void reset_input( void ) { parser.reset_input(); } 71 31003 : uint64_t get_echo_ack( void ) const { return echo_ack; } 72 : bool set_echo_ack( uint64_t now ); 73 : void register_input_frame( uint64_t n, uint64_t now ); 74 : int wait_time( uint64_t now ) const; 75 : 76 : /* interface for Network::Transport */ 77 : void subtract( const Complete * ) const {} 78 : std::string diff_from( const Complete &existing ) const; 79 : std::string init_diff( void ) const; 80 : void apply_string( const std::string & diff ); 81 : bool operator==( const Complete &x ) const; 82 : 83 : bool compare( const Complete &other ) const; 84 : }; 85 : } 86 : 87 : #endif