summaryrefslogtreecommitdiff
path: root/buffer.h
blob: 119097e4501bc31df85c5b9f5fa2d641f9676255 (plain)
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
#pragma once

#include <string>

#include "command.h"
#include "textblob.h"

using namespace std;


//Everything is zero-based.

class Manager;

class Buffer{
	struct Cell{
		char c;
		bool special;
		i64 linex; //position in line
	};
	struct ScreenLine{
		i64 line,part; //part: n'th screen line of the logical line `line`
		i64 fromx; //starting at what x into the line does this screen line have text
		vector<Cell> cells;
	};

	struct Cursorpos{
		i64 line,x;
	};

	struct Screenpos{
		i64 y,x;
	};

	Manager *const manager;
	const bool singleLineMode=false;

	TextBlob tb;

	vector<ScreenLine> screen;
	i64 lastWidth=-1,lastHeight=-1; //excluding the gutter

	Cursorpos cursor={0,0};

	vector<ScreenLine> layoutLine(const string &line,i64 linenum,i64 width);
	void performInitialLayout(i64 width,i64 height);
	void renewLayout(i64 topLine,i64 topPart,i64 width,i64 height);
	void relayoutScreen();
	void scrollUp();

	Screenpos findCursorInScreen() const;

	void handleCommand(const Command &cmd);

public:
	string filename;

	Buffer(Manager *manager);
	Buffer(Manager *manager,bool singleLineMode);

	void receive(const Command &cmd);
	void show(i64 atx,i64 aty,i64 width,i64 height);

	string getText() const;
};