diff --git a/CHANGELOG.md b/CHANGELOG.md index 9a16c94a0..3862f5937 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -11,6 +11,10 @@ API surface). ### Changed +- **morph requires core-cpp 0.21** (was 0.7). The package bound is minor-exact + while core-cpp is 0.x, so an installed core-cpp must be 0.21. morph builds + core-cpp without its logind power monitor (`CORE_CPP_WITH_SYSTEMD=OFF`), so + the bump adds no libsystemd or pkg-config requirement. - **A `gap` or `padding` is a spacing step.** It names a step from 0 to 5, which the mount clamps and each frontend maps: the theme's `space.0` … `space.5` (0, 4, 8, 12, 16, 24 px by default) on Qt Quick, and rows and diff --git a/CMakeLists.txt b/CMakeLists.txt index 96bad9e34..42e48515c 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -317,7 +317,9 @@ endif() # its event loop and timers, base64 and the wakeup primitive from it. Only the # modules morph links are built (EXCLUDE_FROM_ALL, unless morph installs; see # below), none of core-cpp's own tests, examples or TLS, and its TUI only with -# MORPH_BUILD_TUI (without image decoding). With the TUI off core-cpp needs no +# MORPH_BUILD_TUI (without image decoding). Its logind sleep/wake notification +# (CORE_CPP_WITH_SYSTEMD) is off: morph does not watch the power state, and on +# Linux it would add libsystemd and pkg-config to the build. With the TUI off core-cpp needs no # dependency but the thread library and nothing is fetched on its behalf; with # it on, core::tui needs libunicode, which the block above provides. Under # Emscripten it builds its single-threaded WebAssembly subset, which is what @@ -348,7 +350,7 @@ endif() # is off while morph installs: CMake leaves an excluded subdirectory's install # rules out of the parent's install, so `cmake --install` would install # morph's package without the core-cpp package it depends on. -set(MORPH_CORE_CPP_VERSION 0.7) +set(MORPH_CORE_CPP_VERSION 0.21) option(MORPH_INSTALL "Generate morph's install and export rules" ${PROJECT_IS_TOP_LEVEL}) if(NOT DEFINED AF_SANITIZER) find_package(core-cpp ${MORPH_CORE_CPP_VERSION} CONFIG QUIET) @@ -367,13 +369,14 @@ if(NOT core-cpp_FOUND) CPMAddPackage( NAME core-cpp GITHUB_REPOSITORY contour-terminal/core-cpp - GIT_TAG v0.7.0 - VERSION 0.7.0 + GIT_TAG v0.21.0 + VERSION 0.21.0 SYSTEM YES EXCLUDE_FROM_ALL ${_morph_core_cpp_exclude_from_all} OPTIONS "CORE_CPP_TESTING OFF" "CORE_CPP_BUILD_EXAMPLES OFF" "CORE_CPP_WITH_TUI ${MORPH_BUILD_TUI}" "CORE_CPP_WITH_IMAGES OFF" - "CORE_CPP_WITH_TLS OFF" "CORE_CPP_FETCH_DEPS OFF" "CORE_CPP_INSTALL ${MORPH_INSTALL}") + "CORE_CPP_WITH_TLS OFF" "CORE_CPP_WITH_SYSTEMD OFF" "CORE_CPP_FETCH_DEPS OFF" + "CORE_CPP_INSTALL ${MORPH_INSTALL}") unset(_morph_core_cpp_exclude_from_all) endif() diff --git a/cmake/CPM.cmake b/cmake/CPM.cmake index 3bcc2ea7c..86aee418a 100644 --- a/cmake/CPM.cmake +++ b/cmake/CPM.cmake @@ -22,6 +22,8 @@ set(_coreCppCpmBound "") if(DEFINED PACE_FETCH_SILENCE_SECONDS) set(_coreCppCpmBound INACTIVITY_TIMEOUT "${PACE_FETCH_SILENCE_SECONDS}") +elseif(DEFINED FASTCACHED_FETCH_SILENCE_SECONDS) + set(_coreCppCpmBound INACTIVITY_TIMEOUT "${FASTCACHED_FETCH_SILENCE_SECONDS}") endif() set(CPM_DOWNLOAD_VERSION 0.40.8) diff --git a/docs/BUILDING.md b/docs/BUILDING.md index e11bb93e2..c70ad5e3d 100644 --- a/docs/BUILDING.md +++ b/docs/BUILDING.md @@ -9,7 +9,7 @@ - **[Glaze](https://github.com/stephenberry/glaze) 7.4** for JSON reflection, found with `find_package` (for example from the `vcpkg.json` manifest) or fetched through CPM. -- **[core-cpp](https://github.com/contour-terminal/core-cpp) 0.7**, fetched +- **[core-cpp](https://github.com/contour-terminal/core-cpp) 0.21**, fetched through CPM. morph's timers run on its event loop, coroutines build on its `Task`, and `morph::net` takes its base64 and wakeup primitive from it. `morph::morph` is a static library (templates and the macro-sensitive core diff --git a/src/tui/frontend.cpp b/src/tui/frontend.cpp index 70e0b0f16..d36ec797e 100644 --- a/src/tui/frontend.cpp +++ b/src/tui/frontend.cpp @@ -38,7 +38,9 @@ int Frontend::run(ui::AppSource& source) { if (auto const ready = terminal->initialize(); !ready) { throw std::runtime_error{"morph::tui::Frontend: the terminal did not initialise: " + ready.error()}; } - ::core::tui::Screen screen{*terminal, ::core::tui::ScreenConfig{.alternateScreen = owned != nullptr}}; + auto const screenBuffer = + owned != nullptr ? ::core::tui::ScreenBuffer::Alternate : ::core::tui::ScreenBuffer::Primary; + ::core::tui::Screen screen{*terminal, ::core::tui::ScreenConfig{.screenBuffer = screenBuffer}}; std::optional<::core::tui::runtime::TuiRuntime> input; if (_config.input != nullptr) { input.emplace(ioLoop.loop(), *_config.input); diff --git a/src/tui/widget.cpp b/src/tui/widget.cpp index c1c24080f..cd1b643f0 100644 --- a/src/tui/widget.cpp +++ b/src/tui/widget.cpp @@ -224,7 +224,7 @@ namespace { void invert(::core::tui::Buffer& buffer, ::core::tui::Rect area) { for (int row = area.y; row < area.y + area.height; ++row) { for (int col = area.x; col < area.x + area.width; ++col) { - if (auto* const cell = buffer.tryAt(row, col)) { + if (auto* const cell = buffer.cellAt({.x = col, .y = row})) { cell->style.inverse = true; } } @@ -236,7 +236,7 @@ void invert(::core::tui::Buffer& buffer, ::core::tui::Rect area) { void colour(::core::tui::Buffer& buffer, ::core::tui::Rect area, ::core::tui::Color foreground) { for (int row = area.y; row < area.y + area.height; ++row) { for (int col = area.x; col < area.x + area.width; ++col) { - if (auto* const cell = buffer.tryAt(row, col)) { + if (auto* const cell = buffer.cellAt({.x = col, .y = row})) { cell->style.fg = foreground; } } @@ -274,8 +274,8 @@ void WidgetBase::paintClipped(::core::tui::Canvas& canvas, ::core::tui::Size lai ::core::tui::Buffer scratch{drawn.height, left + drawn.width}; for (int row = 0; row < drawn.height; ++row) { for (int col = 0; col < drawn.width; ++col) { - auto const* const from = screen.tryAt(drawn.y + row, drawn.x + col); - auto* const into = scratch.tryAt(row, left + col); + auto const* const from = screen.cellAt({.x = drawn.x + col, .y = drawn.y + row}); + auto* const into = scratch.cellAt({.x = left + col, .y = row}); if (from != nullptr && into != nullptr) { *into = *from; } @@ -290,8 +290,8 @@ void WidgetBase::paintClipped(::core::tui::Canvas& canvas, ::core::tui::Size lai for (int row = 0; row < drawn.height; ++row) { for (int col = 0; col < drawn.width; ++col) { - auto const* const from = scratch.tryAt(row, left + col); - auto* const into = screen.tryAt(drawn.y + row, drawn.x + col); + auto const* const from = scratch.cellAt({.x = left + col, .y = row}); + auto* const into = screen.cellAt({.x = drawn.x + col, .y = drawn.y + row}); if (from == nullptr || into == nullptr) { continue; } diff --git a/tests/tui/test_tui_dialog.cpp b/tests/tui/test_tui_dialog.cpp index 75fe49284..f036b299b 100644 --- a/tests/tui/test_tui_dialog.cpp +++ b/tests/tui/test_tui_dialog.cpp @@ -1110,7 +1110,7 @@ TEST_CASE("tui dialog: a description given as runs draws them on its row and rea REQUIRE(row < rows.size()); auto const column = static_cast(rows.at(row).find("0.21")); auto const& buffer = harness.screen().renderedBuffer(); - CHECK(buffer.at(static_cast(row), column).style.bold); - CHECK(buffer.at(static_cast(row), column).style.fg == harness.screen().theme().error.fg); + CHECK(buffer.cellAt({.x = column, .y = static_cast(row)})->style.bold); + CHECK(buffer.cellAt({.x = column, .y = static_cast(row)})->style.fg == harness.screen().theme().error.fg); CHECK(scene.dialog->accessibleDescription() == "Impurity B: 0.21 %"); } diff --git a/tests/tui/test_tui_display.cpp b/tests/tui/test_tui_display.cpp index 92ed7ec0c..aad74f2e5 100644 --- a/tests/tui/test_tui_display.cpp +++ b/tests/tui/test_tui_display.cpp @@ -207,8 +207,8 @@ TEST_CASE("tui banner: a banner's runs draw on its row, a strong run bold", "[tu banner->setSpans({{.text = "Refused.", .strong = true}, {.text = " 3 left"}}); CHECK(harness.draw() == Rows{"Refused. 3 left"}); auto const& buffer = harness.screen().renderedBuffer(); - CHECK(buffer.at(0, 0).style.bold); - CHECK_FALSE(buffer.at(0, 10).style.bold); + CHECK(buffer.cellAt({.x = 0, .y = 0})->style.bold); + CHECK_FALSE(buffer.cellAt({.x = 10, .y = 0})->style.bold); CHECK(banner->probeText() == "Refused. 3 left"); } @@ -221,9 +221,9 @@ TEST_CASE("tui key-value: a stacked pair takes two rows, and a toned value is bo {.label = "Containers", .value = "180 needed", .tone = ui::Tone::Err}}); CHECK(harness.draw() == Rows{"Serial", "D-9", "Containers", "180 needed"}); auto const& buffer = harness.screen().renderedBuffer(); - CHECK(buffer.at(3, 0).style.bold); - CHECK(buffer.at(3, 0).style.fg == harness.screen().theme().error.fg); - CHECK_FALSE(buffer.at(1, 0).style.bold); + CHECK(buffer.cellAt({.x = 0, .y = 3})->style.bold); + CHECK(buffer.cellAt({.x = 0, .y = 3})->style.fg == harness.screen().theme().error.fg); + CHECK_FALSE(buffer.cellAt({.x = 0, .y = 1})->style.bold); CHECK(kv->probeText() == "Serial: D-9\nContainers: 180 needed"); } @@ -309,9 +309,9 @@ TEST_CASE("tui banner: a link action is underlined inside its sentence and a cli banner->setActionStyle(ui::BannerActionStyle::Link, false); CHECK(harness.draw() == Rows{"1 field needs attention: Containers per pull."}); auto const& buffer = harness.screen().renderedBuffer(); - CHECK(buffer.at(0, 25).style.underline); - CHECK_FALSE(buffer.at(0, 5).style.underline); - CHECK_FALSE(buffer.at(0, 44).style.underline); + CHECK(buffer.cellAt({.x = 25, .y = 0})->style.underline); + CHECK_FALSE(buffer.cellAt({.x = 5, .y = 0})->style.underline); + CHECK_FALSE(buffer.cellAt({.x = 44, .y = 0})->style.underline); static_cast(harness.click({.x = 30, .y = 0})); CHECK(actions == 1); static_cast(harness.click({.x = 5, .y = 0})); diff --git a/tests/tui/test_tui_fields.cpp b/tests/tui/test_tui_fields.cpp index 8377f548b..b66344272 100644 --- a/tests/tui/test_tui_fields.cpp +++ b/tests/tui/test_tui_fields.cpp @@ -644,10 +644,10 @@ TEST_CASE("tui fields: a field the user cannot reach is drawn muted", "[tui][fie REQUIRE_FALSE(theme.textMuted.fg == theme.inputNormal.fg); outer->setEnabled(false); static_cast(harness.draw()); - CHECK(harness.screen().renderedBuffer().at(0, 0).style.fg == theme.textMuted.fg); + CHECK(harness.screen().renderedBuffer().cellAt({.x = 0, .y = 0})->style.fg == theme.textMuted.fg); outer->setEnabled(true); static_cast(harness.draw()); - CHECK(harness.screen().renderedBuffer().at(0, 0).style.fg == theme.inputNormal.fg); + CHECK(harness.screen().renderedBuffer().cellAt({.x = 0, .y = 0})->style.fg == theme.inputNormal.fg); } TEST_CASE("tui fields: Enter on an empty file picker picks nothing", "[tui][fields]") { @@ -1073,7 +1073,7 @@ TEST_CASE("tui fields: a captioned required input draws its mark after the capti CHECK(rows.at(0) == "Meaning *"); CHECK( std::ranges::none_of(rows.begin() + 1, rows.end(), [](std::string const& row) { return row.contains('*'); })); - CHECK(harness.screen().renderedBuffer().at(0, 8).style.fg == harness.screen().theme().error.fg); + CHECK(harness.screen().renderedBuffer().cellAt({.x = 8, .y = 0})->style.fg == harness.screen().theme().error.fg); // Without a caption the mark stays at the control's right edge. input->setCaption("", false); Rows const bare = harness.draw(); @@ -1110,7 +1110,7 @@ TEST_CASE( REQUIRE(rows.size() == 2); CHECK(rows.at(0).ends_with('!')); CHECK(rows.at(1) == "Out of spec"); - CHECK(harness.screen().renderedBuffer().at(1, 0).style.fg == harness.screen().theme().error.fg); + CHECK(harness.screen().renderedBuffer().cellAt({.x = 0, .y = 1})->style.fg == harness.screen().theme().error.fg); CHECK(input->accessibleDescription() == "Out of spec"); input->setErrors({"Not a number"}); CHECK(input->accessibleDescription() == "Not a number\nOut of spec"); @@ -1142,7 +1142,7 @@ TEST_CASE("tui fields: a prominent input draws its text bold", "[tui][fields]") input->setEmphasis(ui::InputEmphasis::Prominent); input->setText("S-123"); CHECK(harness.draw() == Rows{"S-123"}); - CHECK(harness.screen().renderedBuffer().at(0, 0).style.bold); + CHECK(harness.screen().renderedBuffer().cellAt({.x = 0, .y = 0})->style.bold); } // A field narrower than a text it was given draws the text's first cells and an ellipsis, not the tail the editor's diff --git a/tests/tui/test_tui_lists.cpp b/tests/tui/test_tui_lists.cpp index d5159b4b2..06f9aeca0 100644 --- a/tests/tui/test_tui_lists.cpp +++ b/tests/tui/test_tui_lists.cpp @@ -1100,7 +1100,8 @@ TEST_CASE("tui lists: a segmented select draws its options in one row and choose std::vector chosen; select->setOnSelect([&chosen](ui::Key key) { chosen.push_back(std::move(key)); }); CHECK(harness.draw() == Rows{" All 24 │ Flagged 2"}); - CHECK(harness.screen().renderedBuffer().at(0, 1).style.bg == harness.screen().theme().listItemSelected.bg); + CHECK(harness.screen().renderedBuffer().cellAt({.x = 1, .y = 0})->style.bg == + harness.screen().theme().listItemSelected.bg); harness.focus(*select); CHECK(harness.key(KeyCode::Right) == EventResult::Handled); CHECK(chosen == std::vector{ui::Key{std::int64_t{2}}}); diff --git a/tests/tui/test_tui_table.cpp b/tests/tui/test_tui_table.cpp index f397f8f5b..6ba2780cf 100644 --- a/tests/tui/test_tui_table.cpp +++ b/tests/tui/test_tui_table.cpp @@ -728,11 +728,11 @@ TEST_CASE("tui table: a toned row's cells draw in the tone's style", "[tui][tabl auto const& buffer = harness.screen().renderedBuffer(); auto const& theme = harness.screen().theme(); // Row 1 is the first data row; its first cell starts after the two-cell gutter. - CHECK(buffer.at(1, 2).style.fg == theme.error.fg); - CHECK_FALSE(buffer.at(2, 2).style.fg == theme.error.fg); + CHECK(buffer.cellAt({.x = 2, .y = 1})->style.fg == theme.error.fg); + CHECK_FALSE(buffer.cellAt({.x = 2, .y = 2})->style.fg == theme.error.fg); fruit.table->setRowTone(*fruit.rows.at(0), std::nullopt); static_cast(harness.draw()); - CHECK_FALSE(harness.screen().renderedBuffer().at(1, 2).style.fg == theme.error.fg); + CHECK_FALSE(harness.screen().renderedBuffer().cellAt({.x = 2, .y = 1})->style.fg == theme.error.fg); CHECK_THROWS_AS(fruit.table->setRowTone(*fruit.cells.at(0), ui::Tone::Ok), std::logic_error); } diff --git a/tests/tui/test_tui_widgets.cpp b/tests/tui/test_tui_widgets.cpp index 44f826d4a..af8086b25 100644 --- a/tests/tui/test_tui_widgets.cpp +++ b/tests/tui/test_tui_widgets.cpp @@ -60,8 +60,8 @@ TEST_CASE("tui widgets: a button weight of 600 or more draws its caption bold, a light->setWeight(500); static_cast(harness.draw()); auto const& buffer = harness.screen().renderedBuffer(); - CHECK(buffer.at(0, 2).style.bold); - CHECK_FALSE(buffer.at(1, 2).style.bold); + CHECK(buffer.cellAt({.x = 2, .y = 0})->style.bold); + CHECK_FALSE(buffer.cellAt({.x = 2, .y = 1})->style.bold); } // Mutation: ignore the alignment in TextImpl::paintControl (each line starts at cell 0). @@ -722,11 +722,11 @@ TEST_CASE("tui widgets: a primary button is bold, a danger one bold in the error ghost->setEmphasis(ui::ButtonEmphasis::Ghost); static_cast(harness.draw()); auto const& buffer = harness.screen().renderedBuffer(); - CHECK_FALSE(buffer.at(0, 2).style.bold); - CHECK(buffer.at(1, 2).style.bold); - CHECK(buffer.at(2, 2).style.bold); - CHECK(buffer.at(2, 2).style.fg == harness.screen().theme().error.fg); - CHECK_FALSE(buffer.at(3, 2).style.bold); + CHECK_FALSE(buffer.cellAt({.x = 2, .y = 0})->style.bold); + CHECK(buffer.cellAt({.x = 2, .y = 1})->style.bold); + CHECK(buffer.cellAt({.x = 2, .y = 2})->style.bold); + CHECK(buffer.cellAt({.x = 2, .y = 2})->style.fg == harness.screen().theme().error.fg); + CHECK_FALSE(buffer.cellAt({.x = 2, .y = 3})->style.bold); } // Mutation: map Section to Normal in roleStyle (the section is neither bold nor muted). @@ -742,9 +742,9 @@ TEST_CASE("tui widgets: a section text is bold and muted, a step below a heading static_cast(harness.draw()); auto const& buffer = harness.screen().renderedBuffer(); auto const& theme = harness.screen().theme(); - CHECK(buffer.at(0, 0).style.bold); - CHECK(buffer.at(0, 0).style.fg == theme.textMuted.fg); - CHECK(buffer.at(1, 0).style.bold); + CHECK(buffer.cellAt({.x = 0, .y = 0})->style.bold); + CHECK(buffer.cellAt({.x = 0, .y = 0})->style.fg == theme.textMuted.fg); + CHECK(buffer.cellAt({.x = 0, .y = 1})->style.bold); CHECK_FALSE(theme.textMuted.fg == theme.textBold.fg); } @@ -760,9 +760,9 @@ TEST_CASE("tui widgets: a display text is bold as a heading is, and a small text small->setRole(ui::TextRole::Small); static_cast(harness.draw()); auto const& buffer = harness.screen().renderedBuffer(); - CHECK(buffer.at(0, 0).style.bold); - CHECK_FALSE(buffer.at(0, 1).style.bold); - CHECK(buffer.at(0, 1).style.fg == harness.screen().theme().textNormal.fg); + CHECK(buffer.cellAt({.x = 0, .y = 0})->style.bold); + CHECK_FALSE(buffer.cellAt({.x = 1, .y = 0})->style.bold); + CHECK(buffer.cellAt({.x = 1, .y = 0})->style.fg == harness.screen().theme().textNormal.fg); } // Mutation: map Headline to Normal in roleStyle (the title is not bold, and differs from a heading). @@ -779,10 +779,10 @@ TEST_CASE("tui widgets: a headline text is drawn as a heading is: a cell has one normal->setText("Instrument"); static_cast(harness.draw()); auto const& buffer = harness.screen().renderedBuffer(); - CHECK(buffer.at(0, 0).style.bold); - CHECK(buffer.at(0, 0).style.fg == buffer.at(1, 0).style.fg); - CHECK(buffer.at(0, 0).style.bold == buffer.at(1, 0).style.bold); - CHECK_FALSE(buffer.at(2, 0).style.bold); + CHECK(buffer.cellAt({.x = 0, .y = 0})->style.bold); + CHECK(buffer.cellAt({.x = 0, .y = 0})->style.fg == buffer.cellAt({.x = 0, .y = 1})->style.fg); + CHECK(buffer.cellAt({.x = 0, .y = 0})->style.bold == buffer.cellAt({.x = 0, .y = 1})->style.bold); + CHECK_FALSE(buffer.cellAt({.x = 0, .y = 2})->style.bold); } // Mutation: draw an item as a push button (its line shows `[ ... ]`). @@ -811,8 +811,8 @@ TEST_CASE("tui widgets: an item button paints its label unbracketed across its l return lhs.fg == rhs.fg && lhs.bg == rhs.bg && lhs.bold == rhs.bold && lhs.inverse == rhs.inverse; }; // The selected item's style runs to the end of its line, past its label. - CHECK(same(buffer.at(2, 19).style, theme.listItemSelected)); - CHECK(same(buffer.at(1, 19).style, theme.textNormal)); + CHECK(same(buffer.cellAt({.x = 19, .y = 2})->style, theme.listItemSelected)); + CHECK(same(buffer.cellAt({.x = 19, .y = 1})->style, theme.textNormal)); CHECK_FALSE(same(theme.listItemSelected, theme.textNormal)); } @@ -836,10 +836,10 @@ TEST_CASE("tui widgets: a selected push button draws its caption in the list's s auto const same = [](::core::tui::Style const& lhs, ::core::tui::Style const& rhs) { return lhs.fg == rhs.fg && lhs.bg == rhs.bg && lhs.bold == rhs.bold && lhs.inverse == rhs.inverse; }; - CHECK(same(buffer.at(1, 2).style, theme.listItemSelected)); - CHECK(same(buffer.at(1, 3).style, theme.listItemSelected)); - CHECK_FALSE(same(buffer.at(1, 0).style, theme.listItemSelected)); - CHECK_FALSE(same(buffer.at(0, 2).style, theme.listItemSelected)); + CHECK(same(buffer.cellAt({.x = 2, .y = 1})->style, theme.listItemSelected)); + CHECK(same(buffer.cellAt({.x = 3, .y = 1})->style, theme.listItemSelected)); + CHECK_FALSE(same(buffer.cellAt({.x = 0, .y = 1})->style, theme.listItemSelected)); + CHECK_FALSE(same(buffer.cellAt({.x = 2, .y = 0})->style, theme.listItemSelected)); } TEST_CASE("tui widgets: a sidebar surface draws its subtree inverse; a card draws nothing", "[tui][widgets]") { @@ -857,9 +857,9 @@ TEST_CASE("tui widgets: a sidebar surface draws its subtree inverse; a card draw outside->setText("outside"); CHECK(harness.draw() == Rows{"inside", "card", "outside"}); auto const& buffer = harness.screen().renderedBuffer(); - CHECK(buffer.at(0, 0).style.inverse); - CHECK_FALSE(buffer.at(1, 0).style.inverse); - CHECK_FALSE(buffer.at(2, 0).style.inverse); + CHECK(buffer.cellAt({.x = 0, .y = 0})->style.inverse); + CHECK_FALSE(buffer.cellAt({.x = 0, .y = 1})->style.inverse); + CHECK_FALSE(buffer.cellAt({.x = 0, .y = 2})->style.inverse); } // Mutation: ignore `strong` in paintRuns (the strong run is not bold). @@ -870,10 +870,10 @@ TEST_CASE("tui widgets: a text's runs draw in order, a strong run bold and its n text->setSpans({{.text = "Lot "}, {.text = "L-26", .strong = true}, {.text = " ok\nnext", .mono = true}}); CHECK(harness.draw() == Rows{"Lot L-26 ok", "next"}); auto const& buffer = harness.screen().renderedBuffer(); - CHECK_FALSE(buffer.at(0, 3).style.bold); - CHECK(buffer.at(0, 4).style.bold); - CHECK(buffer.at(0, 7).style.bold); - CHECK_FALSE(buffer.at(0, 8).style.bold); + CHECK_FALSE(buffer.cellAt({.x = 3, .y = 0})->style.bold); + CHECK(buffer.cellAt({.x = 4, .y = 0})->style.bold); + CHECK(buffer.cellAt({.x = 7, .y = 0})->style.bold); + CHECK_FALSE(buffer.cellAt({.x = 8, .y = 0})->style.bold); CHECK(text->probeText() == "Lot L-26 ok\nnext"); text->setText("plain"); CHECK(harness.draw() == Rows{"plain"}); @@ -903,15 +903,15 @@ TEST_CASE("tui widgets: a toned run takes the tone's colour, and a toned text ke text->setSpans({{.text = "Past due "}, {.text = "7", .tone = ui::Tone::Err}}); CHECK(harness.draw() == Rows{"Past due 7"}); auto const& buffer = harness.screen().renderedBuffer(); - CHECK_FALSE(buffer.at(0, 0).style.fg == theme.error.fg); - CHECK(buffer.at(0, 9).style.fg == theme.error.fg); + CHECK_FALSE(buffer.cellAt({.x = 0, .y = 0})->style.fg == theme.error.fg); + CHECK(buffer.cellAt({.x = 9, .y = 0})->style.fg == theme.error.fg); text->setText("Past due 7"); text->setRole(ui::TextRole::Heading); text->setTone(ui::Tone::Err); static_cast(harness.draw()); auto const& drawn = harness.screen().renderedBuffer(); - CHECK(drawn.at(0, 0).style.fg == theme.error.fg); - CHECK(drawn.at(0, 0).style.bold); + CHECK(drawn.cellAt({.x = 0, .y = 0})->style.fg == theme.error.fg); + CHECK(drawn.cellAt({.x = 0, .y = 0})->style.bold); } // Mutation: leave the mark's cells out of the text's natural size (the mark then overwrites its last characters). @@ -939,10 +939,10 @@ TEST_CASE("tui widgets: a danger outlined button is red and not bold, a danger o danger->setEmphasis(ui::ButtonEmphasis::Danger); static_cast(harness.draw()); auto const& buffer = harness.screen().renderedBuffer(); - CHECK(buffer.at(0, 2).style.fg == harness.screen().theme().error.fg); - CHECK_FALSE(buffer.at(0, 2).style.bold); - CHECK(buffer.at(1, 2).style.fg == harness.screen().theme().error.fg); - CHECK(buffer.at(1, 2).style.bold); + CHECK(buffer.cellAt({.x = 2, .y = 0})->style.fg == harness.screen().theme().error.fg); + CHECK_FALSE(buffer.cellAt({.x = 2, .y = 0})->style.bold); + CHECK(buffer.cellAt({.x = 2, .y = 1})->style.fg == harness.screen().theme().error.fg); + CHECK(buffer.cellAt({.x = 2, .y = 1})->style.bold); } // Mutation: leave out the fill of the line's style under the content (its rows lose the selected line's colour). @@ -971,8 +971,8 @@ TEST_CASE("tui widgets: a selected list entry with content paints its line on ev for (int row = 0; row < 3; ++row) { INFO("row " << row); for (int const cell : {0, 20}) { - CHECK(buffer.at(row, cell).style.fg == selected.fg); - CHECK(buffer.at(row, cell).style.bold == selected.bold); + CHECK(buffer.cellAt({.x = cell, .y = row})->style.fg == selected.fg); + CHECK(buffer.cellAt({.x = cell, .y = row})->style.bold == selected.bold); } } static_cast(harness.click({.x = 3, .y = 2})); @@ -998,8 +998,8 @@ TEST_CASE("tui widgets: a caption text is drawn in the muted style", "[tui][widg caption->setRole(ui::TextRole::Caption); CHECK(harness.draw() == Rows{"Needs a reason"}); auto const& buffer = harness.screen().renderedBuffer(); - CHECK(buffer.at(0, 0).style.fg == harness.screen().theme().textMuted.fg); - CHECK_FALSE(buffer.at(0, 0).style.bold); + CHECK(buffer.cellAt({.x = 0, .y = 0})->style.fg == harness.screen().theme().textMuted.fg); + CHECK_FALSE(buffer.cellAt({.x = 0, .y = 0})->style.bold); } // Guard: a label is the normal text style on the terminal. It passes without the role too (an unknown role falls @@ -1012,8 +1012,8 @@ TEST_CASE("tui widgets: a label text is drawn in the normal style", "[tui][widge label->setRole(ui::TextRole::Label); CHECK(harness.draw() == Rows{"Sample type"}); auto const& buffer = harness.screen().renderedBuffer(); - CHECK(buffer.at(0, 0).style.fg == harness.screen().theme().textNormal.fg); - CHECK_FALSE(buffer.at(0, 0).style.bold); + CHECK(buffer.cellAt({.x = 0, .y = 0})->style.fg == harness.screen().theme().textNormal.fg); + CHECK_FALSE(buffer.cellAt({.x = 0, .y = 0})->style.bold); } // Mutation: map Overline to Normal in roleStyle (the label is neither bold nor muted). @@ -1025,8 +1025,8 @@ TEST_CASE("tui widgets: an overline text is bold and muted, written as it reads" overline->setRole(ui::TextRole::Overline); CHECK(harness.draw() == Rows{"Record type"}); auto const& buffer = harness.screen().renderedBuffer(); - CHECK(buffer.at(0, 0).style.bold); - CHECK(buffer.at(0, 0).style.fg == harness.screen().theme().textMuted.fg); + CHECK(buffer.cellAt({.x = 0, .y = 0})->style.bold); + CHECK(buffer.cellAt({.x = 0, .y = 0})->style.fg == harness.screen().theme().textMuted.fg); } // Mutation: draw `[ ]` for an icon-only button whose icon has no glyph (the caption ignores the accessible name). @@ -1065,9 +1065,9 @@ TEST_CASE("tui widgets: the toolbar surfaces, joined to the head's block or not, barText->setText("bar"); CHECK(harness.draw() == Rows{"toolbar", "joined", "bar"}); auto const& buffer = harness.screen().renderedBuffer(); - CHECK(buffer.at(0, 0).style.inverse); - CHECK(buffer.at(1, 0).style.inverse); - CHECK_FALSE(buffer.at(2, 0).style.inverse); + CHECK(buffer.cellAt({.x = 0, .y = 0})->style.inverse); + CHECK(buffer.cellAt({.x = 0, .y = 1})->style.inverse); + CHECK_FALSE(buffer.cellAt({.x = 0, .y = 2})->style.inverse); } namespace {