summaryrefslogtreecommitdiffstats
path: root/xmrstak/misc/console.hpp
blob: cfbeddd01ec806bd4dca8a441f58fc89e8f1883e (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
#pragma once

#include "xmrstak/misc/environment.hpp"

#include <mutex>


enum out_colours { K_RED, K_GREEN, K_BLUE, K_YELLOW, K_CYAN, K_MAGENTA, K_WHITE, K_NONE };

// Warning - on Linux get_key will detect control keys, but not on Windows.
// We will only use it for alphanum keys anyway.
int get_key();

void set_colour(out_colours cl);
void reset_colour();

// on MSVC sizeof(long int) = 4, gcc sizeof(long int) = 8, this is the workaround
// now we can use %llu on both compilers
inline long long unsigned int int_port(size_t i)
{
	return i;
}

enum verbosity : size_t { L0 = 0, L1 = 1, L2 = 2, L3 = 3, L4 = 4, LINF = 100};

class printer
{
public:
	static inline printer* inst()
	{
		auto& env = xmrstak::environment::inst();
		if(env.pPrinter == nullptr)
			env.pPrinter = new printer;
		return env.pPrinter;
	};

	inline void set_verbose_level(size_t level) { verbose_level = (verbosity)level; }
	inline void set_flush_stdout(bool status) { b_flush_stdout = status; }
	void print_msg(verbosity verbose, const char* fmt, ...);
	void print_str(const char* str);
	bool open_logfile(const char* file);

private:
	printer();

	std::mutex print_mutex;
	verbosity verbose_level;
	bool b_flush_stdout;
	FILE* logfile;
};

void win_exit(size_t code = 1);
OpenPOWER on IntegriCloud