openMSX
CommandConsole.cc
Go to the documentation of this file.
1 #include "CommandConsole.hh"
2 #include "CommandException.hh"
4 #include "Completer.hh"
5 #include "Interpreter.hh"
6 #include "Keys.hh"
7 #include "FileContext.hh"
8 #include "FileException.hh"
9 #include "FileOperations.hh"
10 #include "CliComm.hh"
11 #include "InputEvents.hh"
12 #include "Display.hh"
13 #include "EventDistributor.hh"
14 #include "SDL.h"
15 #include "Version.hh"
16 #include "checked_cast.hh"
17 #include "utf8_unchecked.hh"
18 #include "StringOp.hh"
19 #include "ScopedAssign.hh"
20 #include "scope_exit.hh"
21 #include "view.hh"
22 #include "xrange.hh"
23 #include <algorithm>
24 #include <fstream>
25 #include <cassert>
26 
27 using std::min;
28 using std::max;
29 using std::string;
30 using std::string_view;
31 
32 namespace openmsx {
33 
34 // class ConsoleLine
35 
36 ConsoleLine::ConsoleLine(string line_, uint32_t rgb)
37  : line(std::move(line_))
38  , chunks(1, {rgb, 0})
39 {
40 }
41 
42 void ConsoleLine::addChunk(string_view text, uint32_t rgb)
43 {
44  chunks.emplace_back(rgb, line.size());
45  line.append(text.data(), text.size());
46 }
47 
48 size_t ConsoleLine::numChars() const
49 {
50  return utf8::unchecked::size(line);
51 }
52 
53 uint32_t ConsoleLine::chunkColor(size_t i) const
54 {
55  assert(i < chunks.size());
56  return chunks[i].first;
57 }
58 
59 string_view ConsoleLine::chunkText(size_t i) const
60 {
61  assert(i < chunks.size());
62  auto pos = chunks[i].second;
63  auto len = ((i + 1) == chunks.size())
64  ? string_view::npos
65  : chunks[i + 1].second - pos;
66  return string_view(line).substr(pos, len);
67 }
68 
69 // class CommandConsole
70 
71 constexpr const char* const PROMPT_NEW = "> ";
72 constexpr const char* const PROMPT_CONT = "| ";
73 constexpr const char* const PROMPT_BUSY = "*busy*";
74 
76  GlobalCommandController& commandController_,
77  EventDistributor& eventDistributor_,
78  Display& display_)
79  : commandController(commandController_)
80  , eventDistributor(eventDistributor_)
81  , display(display_)
82  , consoleSetting(
83  commandController, "console",
84  "turns console display on/off", false, Setting::DONT_SAVE)
85  , historySizeSetting(
86  commandController, "console_history_size",
87  "amount of commands kept in console history", 100, 0, 10000)
88  , removeDoublesSetting(
89  commandController, "console_remove_doubles",
90  "don't add the command to history if it's the same as the previous one",
91  true)
92  , history(std::max(1, historySizeSetting.getInt()))
93  , executingCommand(false)
94 {
95  resetScrollBack();
96  prompt = PROMPT_NEW;
97  newLineConsole(prompt);
98  loadHistory();
99  putPrompt();
100  Completer::setOutput(this);
101 
102  const auto& fullVersion = Version::full();
103  print(fullVersion);
104  print(string(fullVersion.size(), '-'));
105  print("\n"
106  "General information about openMSX is available at "
107  "http://openmsx.org.\n"
108  "\n"
109  "Type 'help' to see a list of available commands "
110  "(use <PgUp>/<PgDn> to scroll).\n"
111  "Or read the Console Command Reference in the manual.\n"
112  "\n");
113 
114  commandController.getInterpreter().setOutput(this);
115  eventDistributor.registerEventListener(
117  // also listen to KEY_UP events, so that we can consume them
118  eventDistributor.registerEventListener(
120 }
121 
123 {
124  eventDistributor.unregisterEventListener(OPENMSX_KEY_DOWN_EVENT, *this);
125  eventDistributor.unregisterEventListener(OPENMSX_KEY_UP_EVENT, *this);
126  commandController.getInterpreter().setOutput(nullptr);
127  Completer::setOutput(nullptr);
128 }
129 
130 void CommandConsole::saveHistory()
131 {
132  try {
133  std::ofstream outputfile;
134  FileOperations::openofstream(outputfile,
135  userFileContext("console").resolveCreate("history.txt"));
136  if (!outputfile) {
137  throw FileException(
138  "Error while saving the console history.");
139  }
140  for (auto& s : history) {
141  outputfile << s << '\n';
142  }
143  } catch (FileException& e) {
144  commandController.getCliComm().printWarning(e.getMessage());
145  }
146 }
147 
148 void CommandConsole::loadHistory()
149 {
150  try {
151  std::ifstream inputfile(
152  userFileContext("console").
153  resolveCreate("history.txt").c_str());
154  string line;
155  while (inputfile) {
156  getline(inputfile, line);
157  putCommandHistory(line);
158  }
159  } catch (FileException&) {
160  // Error while loading the console history, ignore
161  }
162 }
163 
164 void CommandConsole::getCursorPosition(unsigned& xPosition, unsigned& yPosition) const
165 {
166  xPosition = cursorPosition % getColumns();
167  auto num = lines[0].numChars() / getColumns();
168  yPosition = unsigned(num - (cursorPosition / getColumns()));
169 }
170 
171 int CommandConsole::signalEvent(const std::shared_ptr<const Event>& event)
172 {
173  if (!consoleSetting.getBoolean()) return 0;
174  auto& keyEvent = checked_cast<const KeyEvent&>(*event);
175 
176  // If the console is open then don't pass the event to the MSX
177  // (whetever the (keyboard) event is). If the event has a meaning for
178  // the console, then also don't pass the event to the hotkey system.
179  // For example PgUp, PgDown are keys that have both a meaning in the
180  // console and are used by standard key bindings.
181  if (event->getType() == OPENMSX_KEY_DOWN_EVENT) {
182  if (!executingCommand) {
183  if (handleEvent(keyEvent)) {
184  // event was used
185  display.repaintDelayed(40000); // 25fps
186  return EventDistributor::HOTKEY; // block HOTKEY and MSX
187  }
188  } else {
189  // For commands that take a long time to execute (e.g.
190  // a loadstate that needs to create a filepool index),
191  // we also send events during the execution (so that
192  // we can show progress on the OSD). In that case
193  // ignore extra input events.
194  }
195  } else {
196  assert(event->getType() == OPENMSX_KEY_UP_EVENT);
197  }
198  return EventDistributor::MSX; // block MSX
199 }
200 
201 bool CommandConsole::handleEvent(const KeyEvent& keyEvent)
202 {
203  auto keyCode = keyEvent.getKeyCode();
204  int key = keyCode & Keys::K_MASK;
205  int mod = keyCode & ~Keys::K_MASK;
206 
207  switch (mod) {
208  case Keys::KM_CTRL:
209  switch (key) {
210  case Keys::K_H:
211  backspace();
212  return true;
213  case Keys::K_A:
214  cursorPosition = unsigned(prompt.size());
215  return true;
216  case Keys::K_E:
217  cursorPosition = unsigned(lines[0].numChars());
218  return true;
219  case Keys::K_C:
220  clearCommand();
221  return true;
222  case Keys::K_L:
223  clearHistory();
224  return true;
225 #ifndef __APPLE__
226  case Keys::K_V:
227  paste();
228  return true;
229 #endif
230  }
231  break;
232  case Keys::KM_SHIFT:
233  switch (key) {
234  case Keys::K_PAGEUP:
235  scroll(max<int>(getRows() - 1, 1));
236  return true;
237  case Keys::K_PAGEDOWN:
238  scroll(-max<int>(getRows() - 1, 1));
239  return true;
240  }
241  break;
242  case Keys::KM_META:
243  switch (key) {
244 #ifdef __APPLE__
245  case Keys::K_V:
246  paste();
247  return true;
248  case Keys::K_K:
249  clearHistory();
250  return true;
251  case Keys::K_LEFT:
252  cursorPosition = unsigned(prompt.size());
253  return true;
254  case Keys::K_RIGHT:
255  cursorPosition = unsigned(lines[0].numChars());
256  return true;
257 #endif
258  }
259  break;
260  case Keys::KM_ALT:
261  switch (key) {
262  case Keys::K_BACKSPACE:
263  deleteToStartOfWord();
264  return true;
265 #ifdef __APPLE__
266  case Keys::K_DELETE:
267  deleteToEndOfWord();
268  return true;
269 #else
270  case Keys::K_D:
271  deleteToEndOfWord();
272  return true;
273 #endif
274  case Keys::K_LEFT:
275  gotoStartOfWord();
276  return true;
277  case Keys::K_RIGHT:
278  gotoEndOfWord();
279  return true;
280  }
281  break;
282  case 0: // no modifier
283  switch (key) {
284  case Keys::K_PAGEUP:
285  scroll(1);
286  return true;
287  case Keys::K_PAGEDOWN:
288  scroll(-1);
289  return true;
290  case Keys::K_UP:
291  prevCommand();
292  return true;
293  case Keys::K_DOWN:
294  nextCommand();
295  return true;
296  case Keys::K_BACKSPACE:
297  backspace();
298  return true;
299  case Keys::K_DELETE:
300  delete_key();
301  return true;
302  case Keys::K_TAB:
303  tabCompletion();
304  return true;
305  case Keys::K_RETURN:
306  case Keys::K_KP_ENTER:
307  commandExecute();
308  cursorPosition = unsigned(prompt.size());
309  return true;
310  case Keys::K_LEFT:
311  if (cursorPosition > prompt.size()) {
312  --cursorPosition;
313  }
314  return true;
315  case Keys::K_RIGHT:
316  if (cursorPosition < lines[0].numChars()) {
317  ++cursorPosition;
318  }
319  return true;
320  case Keys::K_HOME:
321 #ifdef __APPLE__
322  scroll(lines.size());
323 #else
324  cursorPosition = unsigned(prompt.size());
325 #endif
326  return true;
327  case Keys::K_END:
328 #ifdef __APPLE__
329  scroll(-lines.size());
330 #else
331  cursorPosition = unsigned(lines[0].numChars());
332 #endif
333  return true;
334  }
335  break;
336  }
337 
338  auto unicode = keyEvent.getUnicode();
339  if (!unicode || (mod & Keys::KM_META)) {
340  // Disallow META modifer for 'normal' key presses because on
341  // MacOSX Cmd+L is used as a hotkey to toggle the console.
342  // Hopefully there are no systems that require META to type
343  // normal keys. However there _are_ systems that require the
344  // following modifiers, some examples:
345  // MODE: to type '1-9' on a N900
346  // ALT: to type | [ ] on a azerty keyboard layout
347  // CTRL+ALT: to type '#' on a spanish keyboard layout (windows)
348  //
349  // Event was not used by the console, allow the other
350  // subsystems to process it. E.g. F10, or Cmd+L to close the
351  // console.
352  return false;
353  }
354 
355  // Apparently on macOS keyboard events for keys like F1 have a non-zero
356  // unicode field. This confuses the console code (it thinks it's a
357  // printable character) and it prevents those keys from triggering
358  // hotkey bindings. See this bug report:
359  // https://github.com/openMSX/openMSX/issues/1095
360  // As a workaround we ignore chars in the 'Private Use Area' (PUA).
361  // https://en.wikipedia.org/wiki/Private_Use_Areas
362  if (utf8::is_pua(unicode)) {
363  return false;
364  }
365 
366  if (unicode >= 0x20) {
367  normalKey(unicode);
368  } else {
369  // Skip CTRL-<X> combinations, but still return true.
370  }
371  return true;
372 }
373 
374 void CommandConsole::output(string_view text)
375 {
376  print(text);
377 }
378 
379 unsigned CommandConsole::getOutputColumns() const
380 {
381  return getColumns();
382 }
383 
384 void CommandConsole::print(string_view text, unsigned rgb)
385 {
386  while (true) {
387  auto pos = text.find('\n');
388  newLineConsole(ConsoleLine(string(text.substr(0, pos)), rgb));
389  if (pos == string_view::npos) return;
390  text = text.substr(pos + 1); // skip newline
391  if (text.empty()) return;
392  }
393 }
394 
395 void CommandConsole::newLineConsole(string line)
396 {
397  newLineConsole(ConsoleLine(std::move(line)));
398 }
399 
400 void CommandConsole::newLineConsole(ConsoleLine line)
401 {
402  if (lines.isFull()) {
403  lines.removeBack();
404  }
405  ConsoleLine tmp = std::move(lines[0]);
406  lines[0] = std::move(line);
407  lines.addFront(std::move(tmp));
408 }
409 
410 void CommandConsole::putCommandHistory(const string& command)
411 {
412  if (command.empty()) return;
413  if (removeDoublesSetting.getBoolean() && !history.empty() &&
414  (history.back() == command)) {
415  return;
416  }
417  if (history.full()) history.pop_front();
418  history.push_back(command);
419 }
420 
421 void CommandConsole::commandExecute()
422 {
423  resetScrollBack();
424  string cmd0 = lines[0].str().substr(prompt.size());
425  putCommandHistory(cmd0);
426  saveHistory(); // save at this point already, so that we don't lose history in case of a crash
427 
428  strAppend(commandBuffer, cmd0, '\n');
429  newLineConsole(lines[0]);
430  if (commandController.isComplete(commandBuffer)) {
431  // Normally the busy prompt is NOT shown (not even very briefly
432  // because the screen is not redrawn), though for some commands
433  // that potentially take a long time to execute, we explictly
434  // send events, see also comment in signalEvent().
435  prompt = PROMPT_BUSY;
436  putPrompt();
437 
438  try {
439  ScopedAssign sa(executingCommand, true);
440  auto resultObj = commandController.executeCommand(
441  commandBuffer);
442  auto result = resultObj.getString();
443  if (!result.empty()) {
444  print(result);
445  }
446  } catch (CommandException& e) {
447  print(e.getMessage(), 0xff0000);
448  }
449  commandBuffer.clear();
450  prompt = PROMPT_NEW;
451  } else {
452  prompt = PROMPT_CONT;
453  }
454  putPrompt();
455 }
456 
457 ConsoleLine CommandConsole::highLight(string_view line)
458 {
459  ConsoleLine result;
460  result.addChunk(prompt, 0xffffff);
461 
462  TclParser parser = commandController.getInterpreter().parse(line);
463  string colors = parser.getColors();
464  assert(colors.size() == line.size());
465 
466  unsigned pos = 0;
467  while (pos != colors.size()) {
468  char col = colors[pos];
469  unsigned pos2 = pos++;
470  while ((pos != colors.size()) && (colors[pos] == col)) {
471  ++pos;
472  }
473  // TODO make these color configurable?
474  unsigned rgb;
475  switch (col) {
476  case 'E': rgb = 0xff0000; break; // error
477  case 'c': rgb = 0x5c5cff; break; // comment
478  case 'v': rgb = 0x00ffff; break; // variable
479  case 'l': rgb = 0xff00ff; break; // literal
480  case 'p': rgb = 0xcdcd00; break; // proc
481  case 'o': rgb = 0x00cdcd; break; // operator
482  default: rgb = 0xffffff; break; // other
483  }
484  result.addChunk(line.substr(pos2, pos - pos2), rgb);
485  }
486  return result;
487 }
488 
489 void CommandConsole::putPrompt()
490 {
491  commandScrollBack = unsigned(history.size());
492  currentLine.clear();
493  lines[0] = highLight(currentLine);
494  cursorPosition = unsigned(prompt.size());
495 }
496 
497 void CommandConsole::tabCompletion()
498 {
499  resetScrollBack();
500  auto pl = unsigned(prompt.size());
501  string front(utf8::unchecked::substr(lines[0].str(), pl, cursorPosition - pl));
502  string back (utf8::unchecked::substr(lines[0].str(), cursorPosition));
503  string newFront = commandController.tabCompletion(front);
504  cursorPosition = pl + unsigned(utf8::unchecked::size(newFront));
505  currentLine = newFront + back;
506  lines[0] = highLight(currentLine);
507 }
508 
509 void CommandConsole::scroll(int delta)
510 {
511  consoleScrollBack = max(min(consoleScrollBack + delta, int(lines.size()) - int(rows)), 0);
512 }
513 
514 // Returns the position of the start of the word relative to the current cursor position.
515 // If the cursor is already located at the start of a word then return the start of the previous word.
516 // If there is no previous word, then return the start of the line (position of the prompt).
517 //
518 // One complication is that the line is utf8 encoded and the positions are
519 // given in character-counts instead of byte-counts. To solve this this
520 // function returns a tuple:
521 // * an iterator to the start of the word (likely the new cursor position).
522 // * an iterator to the current cursor position.
523 // * the distance (in characters, not bytes) between these two iterators.
524 // The first item in this tuple is the actual result. The other two are only
525 // returned for efficiency (this function calculates them anyway, and it's
526 // likely the caller will need them as well).
527 static std::tuple<std::string::const_iterator, std::string::const_iterator, unsigned>
528  getStartOfWord(const std::string& line, unsigned cursorPos, unsigned promptSize)
529 {
530  auto begin = std::begin(line);
531  auto prompt = begin + promptSize; // assumes prompt only contains single-byte utf8 chars
532  auto cursor = begin; utf8::unchecked::advance(cursor, cursorPos);
533  auto pos = cursor;
534 
535  // search (backwards) for first non-white-space
536  unsigned distance = 0;
537  while (pos > prompt) {
538  auto pos2 = pos;
540  if (*pos2 != one_of(' ', '\t')) break;
541  pos = pos2;
542  ++distance;
543  }
544  // search (backwards) for first white-space
545  while (pos > prompt) {
546  auto pos2 = pos;
548  if (*pos2 == one_of(' ', '\t')) break;
549  pos = pos2;
550  ++distance;
551  }
552  return {pos, cursor, distance};
553 }
554 
555 // Similar to getStartOfWord() but locates the end of the word instead.
556 // The end of the word is the 2nd (instead of the 1st) element in the tuple.
557 // This is done so that both getStartOfWord() and getEndOfWord() have the invariant:
558 // result = [begin, end, distance]
559 // -> begin <= end
560 // -> end - begin == distance
561 static std::tuple<std::string::const_iterator, std::string::const_iterator, unsigned>
562  getEndOfWord(const std::string& line, unsigned cursorPos)
563 {
564  auto begin = std::begin(line);
565  auto end = std::end (line);
566  auto cursor = begin; utf8::unchecked::advance(cursor, cursorPos);
567  auto pos = cursor;
568 
569  // search (forwards) for first non-white-space
570  unsigned distance = 0;
571  while ((pos < end) && (*pos == one_of(' ', '\t'))) {
572  ++pos; // single-byte utf8 character
573  ++distance;
574  }
575  // search (forwards) for first white-space
576  while ((pos < end) && (*pos != one_of(' ', '\t'))) {
578  ++distance;
579  }
580  return {cursor, pos, distance};
581 }
582 
583 void CommandConsole::gotoStartOfWord()
584 {
585  auto [begin, end, distance] = getStartOfWord(lines[0].str(), cursorPosition, prompt.size());
586  cursorPosition -= distance;
587 }
588 
589 void CommandConsole::deleteToStartOfWord()
590 {
591  resetScrollBack();
592  currentLine = lines[0].str();
593  auto [begin, end, distance] = getStartOfWord(currentLine, cursorPosition, prompt.size());
594  currentLine.erase(begin, end);
595  currentLine.erase(0, prompt.size());
596  lines[0] = highLight(currentLine);
597  cursorPosition -= distance;
598 }
599 
600 void CommandConsole::gotoEndOfWord()
601 {
602  auto [begin, end, distance] = getEndOfWord(lines[0].str(), cursorPosition);
603  cursorPosition += distance;
604 }
605 
606 void CommandConsole::deleteToEndOfWord()
607 {
608  resetScrollBack();
609  currentLine = lines[0].str();
610  auto [begin, end, distance] = getEndOfWord(currentLine, cursorPosition);
611  currentLine.erase(begin, end);
612  currentLine.erase(0, prompt.size());
613  lines[0] = highLight(currentLine);
614 }
615 
616 void CommandConsole::prevCommand()
617 {
618  resetScrollBack();
619  if (history.empty()) {
620  return; // no elements
621  }
622  bool match = false;
623  unsigned tmp = commandScrollBack;
624  while ((tmp != 0) && !match) {
625  --tmp;
626  match = StringOp::startsWith(history[tmp], currentLine);
627  }
628  if (match) {
629  commandScrollBack = tmp;
630  lines[0] = highLight(history[commandScrollBack]);
631  cursorPosition = unsigned(lines[0].numChars());
632  }
633 }
634 
635 void CommandConsole::nextCommand()
636 {
637  resetScrollBack();
638  if (commandScrollBack == history.size()) {
639  return; // don't loop !
640  }
641  bool match = false;
642  auto tmp = commandScrollBack;
643  while ((++tmp != history.size()) && !match) {
644  match = StringOp::startsWith(history[tmp], currentLine);
645  }
646  if (match) {
647  --tmp; // one time to many
648  commandScrollBack = tmp;
649  lines[0] = highLight(history[commandScrollBack]);
650  } else {
651  commandScrollBack = unsigned(history.size());
652  lines[0] = highLight(currentLine);
653  }
654  cursorPosition = unsigned(lines[0].numChars());
655 }
656 
657 void CommandConsole::clearCommand()
658 {
659  resetScrollBack();
660  commandBuffer.clear();
661  prompt = PROMPT_NEW;
662  currentLine.clear();
663  lines[0] = highLight(currentLine);
664  cursorPosition = unsigned(prompt.size());
665 }
666 
667 void CommandConsole::clearHistory()
668 {
669  resetScrollBack();
670  while (lines.size() > 1) {
671  lines.removeBack();
672  }
673 }
674 
675 void CommandConsole::backspace()
676 {
677  resetScrollBack();
678  if (cursorPosition > prompt.size()) {
679  currentLine = lines[0].str();
680  auto b = begin(currentLine);
681  utf8::unchecked::advance(b, cursorPosition - 1);
682  auto e = b;
684  currentLine.erase(b, e);
685  currentLine.erase(0, prompt.size());
686  lines[0] = highLight(currentLine);
687  --cursorPosition;
688  }
689 }
690 
691 void CommandConsole::delete_key()
692 {
693  resetScrollBack();
694  if (lines[0].numChars() > cursorPosition) {
695  currentLine = lines[0].str();
696  auto b = begin(currentLine);
697  utf8::unchecked::advance(b, cursorPosition);
698  auto e = b;
700  currentLine.erase(b, e);
701  currentLine.erase(0, prompt.size());
702  lines[0] = highLight(currentLine);
703  }
704 }
705 
706 void CommandConsole::normalKey(uint32_t chr)
707 {
708  assert(chr);
709  resetScrollBack();
710  currentLine = lines[0].str();
711  auto pos = begin(currentLine);
712  utf8::unchecked::advance(pos, cursorPosition);
713  utf8::unchecked::append(chr, inserter(currentLine, pos));
714  currentLine.erase(0, prompt.size());
715  lines[0] = highLight(currentLine);
716  ++cursorPosition;
717 }
718 
719 void CommandConsole::resetScrollBack()
720 {
721  consoleScrollBack = 0;
722 }
723 
724 static std::vector<std::string_view> splitLines(std::string_view str)
725 {
726  // This differs from StringOp::split() in two ways:
727  // - If the input is an empty string, then the resulting vector
728  // contains 1 element which is the empty string (StringOp::split()
729  // would return an empty vector).
730  // - If the input ends on a newline character, then the final item in
731  // the result vector is an empty string (StringOp::split() would not
732  // include that last empty string).
733  // TODO can we come up with a good name for this function and move it
734  // to StringOp?
735  std::vector<std::string_view> result;
736  while (true) {
737  auto pos = str.find_first_of('\n');
738  if (pos == std::string_view::npos) break;
739  result.push_back(str.substr(0, pos));
740  str = str.substr(pos + 1);
741  }
742  result.push_back(str);
743  return result;
744 }
745 
746 void CommandConsole::paste()
747 {
748  char* text = SDL_GetClipboardText();
749  if (!text) return;
750  scope_exit e([&]{ SDL_free(text); });
751 
752  auto pastedLines = splitLines(text);
753  assert(!pastedLines.empty());
754 
755  // helper function 'append()' to append to the existing text
756  std::string_view prefix = lines[0].str();
757  prefix.remove_prefix(prompt.size());
758  auto append = [&](std::string_view suffix) {
759  if (prefix.empty()) {
760  lines[0] = highLight(suffix);
761  } else {
762  lines[0] = highLight(strCat(prefix, suffix));
763  prefix = "";
764  }
765  };
766  // execute all but the last line
767  for (const auto& line : view::drop_back(pastedLines, 1)) {
768  append(line);
769  commandExecute();
770  }
771  // only enter (not execute) the last line
772  append(pastedLines.back());
773  cursorPosition = unsigned(lines[0].numChars());
774 }
775 
776 } // namespace openmsx
FileException.hh
TclParser
Definition: TclParser.hh:12
openmsx::PROMPT_CONT
constexpr const char *const PROMPT_CONT
Definition: CommandConsole.cc:72
utf8::is_pua
bool is_pua(uint32_t cp)
Definition: utf8_core.hh:256
openmsx::GlobalCommandController::getInterpreter
Interpreter & getInterpreter() override
Definition: GlobalCommandController.cc:123
scope_exit
Definition: scope_exit.hh:26
openmsx::Keys::KM_META
@ KM_META
Definition: Keys.hh:207
circular_buffer::pop_front
void pop_front()
Definition: circular_buffer.hh:231
StringOp::startsWith
bool startsWith(string_view total, string_view part)
Definition: StringOp.cc:71
openmsx::Interpreter::parse
TclParser parse(std::string_view command)
Definition: Interpreter.cc:447
gl::min
vecN< N, T > min(const vecN< N, T > &x, const vecN< N, T > &y)
Definition: gl_vec.hh:274
Display.hh
openmsx::Keys::K_A
@ K_A
Definition: Keys.hh:76
ScopedAssign
Assign new value to some variable and restore the original value when this object goes out of scope.
Definition: ScopedAssign.hh:8
TclParser::getColors
std::string getColors() const
Ouput: a string of equal length of the input command where each character indicates the type of the c...
Definition: TclParser.hh:28
openmsx::CommandConsole::getColumns
unsigned getColumns() const
Definition: CommandConsole.hh:72
utf8::unchecked::next
uint32_t next(octet_iterator &it)
Definition: utf8_unchecked.hh:64
openmsx::GlobalCommandController::getCliComm
CliComm & getCliComm() override
Definition: GlobalCommandController.cc:118
view::drop_back
auto drop_back(Range &&range, size_t n)
Definition: view.hh:294
utf8::unchecked::size
size_t size(std::string_view utf8)
Definition: utf8_unchecked.hh:227
scope_exit.hh
openmsx::CommandConsole::~CommandConsole
~CommandConsole()
Definition: CommandConsole.cc:122
utf8::unchecked::substr
std::string_view substr(std::string_view utf8, std::string_view::size_type first=0, std::string_view::size_type len=std::string_view::npos)
Definition: utf8_unchecked.hh:231
openmsx::GlobalCommandController::executeCommand
TclObject executeCommand(const std::string &command, CliConnection *connection=nullptr) override
Execute the given command.
Definition: GlobalCommandController.cc:301
openmsx::GlobalCommandController::tabCompletion
std::string tabCompletion(std::string_view command)
Complete the given command.
Definition: GlobalCommandController.cc:319
openmsx::Keys::K_C
@ K_C
Definition: Keys.hh:78
Interpreter.hh
circular_buffer::push_back
void push_back(const T &t)
Definition: circular_buffer.hh:216
openmsx::userFileContext
FileContext userFileContext(string_view savePath)
Definition: FileContext.cc:164
CommandConsole.hh
openmsx::Keys::K_RIGHT
@ K_RIGHT
Definition: Keys.hh:126
utf8::unchecked::advance
void advance(octet_iterator &it, distance_type n)
Definition: utf8_unchecked.hh:108
strAppend
void strAppend(std::string &result, Ts &&...ts)
Definition: strCat.hh:644
openmsx::OPENMSX_KEY_DOWN_EVENT
@ OPENMSX_KEY_DOWN_EVENT
Definition: Event.hh:13
openmsx::FileOperations::openofstream
void openofstream(std::ofstream &stream, const std::string &filename)
Open an ofstream in a platform-independent manner.
Definition: FileOperations.cc:367
openmsx::Setting
Definition: Setting.hh:120
openmsx::EventDistributor
Definition: EventDistributor.hh:17
ScopedAssign.hh
openmsx::ConsoleLine::chunkColor
uint32_t chunkColor(size_t i) const
Get the color for the i-th chunk.
Definition: CommandConsole.cc:53
openmsx::Display::repaintDelayed
void repaintDelayed(uint64_t delta)
Definition: Display.cc:367
circular_buffer::empty
bool empty() const
Definition: circular_buffer.hh:196
Version.hh
circular_buffer::back
auto & back()
Definition: circular_buffer.hh:192
openmsx::Interpreter::setOutput
void setOutput(InterpreterOutput *output_)
Definition: Interpreter.hh:25
openmsx::PROMPT_NEW
constexpr const char *const PROMPT_NEW
Definition: CommandConsole.cc:71
openmsx::CliComm::printWarning
void printWarning(std::string_view message)
Definition: CliComm.cc:10
openmsx::EventDistributor::HOTKEY
@ HOTKEY
Definition: EventDistributor.hh:27
openmsx::Keys::K_H
@ K_H
Definition: Keys.hh:83
openmsx::Keys::K_DOWN
@ K_DOWN
Definition: Keys.hh:125
openmsx::EventDistributor::MSX
@ MSX
Definition: EventDistributor.hh:28
utf8_unchecked.hh
openmsx::ConsoleLine::addChunk
void addChunk(std::string_view text, uint32_t rgb)
Append a chunk with a (different) color.
Definition: CommandConsole.cc:42
openmsx::Keys::KM_ALT
@ KM_ALT
Definition: Keys.hh:206
one_of
Definition: one_of.hh:7
EventDistributor.hh
utf8::unchecked::append
octet_iterator append(uint32_t cp, octet_iterator result)
Definition: utf8_unchecked.hh:39
InputEvents.hh
openmsx::Keys::K_D
@ K_D
Definition: Keys.hh:79
utf8::distance
auto distance(octet_iterator first, octet_iterator last)
Definition: utf8_checked.hh:194
openmsx::FileException
Definition: FileException.hh:9
openmsx::Keys::KM_CTRL
@ KM_CTRL
Definition: Keys.hh:205
openmsx::Keys::K_DELETE
@ K_DELETE
Definition: Keys.hh:102
circular_buffer::full
bool full() const
Definition: circular_buffer.hh:197
view.hh
Keys.hh
openmsx::Keys::K_BACKSPACE
@ K_BACKSPACE
Definition: Keys.hh:31
FileContext.hh
openmsx::EventDistributor::CONSOLE
@ CONSOLE
Definition: EventDistributor.hh:26
FileOperations.hh
checked_cast.hh
openmsx::Keys::K_KP_ENTER
@ K_KP_ENTER
Definition: Keys.hh:120
openmsx::Keys::K_K
@ K_K
Definition: Keys.hh:86
openmsx::Keys::KM_SHIFT
@ KM_SHIFT
Definition: Keys.hh:204
openmsx::CommandConsole::CommandConsole
CommandConsole(GlobalCommandController &commandController, EventDistributor &eventDistributor, Display &display)
Definition: CommandConsole.cc:75
openmsx::Keys::K_V
@ K_V
Definition: Keys.hh:97
openmsx::Keys::K_UP
@ K_UP
Definition: Keys.hh:124
StringOp.hh
openmsx::Keys::K_L
@ K_L
Definition: Keys.hh:87
openmsx::Display
Represents the output window/screen of openMSX.
Definition: Display.hh:33
openmsx::Keys::K_LEFT
@ K_LEFT
Definition: Keys.hh:127
GlobalCommandController.hh
openmsx::TclObject::getString
std::string_view getString() const
Definition: TclObject.cc:102
openmsx::GlobalCommandController::isComplete
bool isComplete(const std::string &command)
Returns true iff the command is complete (all braces, quotes etc.
Definition: GlobalCommandController.cc:296
openmsx::ConsoleLine::numChars
size_t numChars() const
Get the number of UTF8 characters in this line.
Definition: CommandConsole.cc:48
openmsx::Keys::K_RETURN
@ K_RETURN
Definition: Keys.hh:34
detail::append
void append(Result &)
Definition: stl.hh:335
gl::max
vecN< N, T > max(const vecN< N, T > &x, const vecN< N, T > &y)
Definition: gl_vec.hh:292
openmsx::Version::full
static std::string full()
Definition: Version.cc:8
openmsx::OPENMSX_KEY_UP_EVENT
@ OPENMSX_KEY_UP_EVENT
Definition: Event.hh:12
openmsx::EventDistributor::registerEventListener
void registerEventListener(EventType type, EventListener &listener, Priority priority=OTHER)
Registers a given object to receive certain events.
Definition: EventDistributor.cc:23
CliComm.hh
openmsx::Keys::K_PAGEDOWN
@ K_PAGEDOWN
Definition: Keys.hh:132
openmsx::CommandConsole::getCursorPosition
void getCursorPosition(unsigned &xPosition, unsigned &yPosition) const
Definition: CommandConsole.cc:164
openmsx::EventDistributor::unregisterEventListener
void unregisterEventListener(EventType type, EventListener &listener)
Unregisters a previously registered event listener.
Definition: EventDistributor.cc:35
openmsx::Keys::K_TAB
@ K_TAB
Definition: Keys.hh:32
strCat
std::string strCat(Ts &&...ts)
Definition: strCat.hh:573
CommandException.hh
openmsx::GlobalCommandController
Definition: GlobalCommandController.hh:37
openmsx::ConsoleLine::ConsoleLine
ConsoleLine()=default
Construct empty line.
openmsx
This file implemented 3 utility functions:
Definition: Autofire.cc:5
circular_buffer::size
size_t size() const
Definition: circular_buffer.hh:195
openmsx::Keys::K_MASK
@ K_MASK
Definition: Keys.hh:27
openmsx::Keys::K_PAGEUP
@ K_PAGEUP
Definition: Keys.hh:131
openmsx::BooleanSetting::getBoolean
bool getBoolean() const noexcept
Definition: BooleanSetting.hh:17
xrange.hh
openmsx::Keys::K_HOME
@ K_HOME
Definition: Keys.hh:129
openmsx::PROMPT_BUSY
constexpr const char *const PROMPT_BUSY
Definition: CommandConsole.cc:73
openmsx::CommandConsole::getRows
unsigned getRows() const
Definition: CommandConsole.hh:74
utf8::unchecked::prior
uint32_t prior(octet_iterator &it)
Definition: utf8_unchecked.hh:100
Completer.hh
openmsx::ConsoleLine::chunkText
std::string_view chunkText(size_t i) const
Get the text for the i-th chunk.
Definition: CommandConsole.cc:59
openmsx::Keys::K_END
@ K_END
Definition: Keys.hh:130
openmsx::Completer::setOutput
static void setOutput(InterpreterOutput *output_)
Definition: Completer.hh:65
openmsx::Keys::K_E
@ K_E
Definition: Keys.hh:80