Skip to content

Commit 2677728

Browse files
authored
[lldb] Underline short option letters as mnemonics (#153695)
Whenever an option would use something other than the first letter of the long option as the short option, Jim would capitalized the letter we picked as a mnemonic. This has often been mistaken for a typo and Jim wondered if we should stop doing this. During the discussion, David mentioned how this reminds him of the underline in menu bars when holding down alt. I suggested we do something similar in LLDB by underlying the letter in the description. https://discourse.llvm.org/t/should-we-remove-the-capital-letter-in-option-helps/87816
1 parent abb18dd commit 2677728

File tree

7 files changed

+49
-24
lines changed

7 files changed

+49
-24
lines changed

lldb/include/lldb/Interpreter/Options.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -85,10 +85,10 @@ class Options {
8585

8686
void OutputFormattedUsageText(Stream &strm,
8787
const OptionDefinition &option_def,
88-
uint32_t output_max_columns);
88+
uint32_t output_max_columns, bool use_color);
8989

9090
void GenerateOptionUsage(Stream &strm, CommandObject &cmd,
91-
uint32_t screen_width);
91+
uint32_t screen_width, bool use_color);
9292

9393
bool SupportsLongOption(const char *long_option);
9494

lldb/source/Commands/CommandObjectDisassemble.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -503,8 +503,9 @@ void CommandObjectDisassemble::DoExecute(Args &command,
503503
"\"disassemble\" arguments are specified as options.\n");
504504
const int terminal_width =
505505
GetCommandInterpreter().GetDebugger().GetTerminalWidth();
506+
const bool use_color = GetCommandInterpreter().GetDebugger().GetUseColor();
506507
GetOptions()->GenerateOptionUsage(result.GetErrorStream(), *this,
507-
terminal_width);
508+
terminal_width, use_color);
508509
return;
509510
}
510511

lldb/source/Commands/CommandObjectFrame.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -349,7 +349,8 @@ class CommandObjectFrameSelect : public CommandObjectParsed {
349349
command[0].c_str());
350350
m_options.GenerateOptionUsage(
351351
result.GetErrorStream(), *this,
352-
GetCommandInterpreter().GetDebugger().GetTerminalWidth());
352+
GetCommandInterpreter().GetDebugger().GetTerminalWidth(),
353+
GetCommandInterpreter().GetDebugger().GetUseColor());
353354
return;
354355
}
355356

lldb/source/Commands/CommandObjectTarget.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4075,7 +4075,8 @@ class CommandObjectTargetModulesLookup : public CommandObjectParsed {
40754075
default:
40764076
m_options.GenerateOptionUsage(
40774077
result.GetErrorStream(), *this,
4078-
GetCommandInterpreter().GetDebugger().GetTerminalWidth());
4078+
GetCommandInterpreter().GetDebugger().GetTerminalWidth(),
4079+
GetCommandInterpreter().GetDebugger().GetUseColor());
40794080
syntax_error = true;
40804081
break;
40814082
}

lldb/source/Commands/Options.td

Lines changed: 29 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -741,18 +741,35 @@ let Command = "process launch" in {
741741
}
742742

743743
let Command = "process attach" in {
744-
def process_attach_continue : Option<"continue", "c">,
745-
Desc<"Immediately continue the process once attached.">;
746-
def process_attach_plugin : Option<"plugin", "P">, Arg<"Plugin">,
747-
Desc<"Name of the process plugin you want to use.">;
748-
def process_attach_pid : Option<"pid", "p">, Group<1>, Arg<"Pid">,
749-
Desc<"The process ID of an existing process to attach to.">;
750-
def process_attach_name : Option<"name", "n">, Group<2>, Arg<"ProcessName">,
751-
Desc<"The name of the process to attach to.">;
752-
def process_attach_include_existing : Option<"include-existing", "i">,
753-
Group<2>, Desc<"Include existing processes when doing attach -w.">;
754-
def process_attach_waitfor : Option<"waitfor", "w">, Group<2>,
755-
Desc<"Wait for the process with <process-name> to launch.">;
744+
def process_attach_continue
745+
: Option<"continue", "c">,
746+
Desc<"Immediately ${ansi.underline}c${ansi.normal}ontinue the process "
747+
"once attached.">;
748+
def process_attach_plugin
749+
: Option<"plugin", "P">,
750+
Arg<"Plugin">,
751+
Desc<"Name of the process ${ansi.underline}p${ansi.normal}lugin you "
752+
"want to use.">;
753+
def process_attach_pid : Option<"pid", "p">,
754+
Group<1>,
755+
Arg<"Pid">,
756+
Desc<"The ${ansi.underline}p${ansi.normal}rocess ID "
757+
"of an existing process to attach to.">;
758+
def process_attach_name : Option<"name", "n">,
759+
Group<2>,
760+
Arg<"ProcessName">,
761+
Desc<"The ${ansi.underline}n${ansi.normal}ame of "
762+
"the process to attach to.">;
763+
def process_attach_include_existing
764+
: Option<"include-existing", "i">,
765+
Group<2>,
766+
Desc<"${ansi.underline}I${ansi.normal}nclude existing processes when "
767+
"doing attach -w.">;
768+
def process_attach_waitfor
769+
: Option<"waitfor", "w">,
770+
Group<2>,
771+
Desc<"${ansi.underline}W${ansi.normal}ait for the process with "
772+
"<process-name> to launch.">;
756773
}
757774

