Mercurial > hg > CbC > CbC_llvm
diff lldb/source/Host/common/Editline.cpp @ 173:0572611fdcc8 llvm10 llvm12
reorgnization done
author | Shinji KONO <kono@ie.u-ryukyu.ac.jp> |
---|---|
date | Mon, 25 May 2020 11:55:54 +0900 |
parents | 1d019706d866 |
children | 2e18cbf3894f |
line wrap: on
line diff
--- a/lldb/source/Host/common/Editline.cpp Mon May 25 11:50:15 2020 +0900 +++ b/lldb/source/Host/common/Editline.cpp Mon May 25 11:55:54 2020 +0900 @@ -35,7 +35,7 @@ // with until TERM is set to VT100 where it stumbles over an implementation // assumption that may not exist on other platforms. The setupterm() function // would normally require headers that don't work gracefully in this context, -// so the function declaraction has been hoisted here. +// so the function declaration has been hoisted here. #if defined(__APPLE__) extern "C" { int setupterm(char *term, int fildes, int *errret); @@ -99,18 +99,24 @@ static int GetOperation(HistoryOperation op) { // The naming used by editline for the history operations is counter - // intuitive to how it's used here. + // intuitive to how it's used in LLDB's editline implementation. + // + // - The H_LAST returns the oldest entry in the history. // // - The H_PREV operation returns the previous element in the history, which // is newer than the current one. // + // - The H_CURR returns the current entry in the history. + // // - The H_NEXT operation returns the next element in the history, which is // older than the current one. // + // - The H_FIRST returns the most recent entry in the history. + // // The naming of the enum entries match the semantic meaning. switch(op) { case HistoryOperation::Oldest: - return H_FIRST; + return H_LAST; case HistoryOperation::Older: return H_NEXT; case HistoryOperation::Current: @@ -118,7 +124,7 @@ case HistoryOperation::Newer: return H_PREV; case HistoryOperation::Newest: - return H_LAST; + return H_FIRST; } llvm_unreachable("Fully covered switch!"); } @@ -138,10 +144,10 @@ while (start < input.length()) { size_t end = input.find('\n', start); if (end == std::string::npos) { - result.insert(result.end(), input.substr(start)); + result.push_back(input.substr(start)); break; } - result.insert(result.end(), input.substr(start, end - start)); + result.push_back(input.substr(start, end - start)); start = end + 1; } return result; @@ -296,19 +302,16 @@ // Editline private methods void Editline::SetBaseLineNumber(int line_number) { - std::stringstream line_number_stream; - line_number_stream << line_number; m_base_line_number = line_number; m_line_number_digits = - std::max(3, (int)line_number_stream.str().length() + 1); + std::max<int>(3, std::to_string(line_number).length() + 1); } std::string Editline::PromptForIndex(int line_index) { bool use_line_numbers = m_multiline_enabled && m_base_line_number > 0; std::string prompt = m_set_prompt; - if (use_line_numbers && prompt.length() == 0) { + if (use_line_numbers && prompt.length() == 0) prompt = ": "; - } std::string continuation_prompt = prompt; if (m_set_continuation_prompt.length() > 0) { continuation_prompt = m_set_continuation_prompt; @@ -423,7 +426,7 @@ } int Editline::CountRowsForLine(const EditLineStringType &content) { - auto prompt = + std::string prompt = PromptForIndex(0); // Prompt width is constant during an edit session int line_length = (int)(content.length() + prompt.length()); return (line_length / m_terminal_width) + 1; @@ -557,6 +560,9 @@ lldb::ConnectionStatus status = lldb::eConnectionStatusSuccess; char ch = 0; + if (m_terminal_size_has_changed) + ApplyTerminalSizeChange(); + // This mutex is locked by our caller (GetLine). Unlock it while we read a // character (blocking operation), so we do not hold the mutex // indefinitely. This gives a chance for someone to interrupt us. After @@ -1049,7 +1055,7 @@ m_editline = el_init(m_editor_name.c_str(), m_input_file, m_output_file, m_error_file); - TerminalSizeChanged(); + ApplyTerminalSizeChange(); if (m_history_sp && m_history_sp->IsValid()) { if (!m_history_sp->Load()) { @@ -1302,28 +1308,32 @@ continuation_prompt == nullptr ? "" : continuation_prompt; } -void Editline::TerminalSizeChanged() { - if (m_editline != nullptr) { - el_resize(m_editline); - int columns; - // This function is documenting as taking (const char *, void *) for the - // vararg part, but in reality in was consuming arguments until the first - // null pointer. This was fixed in libedit in April 2019 - // <http://mail-index.netbsd.org/source-changes/2019/04/26/msg105454.html>, - // but we're keeping the workaround until a version with that fix is more - // widely available. - if (el_get(m_editline, EL_GETTC, "co", &columns, nullptr) == 0) { - m_terminal_width = columns; - if (m_current_line_rows != -1) { - const LineInfoW *info = el_wline(m_editline); - int lineLength = - (int)((info->lastchar - info->buffer) + GetPromptWidth()); - m_current_line_rows = (lineLength / columns) + 1; - } - } else { - m_terminal_width = INT_MAX; - m_current_line_rows = 1; +void Editline::TerminalSizeChanged() { m_terminal_size_has_changed = 1; } + +void Editline::ApplyTerminalSizeChange() { + if (!m_editline) + return; + + m_terminal_size_has_changed = 0; + el_resize(m_editline); + int columns; + // This function is documenting as taking (const char *, void *) for the + // vararg part, but in reality in was consuming arguments until the first + // null pointer. This was fixed in libedit in April 2019 + // <http://mail-index.netbsd.org/source-changes/2019/04/26/msg105454.html>, + // but we're keeping the workaround until a version with that fix is more + // widely available. + if (el_get(m_editline, EL_GETTC, "co", &columns, nullptr) == 0) { + m_terminal_width = columns; + if (m_current_line_rows != -1) { + const LineInfoW *info = el_wline(m_editline); + int lineLength = + (int)((info->lastchar - info->buffer) + GetPromptWidth()); + m_current_line_rows = (lineLength / columns) + 1; } + } else { + m_terminal_width = INT_MAX; + m_current_line_rows = 1; } }