25
25
#include " lldb/Utility/Timeout.h"
26
26
27
27
#include " llvm/Support/FileSystem.h"
28
+ #include " llvm/Support/Locale.h"
28
29
#include " llvm/Support/Threading.h"
29
30
30
31
using namespace lldb_private ;
@@ -101,6 +102,10 @@ bool IsOnlySpaces(const EditLineStringType &content) {
101
102
return true ;
102
103
}
103
104
105
+ static size_t ColumnWidth (llvm::StringRef str) {
106
+ return llvm::sys::locale::columnWidth (str);
107
+ }
108
+
104
109
static int GetOperation (HistoryOperation op) {
105
110
// The naming used by editline for the history operations is counter
106
111
// intuitive to how it's used in LLDB's editline implementation.
@@ -328,14 +333,16 @@ std::string Editline::PromptForIndex(int line_index) {
328
333
std::string continuation_prompt = prompt;
329
334
if (m_set_continuation_prompt.length () > 0 ) {
330
335
continuation_prompt = m_set_continuation_prompt;
331
-
332
336
// Ensure that both prompts are the same length through space padding
333
- while (continuation_prompt.length () < prompt.length ()) {
334
- continuation_prompt += ' ' ;
335
- }
336
- while (prompt.length () < continuation_prompt.length ()) {
337
- prompt += ' ' ;
338
- }
337
+ const size_t prompt_width = ColumnWidth (prompt);
338
+ const size_t cont_prompt_width = ColumnWidth (continuation_prompt);
339
+ const size_t padded_prompt_width =
340
+ std::max (prompt_width, cont_prompt_width);
341
+ if (prompt_width < padded_prompt_width)
342
+ prompt += std::string (padded_prompt_width - prompt_width, ' ' );
343
+ else if (cont_prompt_width < padded_prompt_width)
344
+ continuation_prompt +=
345
+ std::string (padded_prompt_width - cont_prompt_width, ' ' );
339
346
}
340
347
341
348
if (use_line_numbers) {
@@ -353,7 +360,7 @@ void Editline::SetCurrentLine(int line_index) {
353
360
m_current_prompt = PromptForIndex (line_index);
354
361
}
355
362
356
- int Editline::GetPromptWidth () { return ( int ) PromptForIndex (0 ). length ( ); }
363
+ size_t Editline::GetPromptWidth () { return ColumnWidth ( PromptForIndex (0 )); }
357
364
358
365
bool Editline::IsEmacs () {
359
366
const char *editor;
@@ -441,7 +448,7 @@ void Editline::DisplayInput(int firstIndex) {
441
448
int Editline::CountRowsForLine (const EditLineStringType &content) {
442
449
std::string prompt =
443
450
PromptForIndex (0 ); // Prompt width is constant during an edit session
444
- int line_length = (int )(content.length () + prompt. length ( ));
451
+ int line_length = (int )(content.length () + ColumnWidth (prompt ));
445
452
return (line_length / m_terminal_width) + 1 ;
446
453
}
447
454
0 commit comments