LLDB mainline
DefaultHighlighter.cpp
Go to the documentation of this file.
1//===----------------------------------------------------------------------===//
2//
3// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4// See https://llvm.org/LICENSE.txt for license information.
5// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6//
7//===----------------------------------------------------------------------===//
8
10
11using namespace lldb_private;
12
14
16 llvm::StringRef line,
17 std::optional<size_t> cursor_pos,
18 llvm::StringRef previous_lines,
19 Stream &s) const {
20 // If we don't have a valid cursor, then we just print the line as-is.
21 if (!cursor_pos || *cursor_pos >= line.size()) {
22 s << line;
23 return;
24 }
25
26 // If we have a valid cursor, we have to apply the 'selected' style around
27 // the character below the cursor.
28
29 // Split the line around the character which is below the cursor.
30 size_t column = *cursor_pos;
31 // Print the characters before the cursor.
32 s << line.substr(0, column);
33 // Print the selected character with the defined color codes.
34 options.selected.Apply(s, line.substr(column, 1));
35 // Print the rest of the line.
36 s << line.substr(column + 1U);
37}
38
42
47
#define LLDB_PLUGIN_DEFINE_ADV(ClassName, PluginName)
A default highlighter that only highlights the user cursor, but doesn't do any other highlighting.
static llvm::StringRef GetPluginNameStatic()
static Highlighter * CreateInstance(lldb::LanguageType language)
void Highlight(const HighlightStyle &options, llvm::StringRef line, std::optional< size_t > cursor_pos, llvm::StringRef previous_lines, Stream &s) const override
Highlights the given line.
static bool RegisterPlugin(llvm::StringRef name, llvm::StringRef description, ABICreateInstance create_callback)
static bool UnregisterPlugin(ABICreateInstance create_callback)
A stream class that can stream formatted output to a file.
Definition Stream.h:28
A class that represents a running process on the host machine.
LanguageType
Programming language type.
Represents style that the highlighter should apply to the given source code.
Definition Highlighter.h:25