Commit 71f22cbb1eb396cfe388c14c1e4eb6f6d82a4138

Fix combining attributes in ColorTree::visit()
Non-recursive version never actually worked (it couldn't, it didn't even
pop `formats`) and it's not obvious how to make it work properly (need
to know when done processing children of a node).
Author: xaizek
Author date (UTC): 2021-12-29 00:27
Committer name: xaizek
Committer date (UTC): 2021-12-29 10:56
Parent(s): 9c4625959456596985730506e5f86fe8288b9566
Signing key: 99DC5E4DB05F6BE2
Tree: 15c90a6f4fe6f4e02c9fa42a448e377390a55394
File Lines added Lines deleted
ColorTree.cpp 19 25
File ColorTree.cpp changed (mode: 100644) (index c8c08b3..f2c24a5)
... ... ColorTree::append(ColorTree &&branch)
291 291 void void
292 292 ColorTree::visit(const visitorFunc &visitor) const ColorTree::visit(const visitorFunc &visitor) const
293 293 { {
294 std::stack<const ColorTree *> trees;
295 trees.push(this);
296
297 std::stack<const Format *> formats;
298 Format fmt;
299 formats.push(&fmt);
300
301 FormatState formatState;
302 while (!trees.empty()) {
303 const ColorTree &tree = *trees.top();
304 trees.pop();
305
306 formatState -= *formats.top();
307 formats.top() = &tree.format;
308 formatState += tree.format;
309
310 if (tree.branches.empty()) {
311 visitor(tree.text, formatState.getCurrent());
312 } else {
313 for (auto it = tree.branches.crbegin();
314 it != tree.branches.crend();
315 ++it) {
316 trees.push(&*it);
317 formats.emplace(&fmt);
294 struct {
295 const visitorFunc &visitor;
296 FormatState formatState;
297
298 void visit(const ColorTree &tree)
299 {
300 formatState += tree.format;
301
302 if (tree.branches.empty()) {
303 visitor(tree.text, formatState.getCurrent());
304 } else {
305 for (const ColorTree &branch : tree.branches) {
306 visit(branch);
307 }
318 308 } }
309
310 formatState -= tree.format;
319 311 } }
320 }
312 } f = { visitor, {} };
313
314 f.visit(*this);
321 315 } }
322 316
323 317 int int
Hints

Before first commit, do not forget to setup your git environment:
git config --global user.name "your_name_here"
git config --global user.email "your@email_here"

Clone this repository using HTTP(S):
git clone https://code.reversed.top/user/xaizek/libcursed

Clone this repository using ssh (do not forget to upload a key first):
git clone ssh://rocketgit@code.reversed.top/user/xaizek/libcursed

You are allowed to anonymously push to this repository.
This means that your pushed commits will automatically be transformed into a pull request:
... clone the repository ...
... make some changes and some commits ...
git push origin master