1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-23 04:47:36 +00:00

LibLine: Use more descriptive names for row/column

The names x and y caused confusion because of their typical use as
horiz/vert.
This commit is contained in:
AnotherTest 2020-06-08 00:48:40 +04:30 committed by Andreas Kling
parent 9b17bf3dcd
commit aa3e440a58
4 changed files with 40 additions and 40 deletions

View file

@ -339,8 +339,8 @@ void Editor::save_to(JsonObject& object)
object.set("current_prompt", m_new_prompt); object.set("current_prompt", m_new_prompt);
object.set("was_interrupted", m_was_interrupted); object.set("was_interrupted", m_was_interrupted);
JsonObject display_area; JsonObject display_area;
display_area.set("top_left_x", m_origin_x); display_area.set("top_left_row", m_origin_row);
display_area.set("top_left_y", m_origin_y); display_area.set("top_left_column", m_origin_column);
display_area.set("line_count", num_lines()); display_area.set("line_count", num_lines());
object.set("used_display_area", move(display_area)); object.set("used_display_area", move(display_area));
} }
@ -658,7 +658,7 @@ void Editor::handle_read_event()
m_suggestion_display->display(m_suggestion_manager); m_suggestion_display->display(m_suggestion_manager);
m_origin_x = m_suggestion_display->origin_x(); m_origin_row = m_suggestion_display->origin_row();
} }
} }
@ -940,7 +940,7 @@ void Editor::recalculate_origin()
// compensate for that. // compensate for that.
if (m_cached_prompt_length >= m_num_columns) { if (m_cached_prompt_length >= m_num_columns) {
auto added_lines = (m_cached_prompt_length + 1) / m_num_columns - 1; auto added_lines = (m_cached_prompt_length + 1) / m_num_columns - 1;
m_origin_x += added_lines; m_origin_row += added_lines;
} }
// We also need to recalculate our cursor position, // We also need to recalculate our cursor position,
@ -1016,7 +1016,7 @@ void Editor::refresh_display()
if (!has_cleaned_up) { if (!has_cleaned_up) {
cleanup(); cleanup();
} }
VT::move_absolute(m_origin_x, m_origin_y); VT::move_absolute(m_origin_row, m_origin_column);
fputs(m_new_prompt.characters(), stdout); fputs(m_new_prompt.characters(), stdout);
@ -1097,32 +1097,32 @@ void Editor::reposition_cursor()
auto line = cursor_line() - 1; auto line = cursor_line() - 1;
auto column = offset_in_line(); auto column = offset_in_line();
VT::move_absolute(line + m_origin_x, column + m_origin_y); VT::move_absolute(line + m_origin_row, column + m_origin_column);
} }
void VT::move_absolute(u32 x, u32 y) void VT::move_absolute(u32 row, u32 col)
{ {
printf("\033[%d;%dH", x, y); printf("\033[%d;%dH", row, col);
fflush(stdout); fflush(stdout);
} }
void VT::move_relative(int x, int y) void VT::move_relative(int row, int col)
{ {
char x_op = 'A', y_op = 'D'; char x_op = 'A', y_op = 'D';
if (x > 0) if (row > 0)
x_op = 'B'; x_op = 'B';
else else
x = -x; row = -row;
if (y > 0) if (col > 0)
y_op = 'C'; y_op = 'C';
else else
y = -y; col = -col;
if (x > 0) if (row > 0)
printf("\033[%d%c", x, x_op); printf("\033[%d%c", row, x_op);
if (y > 0) if (col > 0)
printf("\033[%d%c", y, y_op); printf("\033[%d%c", col, y_op);
} }
Style Editor::find_applicable_style(size_t offset) const Style Editor::find_applicable_style(size_t offset) const
@ -1416,21 +1416,21 @@ Vector<size_t, 2> Editor::vt_dsr()
} }
length += nread; length += nread;
} while (buf[length - 1] != 'R' && length < 16); } while (buf[length - 1] != 'R' && length < 16);
size_t x { 1 }, y { 1 }; size_t row { 1 }, col { 1 };
if (buf[0] == '\033' && buf[1] == '[') { if (buf[0] == '\033' && buf[1] == '[') {
auto parts = StringView(buf + 2, length - 3).split_view(';'); auto parts = StringView(buf + 2, length - 3).split_view(';');
bool ok; bool ok;
x = parts[0].to_int(ok); row = parts[0].to_int(ok);
if (!ok) { if (!ok) {
dbg() << "Terminal DSR issue; received garbage x"; dbg() << "Terminal DSR issue; received garbage row";
} }
y = parts[1].to_int(ok); col = parts[1].to_int(ok);
if (!ok) { if (!ok) {
dbg() << "Terminal DSR issue; received garbage y"; dbg() << "Terminal DSR issue; received garbage col";
} }
} }
return { x, y }; return { row, col };
} }
String Editor::line(size_t up_to_index) const String Editor::line(size_t up_to_index) const

