1 |
/* |
2 |
* LSCP Shell |
3 |
* |
4 |
* Copyright (c) 2014 Christian Schoenebeck |
5 |
* |
6 |
* This program is part of LinuxSampler and released under the same terms. |
7 |
*/ |
8 |
|
9 |
#include "TerminalPrinter.h" |
10 |
#include <iostream> |
11 |
#include "CCursor.h" |
12 |
|
13 |
TerminalPrinter::TerminalPrinter() : m_lines(0) { |
14 |
m_col = CCursor::now().column(); |
15 |
m_screenWidth = TerminalCtrl::columns(); |
16 |
} |
17 |
|
18 |
TerminalPrinter::~TerminalPrinter() { |
19 |
} |
20 |
|
21 |
TerminalPrinter& TerminalPrinter::operator<< (std::string s) { |
22 |
for (int i = 0; i < s.size(); ++i) |
23 |
printChar(s[i]); |
24 |
std::cout << std::flush; |
25 |
return *this; |
26 |
} |
27 |
|
28 |
void TerminalPrinter::printChar(char c) { |
29 |
std::cout << c << std::flush; |
30 |
switch (c) { |
31 |
case '\r': |
32 |
m_col = 0; |
33 |
break; |
34 |
case '\n': |
35 |
m_col = 0; |
36 |
m_lines++; |
37 |
break; |
38 |
default: |
39 |
m_col++; |
40 |
if (m_col >= m_screenWidth) { |
41 |
m_col = 0; |
42 |
m_lines++; |
43 |
} |
44 |
} |
45 |
} |
46 |
|
47 |
int TerminalPrinter::linesAdvanced() const { |
48 |
return m_lines; |
49 |
} |