File: Console.cpp

package info (click to toggle)
ausaxs 1.1.8-1
  • links: PTS, VCS
  • area: main
  • in suites: sid
  • size: 72,592 kB
  • sloc: cpp: 49,853; ansic: 6,901; python: 730; makefile: 18
file content (68 lines) | stat: -rw-r--r-- 2,095 bytes parent folder | download
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
// SPDX-License-Identifier: LGPL-3.0-or-later
// Author: Kristian Lytje

#include <utility/Console.h>
#include <utility/ConsoleColor.h>
#include <utility/Logging.h>
#include <settings/GeneralSettings.h>

using namespace ausaxs;

std::string indentation = "";
void console::indent(int level) {
    indentation += std::string(level, '\t');
}

void console::unindent(int level) {
    if (indentation.empty()) {
        throw std::runtime_error("Cannot unindent console output below 0.");
    }
    indentation.resize(indentation.size() - level);
}

void console::print_critical(std::string_view text) {
    logging::log_critical(text);
    console::print(text, console::color::red);
}

void console::print_text_critical(std::string_view text) {
    logging::log_critical(text);
    console::print(std::string(text), console::color::white);
}

void console::print_warning(std::string_view text) {
    logging::log_console(text);
    if (!settings::general::warnings) {return;}
    console::print(text, console::color::red);
}

void console::print_success(std::string_view text) {
    logging::log_console(text);
    if (!settings::general::verbose) {return;}
    console::print(indentation + std::string(text), console::color::green);
}

void console::print_failure(std::string_view text) {
    logging::log_console(text);
    if (!settings::general::verbose) {return;}
    console::print(indentation + std::string(text), console::color::red);
}

void console::print_info(std::string_view text) {
    logging::log_console(text);
    if (!settings::general::verbose) {return;}
    console::print(text, console::color::lightblue);
}

void console::print_text(std::string_view text) {
    logging::log_console(text);
    if (!settings::general::verbose) {return;}
    console::print(indentation + std::string(text), console::color::white);
}

bool minor_messages = true;
void console::print_text_minor(std::string_view text) {
    logging::log_console(text);
    if (!minor_messages || !settings::general::verbose) {return;}
    console::print(indentation + std::string(text), console::color::white);
}