summaryrefslogtreecommitdiff
path: root/src/history.cpp
blob: d625cca7521de49df3511991f5406efd8083bbcf (plain) (blame)
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
#include <history.h>

namespace newsbeuter {

history::history() : idx(0) { }

history::~history() { }

void history::add_line(const std::string& line) {
	/*
	 * When a line is added, we need to do so and
	 * reset the index so that the next prev/next
	 * operations start from the beginning again.
	 */
	if (line.length() > 0) {
		lines.insert(lines.begin(), line);
	}
	idx = 0;
}

std::string history::prev() {
	if (idx < lines.size()) {
		return lines[idx++];
	}
	if (lines.size() == 0) {
		return "";
	}
	return lines[idx-1];
}

std::string history::next() {
	if (idx > 0) {
		return lines[--idx];
	}
	return "";
}


}