Handout
This commit is contained in:
37
kernel/device/serialstream.cc
Normal file
37
kernel/device/serialstream.cc
Normal file
@@ -0,0 +1,37 @@
|
||||
#include "serialstream.h"
|
||||
|
||||
SerialStream::SerialStream(ComPort port, BaudRate baud_rate, DataBits data_bits,
|
||||
StopBits stop_bits, Parity parity)
|
||||
: Serial(port, baud_rate, data_bits, stop_bits, parity) {}
|
||||
|
||||
void SerialStream::flush() {
|
||||
print(buffer, pos);
|
||||
pos = 0;
|
||||
}
|
||||
|
||||
void SerialStream::setForeground(Color c) {
|
||||
*this << "\e[" << (30 + static_cast<uint32_t>(c)) << 'm';
|
||||
}
|
||||
|
||||
void SerialStream::setBackground(Color c) {
|
||||
*this << "\e[" << (40 + static_cast<uint32_t>(c)) << 'm';
|
||||
}
|
||||
|
||||
void SerialStream::setAttribute(Attrib a) {
|
||||
*this << "\e[" << static_cast<uint32_t>(a) << 'm';
|
||||
}
|
||||
|
||||
void SerialStream::reset() { *this << "\ec" << ::flush; }
|
||||
|
||||
void SerialStream::setPos(int x, int y) {
|
||||
*this << "\e[" << (y + 1) << ';' << (x + 1) << 'H' << ::flush;
|
||||
}
|
||||
|
||||
void SerialStream::print(char* str, int length) {
|
||||
for (int p = 0; p < length; p++) {
|
||||
if (str[p] == '\n' && (p == 0 || str[p - 1] != '\r')) {
|
||||
write('\r');
|
||||
}
|
||||
write(str[p]);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user