The Pedigree Project 0.1
LogViewer.cc
1/*
2 * Copyright (c) 2008-2014, Pedigree Developers
3 *
4 * Please see the CONTRIB file in the root of the source tree for a full
5 * list of contributors.
6 *
7 * Permission to use, copy, modify, and distribute this software for any
8 * purpose with or without fee is hereby granted, provided that the above
9 * copyright notice and this permission notice appear in all copies.
10 *
11 * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
12 * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
13 * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
14 * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
15 * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
16 * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
17 * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
18 */
19
20#include "pedigree/kernel/Log.h"
21#include "pedigree/kernel/debugger/DebuggerIO.h"
22#include "pedigree/kernel/debugger/commands/LogViewer.h"
23
25
27
29
31 InterruptState& state, DebuggerIO* pScreen) {
32 // Let's enter 'raw' screen mode.
33 pScreen->disableCli();
34
35 // Initialise the Scrollable class
36 move(0, 1);
37 resize(pScreen->getWidth(), pScreen->getHeight() - 2);
38 horizontalScrollTo(0);
39 setScrollKeys('j', 'k');
40
41 // Clear the top status lines.
42 pScreen->drawHorizontalLine(' ', 0, 0, pScreen->getWidth() - 1, DebuggerIO::White,
43 DebuggerIO::Green);
44
45 // Write the correct text in the upper status line.
46 pScreen->drawString("Pedigree debugger - Log viewer", 0, 0, DebuggerIO::White, DebuggerIO::Green);
47
48 // Clear the bottom status lines.
49 // TODO: If we use arrow keys and page up/down keys we actually can remove
50 // the status line
51 // because the interface is then intuitive enough imho.
52 pScreen->drawHorizontalLine(' ', pScreen->getHeight() - 1, 0, pScreen->getWidth() - 1,
53 DebuggerIO::White, DebuggerIO::Green);
54
55 NormalStaticString footer("h/l: left/right j/k: up/down backspace/space: page q: quit");
56 footer.truncate(pScreen->getWidth());
57 pScreen->drawString(footer, pScreen->getHeight() - 1, 0, DebuggerIO::White, DebuggerIO::Green);
58
59 // Main loop.
60 bool bStop = false;
61 while (!bStop) {
62 refresh(pScreen);
63
64 // Wait for input.
65 char c = 0;
66 while (!(c = pScreen->getChar()))
67 ;
68
69 // TODO: Use arrow keys and page up/down someday
70 if (c == 'j')
71 scroll(-1);
72 else if (c == 'k')
73 scroll(1);
74 else if (c == 'h')
75 scrollHorizontal(-8);
76 else if (c == 'l')
77 scrollHorizontal(8);
78 else if (c == ' ')
79 scroll(static_cast<ssize_t>(height()));
80 else if (c == 0x08)
81 scroll(-static_cast<ssize_t>(height()));
82 else if (c == 'q')
83 bStop = true;
84 }
85
86 // HACK:: Serial connections will fill the screen with the last background
87 // colour used.
88 // Here we write a space with black background so the CLI screen
89 // doesn't get filled by some random colour!
90 pScreen->drawString(" ", 1, 0, DebuggerIO::White, DebuggerIO::Black);
91 pScreen->enableCli();
92 return true;
93}
94
95const char* LogViewer::getLine1(size_t index, DebuggerIO::Colour& colour,
96 DebuggerIO::Colour& bgColour) {
98 static NormalStaticString Line;
99 Line.clear();
100 Line.append("[");
101
102 Log& log = Log::instance();
103 if (index < log.getStaticEntryCount()) {
104 const Log::StaticLogEntry& entry = log.getStaticEntry(index);
105 Line.append(entry.timestamp, 10, 8, '0');
106 level = entry.severity;
107 } else {
108 const Log::DynamicLogEntry& entry = log.getDynamicEntry(index);
109 Line.append(entry.timestamp, 10, 8, '0');
110 level = entry.severity;
111 }
112
113 Line.append("] ");
114
115 colour = DebuggerIO::White;
116 switch (level) {
117 case Log::Debug:
118 colour = DebuggerIO::LightBlue;
119 break;
120 case Log::Notice:
121 colour = DebuggerIO::Green;
122 break;
123 case Log::Warning:
124 colour = DebuggerIO::Yellow;
125 break;
126 case Log::Error:
127 colour = DebuggerIO::Magenta;
128 break;
129 case Log::Fatal:
130 colour = DebuggerIO::Red;
131 break;
132 }
133
134 return Line;
135}
136const char* LogViewer::getLine2(size_t index, size_t& colOffset, DebuggerIO::Colour& colour,
137 DebuggerIO::Colour& bgColour) {
138 Log& log = Log::instance();
139 static LargeStaticString Line;
140 Line.clear();
141
142 if (index < log.getStaticEntryCount()) {
143 const Log::StaticLogEntry& entry = log.getStaticEntry(index);
144 Line.append(entry.str);
145 } else {
146 const Log::DynamicLogEntry& entry = log.getDynamicEntry(index);
147 Line.append(entry.str);
148 }
149
150 colour = DebuggerIO::White;
151 colOffset = 11;
152 return Line;
153}
154size_t LogViewer::getLineCount() {
155 Log& log = Log::instance();
156 return log.getStaticEntryCount() + log.getDynamicEntryCount();
157}
158
159size_t LogViewer::getContentWidth() {
160 Log& log = Log::instance();
161 size_t width = 11;
162
163 for (size_t i = 0; i < log.getStaticEntryCount(); ++i) {
164 width = max(width, static_cast<size_t>(11 + log.getStaticEntry(i).str.length()));
165 }
166 for (size_t i = 0; i < log.getDynamicEntryCount(); ++i) {
167 width = max(width, static_cast<size_t>(11 + log.getDynamicEntry(i).str.length()));
168 }
169
170 return width;
171}
virtual void enableCli()=0
virtual void drawString(const char *str, size_t row, size_t col, Colour foreColour, Colour backColour)=0
virtual size_t getWidth()=0
virtual void drawHorizontalLine(char c, size_t row, size_t colStart, size_t colEnd, Colour foreColour, Colour backColour)=0
virtual char getChar()=0
void autocomplete(const HugeStaticString &input, HugeStaticString &output)
Definition LogViewer.cc:28
bool execute(const HugeStaticString &input, HugeStaticString &output, InterruptState &state, DebuggerIO *screen)
Definition LogViewer.cc:30
the kernel's log
Definition Log.h:155
size_t getStaticEntryCount() const
Definition Log.cc:438
const StaticLogEntry & getStaticEntry(size_t n) const
Definition Log.cc:446
size_t getDynamicEntryCount() const
Definition Log.cc:442
static EXPORTED_PUBLIC Log & instance()
Definition Log.cc:117
SeverityLevel
Definition Log.h:170
const DynamicLogEntry & getDynamicEntry(size_t n) const
Definition Log.cc:450
StaticString< LOG_LENGTH > str
Definition Log.h:226