-
Notifications
You must be signed in to change notification settings - Fork 76
/
terminal-canvas.h
63 lines (48 loc) · 2.03 KB
/
terminal-canvas.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
// -*- mode: c ; c-basic-offset: 4; indent-tabs-mode: nil; -*-
// (c) 2016 Henner Zeller <[email protected]>
//
// This program 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 version 2.
//
// 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 General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with this program. If not, see <http://gnu.org/licenses/gpl-2.0.txt>
#ifndef TERMINAL_CANVAS_H_
#define TERMINAL_CANVAS_H_
#include <string>
#include "buffered-write-sequencer.h"
#include "framebuffer.h"
#include "timg-time.h"
namespace timg {
// Canvas that can send a framebuffer to a terminal.
class TerminalCanvas {
public:
// Create a terminal canvas, sending to given file-descriptor.
explicit TerminalCanvas(BufferedWriteSequencer *write_sequencer);
TerminalCanvas(const TerminalCanvas &) = delete;
virtual ~TerminalCanvas();
virtual int cell_height_for_pixels(int pixels) const = 0;
// Send frame to terminal. Move to xposition (relative to the left
// of the screen, and delta y (relative to the current position) first.
virtual void Send(int x, int dy, const Framebuffer &framebuffer,
SeqType sequence_type, Duration end_of_frame) = 0;
// The following methods add content that is emitted before the next Send()
void AddPrefixNextSend(const char *data, int len);
void ClearScreen();
void CursorOff();
void CursorOn();
void MoveCursorDY(int rows); // -: up^, : downV
void MoveCursorDX(int cols); // -: <-left, : right->
protected:
char *AppendPrefixToBuffer(char *buffer);
BufferedWriteSequencer *const write_sequencer_; // not owned
private:
std::string prefix_send_;
};
} // namespace timg
#endif // TERMINAL_CANVAS_H_