20#include <wx/clipbrd.h>
21#include <wx/dcclient.h>
23#include <wx/textctrl.h>
33 : wxScrolledWindow(parent), m_n_lines(n_lines), m_filter(filter) {
36 dc.GetTextExtent(
"Line Height", NULL, &m_line_height);
38 SetScrollRate(0, m_line_height);
39 SetVirtualSize(-1, (m_n_lines + 1) * m_line_height);
40 for (
unsigned i = 0; i < m_n_lines; i++) m_lines.push_back(
"");
44 wxString filter = m_filter.GetValue();
45 if (!m_is_paused && (filter.IsEmpty() || line.Contains(filter))) {
46 while (m_lines.size() > m_n_lines - 1) m_lines.pop_front();
47 m_lines.push_back(line);
52void TtyScroll::OnDraw(wxDC& dc) {
54 wxRect rect_update = GetUpdateRegion().GetBox();
55 CalcUnscrolledPosition(rect_update.x, rect_update.y, &rect_update.x,
58 size_t line_from = rect_update.y / m_line_height,
59 line_to = rect_update.GetBottom() / m_line_height;
61 if (line_to > m_n_lines - 1) line_to = m_n_lines - 1;
63 wxCoord y = line_from * m_line_height;
65 for (
size_t line = line_from; line <= line_to; line++) {
67 CalcScrolledPosition(0, y, NULL, &y_phys);
69 wxString ls = m_lines[line];
70 if (ls.Mid(0, 7) ==
"<GREEN>") {
71 dc.SetTextForeground(wxColour(
"DARK GREEN"));
73 }
else if (ls.Mid(0, 6) == (
"<BLUE>")) {
74 dc.SetTextForeground(wxColour(
"BLUE"));
76 }
else if (ls.Mid(0, 5) ==
"<RED>") {
77 dc.SetTextForeground(wxColour(
"RED"));
79 }
else if (ls.Mid(0, 8) ==
"<MAROON>") {
80 dc.SetTextForeground(wxColour(
"MAROON"));
82 }
else if (ls.Mid(0, 7) ==
"<CORAL>") {
83 dc.SetTextForeground(wxColour(
"CORAL"));
88 dc.DrawText(lss, 0, y);
95 for (
auto& s : m_lines) {
98 if ((pos = s.Find(
"$")) != wxNOT_FOUND) {
99 the_text.append(s.Mid(pos) +
"\n");
100 }
else if ((pos = s.Find(
"!")) != wxNOT_FOUND) {
101 the_text.append(s.Mid(pos) +
"\n");
105 the_text.append(
"\n");
109 if (wxTheClipboard->Open()) {
110 wxTheClipboard->SetData(
new wxTextDataObject(the_text));
111 wxTheClipboard->Close();