View file

@ -264,11 +264,11 @@ private:
set_origin(position[0], position[1]); set_origin(position[0], position[1]);
} }
void set_origin(int x, int y) void set_origin(int row, int col)
{ {
m_origin_x = x; m_origin_row = row;
m_origin_y = y; m_origin_column = col;
m_suggestion_display->set_origin(x, y, {}); m_suggestion_display->set_origin(row, col, {});
} }
bool should_break_token(Vector<u32, 1024>& buffer, size_t index); bool should_break_token(Vector<u32, 1024>& buffer, size_t index);
@ -312,8 +312,8 @@ private:
bool m_cached_prompt_valid { false }; bool m_cached_prompt_valid { false };
// Exact position before our prompt in the terminal. // Exact position before our prompt in the terminal.
size_t m_origin_x { 0 }; size_t m_origin_row { 0 };
size_t m_origin_y { 0 }; size_t m_origin_column { 0 };
OwnPtr<SuggestionDisplay> m_suggestion_display; OwnPtr<SuggestionDisplay> m_suggestion_display;

View file

@ -45,18 +45,18 @@ public:
virtual void set_vt_size(size_t lines, size_t columns) = 0; virtual void set_vt_size(size_t lines, size_t columns) = 0;
size_t origin_x() const { return m_origin_x; } size_t origin_row() const { return m_origin_row; }
size_t origin_y() const { return m_origin_y; } size_t origin_col() const { return m_origin_column; }
void set_origin(int x, int y, Badge<Editor>) void set_origin(int row, int col, Badge<Editor>)
{ {
m_origin_x = x; m_origin_row = row;
m_origin_y = y; m_origin_column = col;
} }
protected: protected:
int m_origin_x { 0 }; int m_origin_row { 0 };
int m_origin_y { 0 }; int m_origin_column { 0 };
}; };
class XtermSuggestionDisplay : public SuggestionDisplay { class XtermSuggestionDisplay : public SuggestionDisplay {

View file

@ -65,7 +65,7 @@ void XtermSuggestionDisplay::display(const SuggestionManager& manager)
longest_suggestion_length = 0; longest_suggestion_length = 0;
} }
VT::move_absolute(max_line_count + m_origin_x, 1); VT::move_absolute(max_line_count + m_origin_row, 1);
if (m_pages.is_empty()) { if (m_pages.is_empty()) {
size_t num_printed = 0; size_t num_printed = 0;
@ -142,8 +142,8 @@ void XtermSuggestionDisplay::display(const SuggestionManager& manager)
m_lines_used_for_last_suggestions = lines_used; m_lines_used_for_last_suggestions = lines_used;
// If we filled the screen, move back the origin. // If we filled the screen, move back the origin.
if (m_origin_x + lines_used >= m_num_lines) { if (m_origin_row + lines_used >= m_num_lines) {
m_origin_x = m_num_lines - lines_used; m_origin_row = m_num_lines - lines_used;
} }
if (m_pages.size() > 1) { if (m_pages.size() > 1) {
@ -156,7 +156,7 @@ void XtermSuggestionDisplay::display(const SuggestionManager& manager)
return; return;
} }
VT::move_absolute(m_origin_x + lines_used, m_num_columns - string.length() - 1); VT::move_absolute(m_origin_row + lines_used, m_num_columns - string.length() - 1);
VT::apply_style({ Style::Background(Style::XtermColor::Green) }); VT::apply_style({ Style::Background(Style::XtermColor::Green) });
fputs(string.characters(), stdout); fputs(string.characters(), stdout);
VT::apply_style(Style::reset_style()); VT::apply_style(Style::reset_style());