{
for (wchar_t ch : content)
{
- if (ch != EditLineCharType(' ')) return false;
+ if (ch != EditLineCharType(' '))
+ return false;
}
return true;
}
{
std::vector<EditLineStringType> result;
size_t start = 0;
- while (start < input.length()) {
+ while (start < input.length())
+ {
size_t end = input.find ('\n', start);
if (end == std::string::npos)
{
EditLineStringType
FixIndentation (const EditLineStringType & line, int indent_correction)
{
- if (indent_correction == 0) return line;
- if (indent_correction < 0) return line.substr (-indent_correction);
+ if (indent_correction == 0)
+ return line;
+ if (indent_correction < 0)
+ return line.substr (-indent_correction);
return EditLineStringType (indent_correction, EditLineCharType(' ')) + line;
}
int space_count = 0;
for (EditLineCharType ch : line)
{
- if (ch != EditLineCharType(' ')) break;
+ if (ch != EditLineCharType(' '))
+ break;
++space_count;
}
return space_count;
const LineInfoW * info = el_wline (m_editline);
for (const EditLineCharType * character = info->buffer; character < info->lastchar; character++)
{
- if (*character != ' ') return false;
+ if (*character != ' ')
+ return false;
}
return true;
}
PromptForIndex (index).c_str(),
unfaint,
m_input_lines[index].c_str());
- if (index < line_count - 1) fprintf (m_output_file, "\n");
+ if (index < line_count - 1)
+ fprintf (m_output_file, "\n");
}
}
StringList lines;
for (EditLineStringType line : m_input_lines)
{
- if (line_count == 0) break;
+ if (line_count == 0)
+ break;
#if LLDB_EDITLINE_USE_WCHAR
lines.AppendString (m_utf8conv.to_bytes (line));
#else
unsigned char
Editline::RecallHistory (bool earlier)
{
- if (!m_history_sp || !m_history_sp->IsValid()) return CC_ERROR;
+ if (!m_history_sp || !m_history_sp->IsValid())
+ return CC_ERROR;
HistoryW * pHistory = m_history_sp->GetHistoryPtr();
HistEventW history_event;
// Treat moving from the "live" entry differently
if (!m_in_history)
{
- if (earlier == false) return CC_ERROR; // Can't go newer than the "live" entry
- if (history_w (pHistory, &history_event, H_FIRST) == -1) return CC_ERROR;
+ if (earlier == false)
+ return CC_ERROR; // Can't go newer than the "live" entry
+ if (history_w (pHistory, &history_event, H_FIRST) == -1)
+ return CC_ERROR;
// Save any edits to the "live" entry in case we return by moving forward in history
// (it would be more bash-like to save over any current entry, but libedit doesn't
if (history_w (pHistory, &history_event, earlier ? H_NEXT : H_PREV) == -1)
{
// Can't move earlier than the earliest entry
- if (earlier) return CC_ERROR;
+ if (earlier)
+ return CC_ERROR;
// ... but moving to newer than the newest yields the "live" entry
new_input_lines = m_live_history_lines;
}
// If we're pulling the lines from history, split them apart
- if (m_in_history) new_input_lines = SplitLines (history_event.str);
+ if (m_in_history)
+ new_input_lines = SplitLines (history_event.str);
// Erase the current edit session and replace it with a new one
MoveCursor (CursorLocation::EditingCursor, CursorLocation::BlockStart);
// After the initial interruptible read, this is guaranteed not to block
ungetc (ch, m_input_file);
*c = fgetwc (m_input_file);
- if (*c != WEOF) return 1;
+ if (*c != WEOF)
+ return 1;
#else
*c = ch;
- if(*c != EOF) return 1;
+ if(*c != EOF)
+ return 1;
#endif
}
else
const char *
Editline::Prompt()
{
- if (m_color_prompts) m_needs_prompt_repaint = true;
+ if (m_color_prompts)
+ m_needs_prompt_repaint = true;
return m_current_prompt.c_str();
}
m_input_lines[m_current_line_index] = current_line;
// Ignore whitespace-only extra fragments when breaking a line
- if (::IsOnlySpaces (new_line_fragment)) new_line_fragment = EditLineConstString("");
+ if (::IsOnlySpaces (new_line_fragment))
+ new_line_fragment = EditLineConstString("");
// Establish the new cursor position at the start of a line when inserting a line break
m_revert_cursor_index = 0;
if (m_current_line_index == m_input_lines.size() - 1 && new_line_fragment.length() == 0)
{
bool end_of_input = true;
- if (m_is_input_complete_callback) {
+ if (m_is_input_complete_callback)
+ {
SaveEditedLine();
auto lines = GetInputAsStringList();
end_of_input = m_is_input_complete_callback (this, lines, m_is_input_complete_callback_baton);
}
// Apply smart indentation
- if (m_fix_indentation_callback) {
+ if (m_fix_indentation_callback)
+ {
StringList lines = GetInputAsStringList (m_current_line_index + 1);
#if LLDB_EDITLINE_USE_WCHAR
lines.AppendString (m_utf8conv.to_bytes (new_line_fragment));
LineInfoW * info = (LineInfoW *)el_wline (m_editline);
// Just delete the next character normally if possible
- if (info->cursor < info->lastchar) {
+ if (info->cursor < info->lastchar)
+ {
info->cursor++;
el_deletestr (m_editline, 1);
return CC_REFRESH;
LineInfoW * info = (LineInfoW *)el_wline (m_editline);
// Just delete the previous character normally when not at the start of a line
- if (info->cursor > info->buffer) {
+ if (info->cursor > info->buffer)
+ {
el_deletestr (m_editline, 1);
return CC_REFRESH;
}
// No prior line and no prior character? Let the user know
- if (m_current_line_index == 0) return CC_ERROR;
+ if (m_current_line_index == 0)
+ return CC_ERROR;
// No prior character, but prior line? Combine with the line above
SaveEditedLine();
MoveCursor (CursorLocation::EditingCursor, CursorLocation::EditingPrompt);
// Treat moving up from a blank last line as a deletion of that line
- if (m_current_line_index == m_input_lines.size() - 1 && IsOnlySpaces()) {
+ if (m_current_line_index == m_input_lines.size() - 1 && IsOnlySpaces())
+ {
m_input_lines.erase (m_input_lines.begin() + m_current_line_index);
fprintf (m_output_file, ANSI_CLEAR_BELOW);
}
SaveEditedLine();
// Handle attempts to move down from the last line
- if (m_current_line_index == m_input_lines.size() - 1) {
+ if (m_current_line_index == m_input_lines.size() - 1)
+ {
// Don't add an extra line if the existing last line is blank, move through history instead
- if (IsOnlySpaces()) {
+ if (IsOnlySpaces())
+ {
return RecallHistory (false);
}
const LineInfoW * info = el_wline (m_editline);
int cursor_position = (int)((info->cursor - info->buffer) + GetPromptWidth());
int cursor_row = cursor_position / m_terminal_width;
- for (int line_count = 0; line_count < m_current_line_rows - cursor_row; line_count++) {
+ for (int line_count = 0; line_count < m_current_line_rows - cursor_row; line_count++)
+ {
fprintf (m_output_file, "\n");
}
return CC_NEWLINE;
unsigned char
Editline::FixIndentationCommand (int ch)
{
- if (!m_fix_indentation_callback) return CC_NORM;
+ if (!m_fix_indentation_callback)
+ return CC_NORM;
// Insert the character by hand prior to correction
EditLineCharType inserted[] = { (EditLineCharType)ch, 0 };
unsigned char
Editline::TabCommand (int ch)
{
- if (m_completion_callback == nullptr) return CC_ERROR;
+ if (m_completion_callback == nullptr)
+ return CC_ERROR;
const LineInfo *line_info = el_line (m_editline);
StringList completions;
completions,
m_completion_callback_baton);
- if (num_completions == 0) return CC_ERROR;
+ if (num_completions == 0)
+ return CC_ERROR;
// if (num_completions == -1)
// {
// el_insertstr (m_editline, m_completion_key);
void
Editline::ConfigureEditor (bool multiline)
{
- if (m_editline && m_multiline_enabled == multiline) return;
+ if (m_editline && m_multiline_enabled == multiline)
+ return;
m_multiline_enabled = multiline;
- if (m_editline) {
+ if (m_editline)
+ {
// Disable edit mode to stop the terminal from flushing all input
// during the call to el_end() since we expect to have multiple editline
// instances in this program.
Editline::~Editline()
{
- if (m_editline) {
+ if (m_editline)
+ {
// Disable edit mode to stop the terminal from flushing all input
// during the call to el_end() since we expect to have multiple editline
// instances in this program.
void
Editline::TerminalSizeChanged()
{
- if (m_editline != nullptr) {
+ if (m_editline != nullptr)
+ {
el_resize (m_editline);
int columns;
// Despite the man page claiming non-zero indicates success, it's actually zero
- if (el_get (m_editline, EL_GETTC, "co", &columns) == 0) {
+ if (el_get (m_editline, EL_GETTC, "co", &columns) == 0)
+ {
m_terminal_width = columns;
- if (m_current_line_rows != -1) {
+ 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 {
+ else
+ {
m_terminal_width = INT_MAX;
m_current_line_rows = 1;
}