summaryrefslogtreecommitdiff
path: root/multilog.h
blob: 3c411f21b11cce2526c3eaca92b0b30811a635f7 (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
#pragma once

#include <vector>
#include <string_view>
#include <mutex>

using namespace std;


// Access is thread-safe
class MultiLog {
	struct Item {
		int id;
		string line;
		bool complete = false;

		Item();
	};

	mutex mut;
	vector<Item> items;
	const bool fancy;

	// Methods assume mutex is taken.
	size_t findId(int id);
	void redrawLine(size_t idx);

public:
	MultiLog(bool fancy);

	// Returns id of new item
	int add(const string_view prefix);
	void append(int id, const string_view text);
	void complete(int id);
};