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/debugger/commands/LogViewer.h"
21 #include "pedigree/kernel/Log.h"
22 #include "pedigree/kernel/debugger/DebuggerIO.h"
23 
25 {
26 }
27 
29 {
30 }
31 
33  const HugeStaticString &input, HugeStaticString &output)
34 {
35 }
36 
38  const HugeStaticString &input, HugeStaticString &output,
39  InterruptState &state, DebuggerIO *pScreen)
40 {
41  // Let's enter 'raw' screen mode.
42  pScreen->disableCli();
43 
44  // Initialise the Scrollable class
45  move(0, 1);
46  resize(pScreen->getWidth(), pScreen->getHeight() - 2);
47  setScrollKeys('j', 'k');
48 
49  // Clear the top status lines.
50  pScreen->drawHorizontalLine(
51  ' ', 0, 0, pScreen->getWidth() - 1, DebuggerIO::White,
52  DebuggerIO::Green);
53 
54  // Write the correct text in the upper status line.
55  pScreen->drawString(
56  "Pedigree debugger - Log viewer", 0, 0, DebuggerIO::White,
57  DebuggerIO::Green);
58 
59  // Clear the bottom status lines.
60  // TODO: If we use arrow keys and page up/down keys we actually can remove
61  // the status line
62  // because the interface is then intuitive enough imho.
63  pScreen->drawHorizontalLine(
64  ' ', pScreen->getHeight() - 1, 0, pScreen->getWidth() - 1,
65  DebuggerIO::White, DebuggerIO::Green);
66 
67  // Write some helper text in the lower status line.
68  // TODO FIXME: Drawing this might screw the top status bar
69  pScreen->drawString(
70  "j: Up one line. k: Down one line. backspace: Page up. space: Page "
71  "down. q: Quit",
72  pScreen->getHeight() - 1, 0, DebuggerIO::White, DebuggerIO::Green);
73  pScreen->drawString(
74  "j", pScreen->getHeight() - 1, 0, DebuggerIO::Yellow,
75  DebuggerIO::Green);
76  pScreen->drawString(
77  "k", pScreen->getHeight() - 1, 16, DebuggerIO::Yellow,
78  DebuggerIO::Green);
79  pScreen->drawString(
80  "backspace", pScreen->getHeight() - 1, 34, DebuggerIO::Yellow,
81  DebuggerIO::Green);
82  pScreen->drawString(
83  "space", pScreen->getHeight() - 1, 54, DebuggerIO::Yellow,
84  DebuggerIO::Green);
85  pScreen->drawString(
86  "q", pScreen->getHeight() - 1, 72, DebuggerIO::Yellow,
87  DebuggerIO::Green);
88 
89  // Main loop.
90  bool bStop = false;
91  while (!bStop)
92  {
93  refresh(pScreen);
94 
95  // Wait for input.
96  char c = 0;
97  while (!(c = pScreen->getChar()))
98  ;
99 
100  // TODO: Use arrow keys and page up/down someday
101  if (c == 'j')
102  scroll(-1);
103  else if (c == 'k')
104  scroll(1);
105  else if (c == ' ')
106  scroll(static_cast<ssize_t>(height()));
107  else if (c == 0x08)
108  scroll(-static_cast<ssize_t>(height()));
109  else if (c == 'q')
110  bStop = true;
111  }
112 
113  // HACK:: Serial connections will fill the screen with the last background
114  // colour used.
115  // Here we write a space with black background so the CLI screen
116  // doesn't get filled by some random colour!
117  pScreen->drawString(" ", 1, 0, DebuggerIO::White, DebuggerIO::Black);
118  pScreen->enableCli();
119  return true;
120 }
121 
122 const char *LogViewer::getLine1(
123  size_t index, DebuggerIO::Colour &colour, DebuggerIO::Colour &bgColour)
124 {
125  Log::SeverityLevel level;
126  static NormalStaticString Line;
127  Line.clear();
128  Line.append("[");
129 
130  Log &log = Log::instance();
131  if (index < log.getStaticEntryCount())
132  {
133  const Log::StaticLogEntry &entry = log.getStaticEntry(index);
134  Line.append(entry.timestamp, 10, 8, '0');
135  level = entry.severity;
136  }
137  else
138  {
139  const Log::DynamicLogEntry &entry = log.getDynamicEntry(index);
140  Line.append(entry.timestamp, 10, 8, '0');
141  level = entry.severity;
142  }
143 
144  Line.append("] ");
145 
146  colour = DebuggerIO::White;
147  switch (level)
148  {
149  case Log::Debug:
150  colour = DebuggerIO::LightBlue;
151  break;
152  case Log::Notice:
153  colour = DebuggerIO::Green;
154  break;
155  case Log::Warning:
156  colour = DebuggerIO::Yellow;
157  break;
158  case Log::Error:
159  colour = DebuggerIO::Magenta;
160  break;
161  case Log::Fatal:
162  colour = DebuggerIO::Red;
163  break;
164  }
165 
166  return Line;
167 }
168 const char *LogViewer::getLine2(
169  size_t index, size_t &colOffset, DebuggerIO::Colour &colour,
170  DebuggerIO::Colour &bgColour)
171 {
172  Log &log = Log::instance();
173  static LargeStaticString Line;
174  Line.clear();
175 
176  if (index < log.getStaticEntryCount())
177  {
178  const Log::StaticLogEntry &entry = log.getStaticEntry(index);
179  Line.append(entry.str);
180  }
181  else
182  {
183  const Log::DynamicLogEntry &entry = log.getDynamicEntry(index);
184  Line.append(entry.str);
185  }
186 
187  colour = DebuggerIO::White;
188  colOffset = 11;
189  return Line;
190 }
191 size_t LogViewer::getLineCount()
192 {
193  Log &log = Log::instance();
194  return log.getStaticEntryCount() + log.getDynamicEntryCount();
195 }
virtual size_t getWidth()=0
virtual void enableCli()=0
StaticString< LOG_LENGTH > str
Definition: Log.h:245
the kernel&#39;s log
Definition: Log.h:166
size_t getStaticEntryCount() const
Definition: Log.cc:225
virtual char getChar()=0
SeverityLevel severity
Definition: Log.h:243
const StaticLogEntry & getStaticEntry(size_t n) const
Definition: Log.cc:235
const DynamicLogEntry & getDynamicEntry(size_t n) const
Definition: Log.cc:240
~LogViewer()
Definition: LogViewer.cc:28
unsigned int timestamp
Definition: Log.h:241
size_t getDynamicEntryCount() const
Definition: Log.cc:230
SeverityLevel
Definition: Log.h:180
virtual void drawString(const char *str, size_t row, size_t col, Colour foreColour, Colour backColour)=0
static EXPORTED_PUBLIC Log & instance()
Definition: Log.cc:108
virtual void drawHorizontalLine(char c, size_t row, size_t colStart, size_t colEnd, Colour foreColour, Colour backColour)=0
bool execute(const HugeStaticString &input, HugeStaticString &output, InterruptState &state, DebuggerIO *screen)
Definition: LogViewer.cc:37
void autocomplete(const HugeStaticString &input, HugeStaticString &output)
Definition: LogViewer.cc:32