758775
let Command = "process continue" in {

lldb/source/Interpreter/CommandObject.cpp

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -359,7 +359,8 @@ bool CommandObject::HelpTextContainsWord(llvm::StringRef search_word,
359359
StreamString usage_help;
360360
GetOptions()->GenerateOptionUsage(
361361
usage_help, *this,
362-
GetCommandInterpreter().GetDebugger().GetTerminalWidth());
362+
GetCommandInterpreter().GetDebugger().GetTerminalWidth(),
363+
GetCommandInterpreter().GetDebugger().GetUseColor());
363364
if (!usage_help.Empty()) {
364365
llvm::StringRef usage_text = usage_help.GetString();
365366
if (usage_text.contains_insensitive(search_word))
@@ -672,7 +673,8 @@ void CommandObject::GenerateHelpText(Stream &output_strm) {
672673
if (options != nullptr) {
673674
options->GenerateOptionUsage(
674675
output_strm, *this,
675-
GetCommandInterpreter().GetDebugger().GetTerminalWidth());
676+
GetCommandInterpreter().GetDebugger().GetTerminalWidth(),
677+
GetCommandInterpreter().GetDebugger().GetUseColor());
676678
}
677679
llvm::StringRef long_help = GetHelpLong();
678680
if (!long_help.empty()) {

lldb/source/Interpreter/Options.cpp

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
#include "lldb/Interpreter/CommandObject.h"
2020
#include "lldb/Interpreter/CommandReturnObject.h"
2121
#include "lldb/Target/Target.h"
22+
#include "lldb/Utility/AnsiTerminal.h"
2223
#include "lldb/Utility/DiagnosticsRendering.h"
2324
#include "lldb/Utility/StreamString.h"
2425
#include "llvm/ADT/STLExtras.h"
@@ -261,7 +262,8 @@ Option *Options::GetLongOptions() {
261262

262263
void Options::OutputFormattedUsageText(Stream &strm,
263264
const OptionDefinition &option_def,
264-
uint32_t output_max_columns) {
265+
uint32_t output_max_columns,
266+
bool use_color) {
265267
std::string actual_text;
266268
if (option_def.validator) {
267269
const char *condition = option_def.validator->ShortConditionString();
@@ -278,7 +280,7 @@ void Options::OutputFormattedUsageText(Stream &strm,
278280
if (static_cast<uint32_t>(actual_text.length() + strm.GetIndentLevel()) <
279281
output_max_columns) {
280282
// Output it as a single line.
281-
strm.Indent(actual_text);
283+
strm.Indent(ansi::FormatAnsiTerminalCodes(actual_text, use_color));
282284
strm.EOL();
283285
} else {
284286
// We need to break it up into multiple lines.
@@ -312,7 +314,8 @@ void Options::OutputFormattedUsageText(Stream &strm,
312314
strm.Indent();
313315
assert(start < final_end);
314316
assert(start + sub_len <= final_end);
315-
strm.Write(actual_text.c_str() + start, sub_len);
317+
strm.PutCString(ansi::FormatAnsiTerminalCodes(
318+
llvm::StringRef(actual_text.c_str() + start, sub_len), use_color));
316319
start = end + 1;
317320
}
318321
strm.EOL();
@@ -385,7 +388,7 @@ static bool PrintOption(const OptionDefinition &opt_def,
385388
}
386389

387390
void Options::GenerateOptionUsage(Stream &strm, CommandObject &cmd,
388-
uint32_t screen_width) {
391+
uint32_t screen_width, bool use_color) {
389392
auto opt_defs = GetDefinitions();
390393
const uint32_t save_indent_level = strm.GetIndentLevel();
391394
llvm::StringRef name = cmd.GetCommandName();
@@ -527,7 +530,7 @@ void Options::GenerateOptionUsage(Stream &strm, CommandObject &cmd,
527530
strm.IndentMore(5);
528531

529532
if (opt_def.usage_text)
530-
OutputFormattedUsageText(strm, opt_def, screen_width);
533+
OutputFormattedUsageText(strm, opt_def, screen_width, use_color);
531534
if (!opt_def.enum_values.empty()) {
532535
strm.Indent();
533536
strm.Printf("Values: ");

0 commit comments

Comments
 (0)