126 lines
3.9 KiB
C++
126 lines
3.9 KiB
C++
//! \file piterminal.h
|
|
//! \ingroup Console
|
|
//! \brief
|
|
//! \~english Virtual terminal
|
|
//! \~russian Виртуальный терминал
|
|
//! \details
|
|
//! \~english Provides terminal emulation for reading console input and output.
|
|
//! \~russian Обеспечивает эмуляцию терминала для чтения ввода и вывода консоли.
|
|
/*
|
|
PIP - Platform Independent Primitives
|
|
Virtual terminal
|
|
Ivan Pelipenko peri4ko@yandex.ru
|
|
|
|
This program is free software: you can redistribute it and/or modify
|
|
it under the terms of the GNU Lesser General Public License as published by
|
|
the Free Software Foundation, either version 3 of the License, or
|
|
(at your option) any later version.
|
|
|
|
This program 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 Lesser General Public License for more details.
|
|
|
|
You should have received a copy of the GNU Lesser General Public License
|
|
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
*/
|
|
|
|
#ifndef PITERMINAL_H
|
|
#define PITERMINAL_H
|
|
|
|
#include "pikbdlistener.h"
|
|
#include "pip_console_export.h"
|
|
#include "piscreentypes.h"
|
|
|
|
|
|
class PIP_CONSOLE_EXPORT PITerminal: public PIThread {
|
|
PIOBJECT_SUBCLASS(PITerminal, PIThread);
|
|
|
|
public:
|
|
//! \brief
|
|
//! \~english Constructs PITerminal
|
|
//! \~russian Создает PITerminal
|
|
PITerminal();
|
|
|
|
//! \brief
|
|
//! \~english Destructor
|
|
//! \~russian Деструктор
|
|
~PITerminal();
|
|
|
|
//! \brief
|
|
//! \~english Returns number of columns
|
|
//! \~russian Возвращает количество колонок
|
|
int columns() const { return size_x; }
|
|
|
|
//! \brief
|
|
//! \~english Returns number of rows
|
|
//! \~russian Возвращает количество строк
|
|
int rows() const { return size_y; }
|
|
|
|
//! \brief
|
|
//! \~english Resizes terminal
|
|
//! \~russian Изменяет размер терминала
|
|
//! \param cols Number of columns / Количество колонок
|
|
//! \param rows Number of rows / Количество строк
|
|
bool resize(int cols, int rows);
|
|
|
|
//! \brief
|
|
//! \~english Writes data to terminal
|
|
//! \~russian Записывает данные в терминал
|
|
void write(const PIByteArray & d);
|
|
|
|
//! \brief
|
|
//! \~english Writes special key to terminal
|
|
//! \~russian Записывает специальную клавишу в терминал
|
|
void write(PIKbdListener::SpecialKey k, PIKbdListener::KeyModifiers m);
|
|
|
|
//! \brief
|
|
//! \~english Writes key event to terminal
|
|
//! \~russian Записывает событие клавиши в терминал
|
|
void write(PIKbdListener::KeyEvent ke);
|
|
|
|
//! \brief
|
|
//! \~english Returns terminal content
|
|
//! \~russian Возвращает содержимое терминала
|
|
PIVector<PIVector<PIScreenTypes::Cell>> content();
|
|
|
|
//! \brief
|
|
//! \~english Checks if key is special
|
|
//! \~russian Проверяет, является ли клавиша специальной
|
|
static bool isSpecialKey(int k);
|
|
|
|
//! \brief
|
|
//! \~english Initializes terminal
|
|
//! \~russian Инициализирует терминал
|
|
bool initialize();
|
|
|
|
//! \brief
|
|
//! \~english Destroys terminal
|
|
//! \~russian Уничтожает терминал
|
|
void destroy();
|
|
|
|
private:
|
|
void initPrivate();
|
|
void readConsole();
|
|
void getCursor(int & x, int & y);
|
|
uchar invertColor(uchar c);
|
|
void run() override;
|
|
#ifndef WINDOWS
|
|
void parseInput(const PIString & s);
|
|
bool isCompleteEscSeq(const PIString & es);
|
|
void applyEscSeq(PIString es);
|
|
void moveCursor(int dx, int dy);
|
|
int termType(const PIString & t);
|
|
#endif
|
|
|
|
PRIVATE_DECLARATION(PIP_CONSOLE_EXPORT)
|
|
int dsize_x, dsize_y;
|
|
int size_x, size_y, cursor_x, cursor_y;
|
|
bool cursor_blink, cursor_visible;
|
|
PITimeMeasurer cursor_tm;
|
|
PIVector<PIVector<PIScreenTypes::Cell>> cells;
|
|
};
|
|
|
|
|
|
#endif // PITERMINAL_H
|