From 00f16bc326747f6957b593bd8ab7c4f9b21630d9 Mon Sep 17 00:00:00 2001 From: Ttibsi Date: Mon, 17 Nov 2025 12:18:58 +0000 Subject: [PATCH] Resolve overflows in UI drawing for buffer list view --- src/controller.cpp | 27 +++++++++++++++++++------- tests/integration/command_mode_test.py | 20 +++++++++---------- 2 files changed, 29 insertions(+), 18 deletions(-) diff --git a/src/controller.cpp b/src/controller.cpp index 0f3746a7..a146ac15 100644 --- a/src/controller.cpp +++ b/src/controller.cpp @@ -735,7 +735,13 @@ void Controller::add_model(const std::string& filename) { return lhs.filename.size() < rhs.filename.size(); })->filename.size(); - std::string title = "\u2551 id \u2502 filename " + std::string(max_name_len - 8, ' '); + // "filename" + if (max_name_len < 8) { + max_name_len = 8; + } + max_name_len += 2; + + std::string title = "\u2551 id \u2502 filename" + std::string(uint_t(max_name_len - 8), ' '); title += " \u2502 pos \u2551"; std::size_t title_len = title.size() - 9; @@ -759,13 +765,19 @@ void Controller::add_model(const std::string& filename) { std::string line = "\u2551 " + std::to_string(idx); line += " \u2502 "; line += rawterm::bold(m.filename); + + int spacing = 0; + if (max_name_len > m.filename.size()) { + spacing = max_name_len - m.filename.size(); + } + if (m.unsaved) { line += rawterm::bold("*"); - if (m.filename.size() < max_name_len) { - line += std::string(max_name_len - m.filename.size() - 1, ' '); - } - } else { - line += std::string(max_name_len - m.filename.size() + 1, ' '); + spacing--; + } + + if (spacing > 0) { + line += std::string(spacing, ' '); } line += " \u2502 "; @@ -773,7 +785,8 @@ void Controller::add_model(const std::string& filename) { line.push_back(':'); line += std::to_string(m.current_char + 1); - std::size_t diff = title.size() - rawterm::raw_size(line) - std::string("\u2551").size(); + const std::size_t diff = + title.size() - rawterm::raw_size(line) - std::string("\u2551").size(); line += std::string(diff, ' '); line += "\u2551"; diff --git a/tests/integration/command_mode_test.py b/tests/integration/command_mode_test.py index ad07c849..f7bca142 100644 --- a/tests/integration/command_mode_test.py +++ b/tests/integration/command_mode_test.py @@ -265,18 +265,16 @@ def test_list_open_buffers(r: TmuxRunner): inverted_buf_name = "\x1B[7m[BUFFERS]\x1B[0m" assert inverted_buf_name in r.await_tab_bar_parts() - lines: list[str] = r.lines() - assert "0" in lines[4] - assert "tests/fixture/temp_file.txt" in lines[4] - assert "1:1" in lines[4] - - assert "1" in lines[5] - assert "NO NAME" in lines[5] - assert "1:1" in lines[5] + expected_lines: list[str] = [ + "║ 0 │ tests/fixture/temp_file.txt │ 1:1 ║", + "║ 1 │ NO NAME │ 1:1 ║", + "║ 2 │ tests/fixture/test_file_1.txt │ 1:1 ║", + ] - assert "2" in lines[6] - assert r.filename in lines[6] - assert "1:1" in lines[6] + lines: list[str] = r.lines() + assert expected_lines[0] in lines[4] + assert expected_lines[1] in lines[5] + assert expected_lines[2] in lines[6] assert r.await_statusbar_parts()[1] == "[RO]"