[Lldb-commits] [lldb] [lldb] Improve editline completion formatting (PR #116456)
Pavel Labath via lldb-commits
lldb-commits at lists.llvm.org
Mon Nov 18 00:59:15 PST 2024
================
@@ -927,12 +927,92 @@ unsigned char Editline::BufferEndCommand(int ch) {
static void
PrintCompletion(FILE *output_file,
llvm::ArrayRef<CompletionResult::Completion> results,
- size_t max_len) {
+ size_t max_completion_length, size_t max_lenght) {
+
+ constexpr size_t ellipsis_length = 3;
+ constexpr size_t tab_legnth = 8;
+ constexpr size_t separator_length = 4;
+ const size_t description_col =
+ std::min(max_completion_length + tab_legnth, max_lenght);
+
for (const CompletionResult::Completion &c : results) {
- fprintf(output_file, "\t%-*s", (int)max_len, c.GetCompletion().c_str());
- if (!c.GetDescription().empty())
- fprintf(output_file, " -- %s", c.GetDescription().c_str());
- fprintf(output_file, "\n");
+ // Print the leading tab-sized padding.
+ fprintf(output_file, " ");
+ size_t cursor = tab_legnth;
+
+ if (!c.GetCompletion().empty()) {
+ const size_t completion_length = c.GetCompletion().size();
+ if (cursor + completion_length < max_lenght) {
+ fprintf(output_file, "%s", c.GetCompletion().c_str());
+ cursor = cursor + completion_length;
+ } else {
+ // If the completion doesn't fit on the screen, print ellipsis and don't
+ // bother with the description.
+ fprintf(output_file, "%s...\n",
+ c.GetCompletion()
+ .substr(0, max_lenght - cursor - ellipsis_length)
+ .c_str());
----------------
labath wrote:
```suggestion
fprintf(output_file, "%.*s...\n", max_length - cursor - ellipsis_length,
c.GetCompletion()
.c_str());
```
https://github.com/llvm/llvm-project/pull/116456
More information about the lldb-commits
mailing list