summaryrefslogtreecommitdiff
path: root/competition/multilog.cpp
diff options
context:
space:
mode:
authorTom Smeding <tom.smeding@gmail.com>2018-08-20 23:51:16 +0200
committerTom Smeding <tom.smeding@gmail.com>2018-08-20 23:52:03 +0200
commit57a1091dfb2c6403cbe63c7ddca8acc7e3d0f940 (patch)
treea997ed523a853d9d5fff7d5b90b12a180b00a231 /competition/multilog.cpp
parentf0b6d1b9c46578183b427bcec4bbe99ab10c7b97 (diff)
Switch to https://git.tomsmeding.com/competitionHEADmaster
Diffstat (limited to 'competition/multilog.cpp')
-rw-r--r--competition/multilog.cpp57
1 files changed, 0 insertions, 57 deletions
diff --git a/competition/multilog.cpp b/competition/multilog.cpp
deleted file mode 100644
index bf10ec6..0000000
--- a/competition/multilog.cpp
+++ /dev/null
@@ -1,57 +0,0 @@
-#include <iostream>
-#include <string>
-#include <cassert>
-#include "multilog.h"
-
-
-static int uniqid() {
- static int i = 0;
- return i++;
-}
-
-
-MultiLog::Item::Item()
- : id(uniqid()) {}
-
-int MultiLog::add(const string_view prefix) {
- lock_guard guard(mut);
-
- items.emplace_back();
- items.back().line = prefix;
- cout << prefix << endl;
- return items.back().id;
-}
-
-void MultiLog::append(int id, const string_view text) {
- lock_guard guard(mut);
-
- assert(text.find('\n') == string::npos);
-
- size_t idx = findId(id);
- items[idx].line += text;
- redrawLine(idx);
-}
-
-void MultiLog::complete(int id) {
- lock_guard guard(mut);
-
- size_t idx = findId(id);
- items[idx].complete = true;
- size_t nextIdx;
- for (nextIdx = 0; nextIdx < items.size(); nextIdx++) {
- if (!items[nextIdx].complete) break;
- }
- if (nextIdx > 0) items.erase(items.begin(), items.begin() + (nextIdx - 1));
-}
-
-size_t MultiLog::findId(int id) {
- for (int i = 0; i < (int)items.size(); i++) {
- if (items[i].id == id) return i;
- }
- assert(false);
-}
-
-void MultiLog::redrawLine(size_t idx) {
- size_t offset = items.size() - idx;
- cout << "\r\x1B[" << offset << "A\x1B[K" << items[idx].line << "\r\x1B[" << offset << "B" << flush;
-}