Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
13 changes: 8 additions & 5 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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)
Expand All @@ -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()

Expand Down
2 changes: 2 additions & 0 deletions cmake/CPM.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
2 changes: 1 addition & 1 deletion docs/BUILDING.md
Original file line number Diff line number Diff line change
Expand Up @@ -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<T>`, and `morph::net` takes its base64 and wakeup primitive from it.
`morph::morph` is a static library (templates and the macro-sensitive core
Expand Down
4 changes: 3 additions & 1 deletion src/tui/frontend.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
12 changes: 6 additions & 6 deletions src/tui/widget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
}
Expand All @@ -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;
}
}
Expand Down Expand Up @@ -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;
}
Expand All @@ -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;
}
Expand Down
4 changes: 2 additions & 2 deletions tests/tui/test_tui_dialog.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<int>(rows.at(row).find("0.21"));
auto const& buffer = harness.screen().renderedBuffer();
CHECK(buffer.at(static_cast<int>(row), column).style.bold);
CHECK(buffer.at(static_cast<int>(row), column).style.fg == harness.screen().theme().error.fg);
CHECK(buffer.cellAt({.x = column, .y = static_cast<int>(row)})->style.bold);
CHECK(buffer.cellAt({.x = column, .y = static_cast<int>(row)})->style.fg == harness.screen().theme().error.fg);
CHECK(scene.dialog->accessibleDescription() == "Impurity B: 0.21 %");
}
16 changes: 8 additions & 8 deletions tests/tui/test_tui_display.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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");
}

Expand All @@ -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");
}

Expand Down Expand Up @@ -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<void>(harness.click({.x = 30, .y = 0}));
CHECK(actions == 1);
static_cast<void>(harness.click({.x = 5, .y = 0}));
Expand Down
10 changes: 5 additions & 5 deletions tests/tui/test_tui_fields.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<void>(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<void>(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]") {
Expand Down Expand Up @@ -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();
Expand Down Expand Up @@ -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");
Expand Down Expand Up @@ -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
Expand Down
3 changes: 2 additions & 1 deletion tests/tui/test_tui_lists.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1100,7 +1100,8 @@ TEST_CASE("tui lists: a segmented select draws its options in one row and choose
std::vector<ui::Key> 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>{ui::Key{std::int64_t{2}}});
Expand Down
6 changes: 3 additions & 3 deletions tests/tui/test_tui_table.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<void>(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);
}

Expand Down
Loading
Loading