diff options
author | Tom Smeding <tom.smeding@gmail.com> | 2018-08-20 23:51:16 +0200 |
---|---|---|
committer | Tom Smeding <tom.smeding@gmail.com> | 2018-08-20 23:52:03 +0200 |
commit | 57a1091dfb2c6403cbe63c7ddca8acc7e3d0f940 (patch) | |
tree | a997ed523a853d9d5fff7d5b90b12a180b00a231 /competition/multilog.cpp | |
parent | f0b6d1b9c46578183b427bcec4bbe99ab10c7b97 (diff) |
Diffstat (limited to 'competition/multilog.cpp')
-rw-r--r-- | competition/multilog.cpp | 57 |
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; -} |