diff options
author | Kate Stone <katherine.stone@apple.com> | 2015-07-14 05:48:36 +0000 |
---|---|---|
committer | Kate Stone <katherine.stone@apple.com> | 2015-07-14 05:48:36 +0000 |
commit | ea671fbdffda6976607997eb2e5d796211cf5003 (patch) | |
tree | 24e6b00951c3ddccba9afad5f20faaf338d8ff81 /lldb/source/Interpreter/CommandObject.cpp | |
parent | 2ffb36e829f79d3660b7a2cf94a1746f62a81518 (diff) | |
download | llvm-ea671fbdffda6976607997eb2e5d796211cf5003.zip llvm-ea671fbdffda6976607997eb2e5d796211cf5003.tar.gz llvm-ea671fbdffda6976607997eb2e5d796211cf5003.tar.bz2 |
Fixed line wrapping for the "long help" content in LLDB commands. Content is now dynamically wrapped for the column width of the current terminal. Lines that begin with whitespace will be indented identically on subsequent lines to maintain formatting.
Existing commands supplying this type of help content have been reworked to take advantage of the changes. In addition to formatting changes, content was changes for accuracy and clarity purposes.
<rdar://problem/21269977>
llvm-svn: 242122
Diffstat (limited to 'lldb/source/Interpreter/CommandObject.cpp')
-rw-r--r-- | lldb/source/Interpreter/CommandObject.cpp | 26 |
1 files changed, 24 insertions, 2 deletions
diff --git a/lldb/source/Interpreter/CommandObject.cpp b/lldb/source/Interpreter/CommandObject.cpp index d67f76e..c0efd9e 100644 --- a/lldb/source/Interpreter/CommandObject.cpp +++ b/lldb/source/Interpreter/CommandObject.cpp @@ -10,6 +10,7 @@ #include "lldb/Interpreter/CommandObject.h" #include <string> +#include <sstream> #include <map> #include <stdlib.h> @@ -921,6 +922,27 @@ ExprPathHelpTextCallback() } void +CommandObject::FormatLongHelpText (Stream &output_strm, const char *long_help) +{ + CommandInterpreter& interpreter = GetCommandInterpreter(); + std::stringstream lineStream (long_help); + std::string line; + while (std::getline (lineStream, line)) { + if (line.empty()) { + output_strm << "\n"; + continue; + } + size_t result = line.find_first_not_of (" \t"); + if (result == std::string::npos) { + result = 0; + } + std::string whitespace_prefix = line.substr (0, result); + std::string remainder = line.substr (result); + interpreter.OutputFormattedHelpText(output_strm, whitespace_prefix.c_str(), remainder.c_str()); + } +} + +void CommandObject::GenerateHelpText (CommandReturnObject &result) { GenerateHelpText(result.GetOutputStream()); @@ -947,7 +969,7 @@ CommandObject::GenerateHelpText (Stream &output_strm) const char *long_help = GetHelpLong(); if ((long_help != nullptr) && (strlen (long_help) > 0)) - output_strm.Printf ("\n%s", long_help); + FormatLongHelpText (output_strm, long_help); if (WantsRawCommandString() && !WantsCompletion()) { // Emit the message about using ' -- ' between the end of the command options and the raw input @@ -984,7 +1006,7 @@ CommandObject::GenerateHelpText (Stream &output_strm) const char *long_help = GetHelpLong(); if ((long_help != nullptr) && (strlen (long_help) > 0)) - output_strm.Printf ("%s", long_help); + FormatLongHelpText (output_strm, long_help); else if (WantsRawCommandString()) { std::string help_text (GetHelp()); |