Skip to content

Commit 3e23309

Browse files
Merge pull request #10536 from adrian-prantl/statusline-unicode
Statusline unicode
2 parents c89ea13 + a579d0b commit 3e23309

File tree

13 files changed

+131
-16
lines changed

13 files changed

+131
-16
lines changed

lldb/include/lldb/Core/Debugger.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -312,6 +312,9 @@ class Debugger : public std::enable_shared_from_this<Debugger>,
312312

313313
const FormatEntity::Entry *GetStatuslineFormat() const;
314314

315+
llvm::StringRef GetSeparator() const;
316+
bool SetSeparator(llvm::StringRef s);
317+
315318
llvm::StringRef GetShowProgressAnsiPrefix() const;
316319

317320
llvm::StringRef GetShowProgressAnsiSuffix() const;

lldb/include/lldb/Core/FormatEntity.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -103,6 +103,7 @@ struct Entry {
103103
CurrentPCArrow,
104104
ProgressCount,
105105
ProgressMessage,
106+
Separator,
106107
};
107108

108109
struct Definition {

lldb/include/lldb/Core/IOHandler.h

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,12 @@ class IOHandler {
9999
// Prompt support isn't mandatory
100100
return false;
101101
}
102+
103+
virtual bool SetUseColor(bool use_color) {
104+
// Color support isn't mandatory.
105+
return false;
106+
};
107+
102108
bool SetPrompt(const char *) = delete;
103109

104110
virtual llvm::StringRef GetControlSequence(char ch) { return {}; }
@@ -375,6 +381,8 @@ class IOHandlerEditline : public IOHandler {
375381
bool SetPrompt(llvm::StringRef prompt) override;
376382
bool SetPrompt(const char *prompt) = delete;
377383

384+
bool SetUseColor(bool use_color) override;
385+
378386
const char *GetContinuationPrompt();
379387

380388
void SetContinuationPrompt(llvm::StringRef prompt);

lldb/include/lldb/Host/Editline.h

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -168,6 +168,9 @@ class Editline {
168168
DisplayCompletions(Editline &editline,
169169
llvm::ArrayRef<CompletionResult::Completion> results);
170170

171+
/// Sets if editline should use color.
172+
void UseColor(bool use_color);
173+
171174
/// Sets a string to be used as a prompt, or combined with a line number to
172175
/// form a prompt.
173176
void SetPrompt(const char *prompt);
@@ -223,21 +226,29 @@ class Editline {
223226
void SetPromptAnsiPrefix(std::string prefix) {
224227
if (m_color)
225228
m_prompt_ansi_prefix = std::move(prefix);
229+
else
230+
m_prompt_ansi_prefix.clear();
226231
}
227232

228233
void SetPromptAnsiSuffix(std::string suffix) {
229234
if (m_color)
230235
m_prompt_ansi_suffix = std::move(suffix);
236+
else
237+
m_prompt_ansi_suffix.clear();
231238
}
232239

233240
void SetSuggestionAnsiPrefix(std::string prefix) {
234241
if (m_color)
235242
m_suggestion_ansi_prefix = std::move(prefix);
243+
else
244+
m_suggestion_ansi_prefix.clear();
236245
}
237246

238247
void SetSuggestionAnsiSuffix(std::string suffix) {
239248
if (m_color)
240249
m_suggestion_ansi_suffix = std::move(suffix);
250+
else
251+
m_suggestion_ansi_suffix.clear();
241252
}
242253

243254
/// Prompts for and reads a single line of user input.

lldb/include/lldb/Interpreter/CommandInterpreter.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -478,6 +478,8 @@ class CommandInterpreter : public Broadcaster,
478478

479479
void UpdatePrompt(llvm::StringRef prompt);
480480

481+
void UpdateUseColor(bool use_color);
482+
481483
bool Confirm(llvm::StringRef message, bool default_answer);
482484

483485
void LoadCommandDictionary();

lldb/source/Core/CoreProperties.td

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -229,10 +229,19 @@ let Definition = "debugger" in {
229229
Global,
230230
DefaultTrue,
231231
Desc<"Whether to show a statusline at the bottom of the terminal.">;
232-
def StatuslineFormat: Property<"statusline-format", "FormatEntity">,
233-
Global,
234-
DefaultStringValue<"${ansi.negative}{${target.file.basename}}{ | ${line.file.basename}:${line.number}:${line.column}}{ | ${thread.stop-reason}}{ | {${progress.count} }${progress.message}}">,
235-
Desc<"The default statusline format string.">;
232+
def Separator : Property<"separator", "String">,
233+
Global,
234+
DefaultStringValue<"│ ">,
235+
Desc<"A separator used, e.g., in the status line.">;
236+
def StatuslineFormat
237+
: Property<"statusline-format", "FormatEntity">,
238+
Global,
239+
DefaultStringValue<
240+
"${ansi.negative}{${target.file.basename}}{ "
241+
"${separator}${line.file.basename}:${line.number}:${line.column}}{ "
242+
"${separator}${thread.stop-reason}}{ "
243+
"${separator}{${progress.count} }${progress.message}}">,
244+
Desc<"The default statusline format string.">;
236245
def UseSourceCache: Property<"use-source-cache", "Boolean">,
237246
Global,
238247
DefaultTrue,

lldb/source/Core/Debugger.cpp

Lines changed: 31 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -234,16 +234,16 @@ Status Debugger::SetPropertyValue(const ExecutionContext *exe_ctx,
234234
CommandInterpreter::eBroadcastBitResetPrompt, bytes.release());
235235
GetCommandInterpreter().BroadcastEvent(prompt_change_event_sp);
236236
} else if (property_path == g_debugger_properties[ePropertyUseColor].name) {
237-
// use-color changed. Ping the prompt so it can reset the ansi terminal
238-
// codes.
239-
SetPrompt(GetPrompt());
237+
// use-color changed. set use-color, this also pings the prompt so it can
238+
// reset the ansi terminal codes.
239+
SetUseColor(GetUseColor());
240240
} else if (property_path ==
241241
g_debugger_properties[ePropertyPromptAnsiPrefix].name ||
242242
property_path ==
243243
g_debugger_properties[ePropertyPromptAnsiSuffix].name) {
244-
// Prompt colors changed. Ping the prompt so it can reset the ansi
245-
// terminal codes.
246-
SetPrompt(GetPrompt());
244+
// Prompt color changed. set use-color, this also pings the prompt so it
245+
// can reset the ansi terminal codes.
246+
SetUseColor(GetUseColor());
247247
} else if (property_path ==
248248
g_debugger_properties[ePropertyShowStatusline].name) {
249249
// Statusline setting changed. If we have a statusline instance, update it
@@ -253,7 +253,9 @@ Status Debugger::SetPropertyValue(const ExecutionContext *exe_ctx,
253253
else
254254
m_statusline.reset();
255255
} else if (property_path ==
256-
g_debugger_properties[ePropertyStatuslineFormat].name) {
256+
g_debugger_properties[ePropertyStatuslineFormat].name ||
257+
property_path ==
258+
g_debugger_properties[ePropertySeparator].name) {
257259
// Statusline format changed. Redraw the statusline.
258260
RedrawStatusline();
259261
} else if (property_path ==
@@ -443,6 +445,8 @@ bool Debugger::GetUseColor() const {
443445
bool Debugger::SetUseColor(bool b) {
444446
const uint32_t idx = ePropertyUseColor;
445447
bool ret = SetPropertyAtIndex(idx, b);
448+
449+
GetCommandInterpreter().UpdateUseColor(b);
446450
SetPrompt(GetPrompt());
447451
return ret;
448452
}
@@ -481,6 +485,19 @@ const FormatEntity::Entry *Debugger::GetStatuslineFormat() const {
481485
return GetPropertyAtIndexAs<const FormatEntity::Entry *>(idx);
482486
}
483487

488+
llvm::StringRef Debugger::GetSeparator() const {
489+
constexpr uint32_t idx = ePropertySeparator;
490+
return GetPropertyAtIndexAs<llvm::StringRef>(
491+
idx, g_debugger_properties[idx].default_cstr_value);
492+
}
493+
494+
bool Debugger::SetSeparator(llvm::StringRef s) {
495+
constexpr uint32_t idx = ePropertySeparator;
496+
bool ret = SetPropertyAtIndex(idx, s);
497+
RedrawStatusline();
498+
return ret;
499+
}
500+
484501
bool Debugger::GetUseAutosuggestion() const {
485502
const uint32_t idx = ePropertyShowAutosuggestion;
486503
return GetPropertyAtIndexAs<bool>(
@@ -974,11 +991,16 @@ Debugger::Debugger(lldb::LogOutputCallback log_callback, void *baton)
974991

975992
// Turn off use-color if this is a dumb terminal.
976993
const char *term = getenv("TERM");
977-
if (term && !strcmp(term, "dumb"))
994+
auto disable_color = [&]() {
978995
SetUseColor(false);
996+
SetSeparator("| ");
997+
};
998+
999+
if (term && !strcmp(term, "dumb"))
1000+
disable_color();
9791001
// Turn off use-color if we don't write to a terminal with color support.
9801002
if (!GetOutputFileSP()->GetIsTerminalWithColors())
981-
SetUseColor(false);
1003+
disable_color();
9821004

9831005
if (Diagnostics::Enabled()) {
9841006
m_diagnostics_callback_id = Diagnostics::Instance().AddCallback(

lldb/source/Core/FormatEntity.cpp

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -266,6 +266,7 @@ constexpr Definition g_top_level_entries[] = {
266266
g_var_child_entries, true),
267267
Entry::DefinitionWithChildren("progress", EntryType::Invalid,
268268
g_progress_child_entries),
269+
Definition("separator", EntryType::Separator),
269270
};
270271

271272
constexpr Definition g_root = Entry::DefinitionWithChildren(
@@ -367,6 +368,7 @@ const char *FormatEntity::Entry::TypeToCString(Type t) {
367368
ENUM_TO_CSTR(CurrentPCArrow);
368369
ENUM_TO_CSTR(ProgressCount);
369370
ENUM_TO_CSTR(ProgressMessage);
371+
ENUM_TO_CSTR(Separator);
370372
}
371373
return "???";
372374
}
@@ -1947,6 +1949,13 @@ bool FormatEntity::Format(const Entry &entry, Stream &s,
19471949
}
19481950
}
19491951
return false;
1952+
1953+
case Entry::Type::Separator:
1954+
if (Target *target = Target::GetTargetFromContexts(exe_ctx, sc)) {
1955+
s << target->GetDebugger().GetSeparator();
1956+
return true;
1957+
}
1958+
return false;
19501959
}
19511960

19521961
return false;

lldb/source/Core/IOHandler.cpp

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -476,6 +476,21 @@ bool IOHandlerEditline::SetPrompt(llvm::StringRef prompt) {
476476
return true;
477477
}
478478

479+
bool IOHandlerEditline::SetUseColor(bool use_color) {
480+
m_color = use_color;
481+
482+
#if LLDB_ENABLE_LIBEDIT
483+
if (m_editline_up) {
484+
m_editline_up->UseColor(use_color);
485+
m_editline_up->SetSuggestionAnsiPrefix(ansi::FormatAnsiTerminalCodes(
486+
m_debugger.GetAutosuggestionAnsiPrefix()));
487+
m_editline_up->SetSuggestionAnsiSuffix(ansi::FormatAnsiTerminalCodes(
488+
m_debugger.GetAutosuggestionAnsiSuffix()));
489+
}
490+
#endif
491+
return true;
492+
}
493+
479494
const char *IOHandlerEditline::GetContinuationPrompt() {
480495
return (m_continuation_prompt.empty() ? nullptr
481496
: m_continuation_prompt.c_str());

lldb/source/Host/common/Editline.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1113,6 +1113,8 @@ void Editline::DisplayCompletions(
11131113
}
11141114
}
11151115

1116+
void Editline::UseColor(bool use_color) { m_color = use_color; }
1117+
11161118
unsigned char Editline::TabCommand(int ch) {
11171119
if (!m_completion_callback)
11181120
return CC_ERROR;

0 commit comments

Comments
 (0)