aboutsummaryrefslogtreecommitdiffstats
path: root/src/ui/AsciiRenderer.cpp
blob: d06dadb0daea7b1710064d859d9dc4298fcffe73 (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
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
/*
 * Renderer.cpp
 *
 *  Created on: Nov 23, 2017
 *      Author: naopross
 */

#include "AsciiRenderer.hpp"

#include <memory>

namespace samb {

AsciiRenderer::AsciiRenderer(Structogram& structogram, unsigned int width):
		m_structogram(structogram), m_width(width) {}

AsciiRenderer::~AsciiRenderer() {}

void AsciiRenderer::drawPadding(unsigned int amt) {
	while (amt--) {
		std::cout << " ";
	}
}

void AsciiRenderer::drawLine() const {
	for (unsigned int i = 0; i < m_width; i++) {
		std::cout << "-";
	}

	std::cout << std::endl;
}

void AsciiRenderer::drawText(std::string text, unsigned int width, std::string before, std::string after) const {

	if (width == 0) {
		width = m_width;
	}

	unsigned int textWidth = width - before.length() - after.length();

	std::cout << before;
	for (std::size_t i = 0; i < text.length(); i++) {
		if (i % textWidth == 0 && i != 0) {
			std::cout << after <<  "\n" << before;
		}

		std::cout << text[i];
	}

	std::cout << std::endl;
}

void AsciiRenderer::drawDecision(std::string condition, std::string trueText, std::string falseText, unsigned int width) const {
	if (width == 0) {
		width = m_width -2;
	}

	std::cout << "|";

//	drawPadding(width - condition.length());
}

void AsciiRenderer::render() {

	for (Structogram::iterator it = m_structogram.begin(); it != m_structogram.end(); ++it) {

		switch (it->type) {
		case Statement::Type::PROCESS:
			drawLine();
			drawText(it->text);
			drawLine();
			break;

		case Statement::Type::DECISION:
			break;

		case Statement::Type::SWITCH:
			break;

		case Statement::Type::SCOPE:
			std::cout << "Title: " << it->text << std::endl;
			break;

		case Statement::Type::WHILE:
			break;

		case Statement::Type::UNTIL:
			break;

		case Statement::Type::PARALLEL:
			break;

		case Statement::END:
			// do nothing
			break;
		}
	}
}

} /* namespace samb */