-
Notifications
You must be signed in to change notification settings - Fork 1
/
IO.h
128 lines (95 loc) · 3.07 KB
/
IO.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
/**Copyright 2012 Fabien LUCE
This file is part of Cptalk!.
Cptalk! is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
Cptalk! is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with Cptalk!. If not, see <http://www.gnu.org/licenses/>.**/
#ifndef IO_H
#define IO_H
//
// Forward declaration for dialog between Linker and ICore_XMPP
class Linker;
class Core;
class Input;
class Output;
class CpClient;
// Headers include
#include "common.h"
#include <ncurses.h>
#include <panel.h>
#include <cstring>
#include <iostream>
#include <vector>
class Terminal {
public:
Terminal();
~Terminal();
void refresh();
// pour l instant publique
unsigned int height; //nb_lignes
unsigned int width; //nb_colonnes
private:
WINDOW* window; // pointeur vers la fenetre concernee
};
// classe de base Input et Ouput
class IO {
public:
IO(unsigned int a, unsigned int b);
~IO();
virtual void draw()=0;
virtual void refresh();
virtual void reset();
virtual void add_history(Line l);
virtual void print_line(Line l,unsigned int i); //i: ligne d'affichage
virtual void push_to_display(Line l, unsigned int w); // auto format the line into several ones to fit the screen
virtual unsigned int& get_index();
virtual unsigned int get_history_size();
virtual unsigned int get_window_height();
void register_terminal(Terminal& terminal);
void refresh_terminal();
protected:
unsigned int height; //nb_lignes
unsigned int width; //nb_colonnes
unsigned int get_start_index(unsigned int final_index,unsigned int line_number);
unsigned int get_final_index(unsigned int start_index,unsigned int line_number);
unsigned int print_index; //register the index printed
WINDOW* window; // pointeur vers la fenetre concernee
PANEL* panel;
Terminal* ptr_terminal;
Buffer history;
Buffer display;
};
class Output : public IO {
public:
Output(Terminal& term);
~Output();
void draw();
void print_history(unsigned int i);
void print_history_last_n(unsigned int n); // print last n lines if possible
private:
};
class Input: public IO {
public:
Input(Terminal& term);
~Input();
void draw();
void edit(); // gather all input element and send it either to linker or to itself
bool char_analysis(int c, unsigned int& i,string& s);
bool complete(string& s,unsigned int& index);
void register_linker(Linker& linker);
void set_timeout(unsigned int t_out);
void update_roster_choice(vector<string> list_roster);
private:
Linker* ptr_linker;
void print_string(string s); //i: ligne d'affichage
unsigned int timeout;
vector<string> commands_choice;
vector<string> roster_choice;
};
#endif /* IO_H */