display

Layout and Rendering TUI library
git clone git://git.dimitrijedobrota.com/display.git
Log | Files | Refs | README | LICENSE | HACKING | CONTRIBUTING | CODE_OF_CONDUCT | BUILDING

commit da954532dc2d74ba345a97b86b277ca63307d251
parent c0fa9392d151258ba51b2c2dd85bd7490a964c48
author Dimitrije Dobrota < mail@dimitrijedobrota.com >
date Tue, 20 May 2025 22:14:22 +0200

New Alec version, start using Based

Diffstat:
M .clang-format | +++++++++ ---
M .clang-tidy | ++++++++++++++++++++++++++++++ ----------------
M CMakeLists.txt | ++++ --
M CMakePresets.json | + -
M example/example.cpp | ++++++++++++ -------
M include/display/layout.hpp | +++ --
M include/display/layout_rigid.hpp | +++ --
M include/display/types.hpp | +++++++ ----
M source/display.cpp | + -
M source/window.cpp | ++ --
M vcpkg-configuration.json | + -
M vcpkg.json | +++++ -

12 files changed, 78 insertions(+), 42 deletions(-)


diff --git a/ .clang-format b/ .clang-format

@@ -2,12 +2,12 @@

Language: Cpp
# BasedOnStyle: Chromium
AccessModifierOffset: -2
AlignAfterOpenBracket: Align
AlignAfterOpenBracket: BlockIndent
AlignConsecutiveMacros: false
AlignConsecutiveAssignments: false
AlignConsecutiveBitFields: false
AlignConsecutiveDeclarations: false
AlignEscapedNewlines: DontAlign
AlignEscapedNewlines: Right
AlignOperands: DontAlign
AlignTrailingComments: false
AllowAllArgumentsOnNextLine: true

@@ -17,9 +17,10 @@ AllowShortEnumsOnASingleLine: false

AllowShortBlocksOnASingleLine: Empty
AllowShortCaseLabelsOnASingleLine: false
AllowShortFunctionsOnASingleLine: Inline
AllowShortLambdasOnASingleLine: All
AllowShortLambdasOnASingleLine: Empty
AllowShortIfStatementsOnASingleLine: Never
AllowShortLoopsOnASingleLine: false
AllowShortCompoundRequirementOnASingleLine: true
AlwaysBreakAfterDefinitionReturnType: None
AlwaysBreakAfterReturnType: None
AlwaysBreakBeforeMultilineStrings: true

@@ -50,6 +51,7 @@ BreakBeforeBraces: Custom

# BreakBeforeInheritanceComma: true
BreakInheritanceList: BeforeComma
BreakBeforeTernaryOperators: true
BreakBeforeConceptDeclarations: Always
BreakConstructorInitializersBeforeComma: true
BreakConstructorInitializers: BeforeComma
BreakAfterJavaFieldAnnotations: true

@@ -70,6 +72,7 @@ ForEachMacros:

- foreach
- Q_FOREACH
- BOOST_FOREACH
- BASED_FOREACH
IncludeBlocks: Regroup
IncludeCategories:
# Standard library headers come before anything else

@@ -90,6 +93,8 @@ IndentPPDirectives: AfterHash

IndentExternBlock: NoIndent
IndentWidth: 2
IndentWrappedFunctionNames: false
IndentRequiresClause: true
RequiresClausePosition: OwnLine
InsertTrailingCommas: Wrapped
JavaScriptQuotes: Double
JavaScriptWrapImports: true

@@ -98,6 +103,7 @@ MacroBlockBegin: ''

MacroBlockEnd: ''
MaxEmptyLinesToKeep: 1
NamespaceIndentation: None
RequiresExpressionIndentation: OuterScope
ObjCBinPackProtocolList: Never
ObjCBlockIndentWidth: 2
ObjCBreakBeforeNestedBlockParam: true

diff --git a/ .clang-tidy b/ .clang-tidy

@@ -3,23 +3,23 @@

# misc-non-private-member-variables-in-classes: the options don't do anything
# modernize-use-nodiscard: too aggressive, attribute is situationally useful
Checks: "*,\
-google-readability-todo,\
-altera-*,\
-boost-*,\
-cppcoreguidelines-avoid-magic-numbers,\
-abseil-string-find-str-contains,\
-boost*,\
-cppcoreguidelines-avoid-do-while,\
-cppcoreguidelines-pro-bounds-constant-array-index,\
-fuchsia-*,\
fuchsia-multiple-inheritance,\
-google-readability-todo,\
-llvm-header-guard,\
-llvm-include-order,\
-llvmlibc-*,\
-modernize-use-designated-initializers,\
-modernize-use-nodiscard,\
-modernize-use-trailing-return-type,\
-modernize-use-ranges,\
-misc-include-cleaner,\
-misc-non-private-member-variables-in-classes,\
-readability-magic-numbers
-misc-no-recursion,\
-modernize-use-trailing-return-type,\
-readability-suspicious-call-argument,\
-*-ranges,\
-cppcoreguidelines-missing-std-forward,\
-cppcoreguidelines-rvalue-reference-param-not-moved,\
"
WarningsAsErrors: ''
CheckOptions:

@@ -56,9 +56,9 @@ CheckOptions:

value: 'true'
# These seem to be the most common identifier styles
- key: 'readability-identifier-naming.AbstractClassCase'
value: 'CamelCase'
value: 'lower_case'
- key: 'readability-identifier-naming.ClassCase'
value: 'CamelCase'
value: 'lower_case'
- key: 'readability-identifier-naming.ClassConstantCase'
value: 'lower_case'
- key: 'readability-identifier-naming.ClassMemberCase'

@@ -80,9 +80,9 @@ CheckOptions:

- key: 'readability-identifier-naming.ConstexprVariableCase'
value: 'lower_case'
- key: 'readability-identifier-naming.EnumCase'
value: 'CamelCase'
value: 'lower_case'
- key: 'readability-identifier-naming.EnumConstantCase'
value: 'CamelCase'
value: 'lower_case'
- key: 'readability-identifier-naming.FunctionCase'
value: 'lower_case'
- key: 'readability-identifier-naming.GlobalConstantCase'

@@ -136,7 +136,7 @@ CheckOptions:

- key: 'readability-identifier-naming.PublicMethodCase'
value: 'lower_case'
- key: 'readability-identifier-naming.ScopedEnumConstantCase'
value: 'CamelCase'
value: 'lower_case'
- key: 'readability-identifier-naming.StaticConstantCase'
value: 'lower_case'
- key: 'readability-identifier-naming.StaticVariableCase'

@@ -149,6 +149,8 @@ CheckOptions:

value: 'CamelCase'
- key: 'readability-identifier-naming.TypeAliasCase'
value: 'lower_case'
- key: 'readability-identifier-naming.TypeAliasIgnoredRegexp'
value: 'N'
- key: 'readability-identifier-naming.TypedefCase'
value: 'lower_case'
- key: 'readability-identifier-naming.TypeTemplateParameterCase'

@@ -156,9 +158,21 @@ CheckOptions:

- key: 'readability-identifier-naming.UnionCase'
value: 'lower_case'
- key: 'readability-identifier-naming.ValueTemplateParameterCase'
value: 'CamelCase'
value: 'lower_case'
- key: 'readability-identifier-naming.VariableCase'
value: 'lower_case'
- key: 'readability-identifier-naming.VirtualMethodCase'
value: 'lower_case'
- key: 'readability-identifier-length.IgnoredVariableNames'
value: "^[abcdxyznm]$"
- key: 'readability-identifier-length.IgnoredParameterNames'
value: "^[abcdxyznm]$"
- key: 'google-runtime-int.UnsignedTypePrefix'
value: "u"
- key: 'google-runtime-int.SignedTypePrefix'
value: "i"
- key: 'cppcoreguidelines-missing-std-forward.ForwardFunction'
value: "::based::forward"
- key: 'cppcoreguidelines-rvalue-reference-param-not-moved.MoveFunction'
value: "::based::move"
...

diff --git a/ CMakeLists.txt b/ CMakeLists.txt

@@ -4,7 +4,7 @@ include(cmake/prelude.cmake)


project(
display
VERSION 0.2.0
VERSION 0.3.0
DESCRIPTION "TUI library"
HOMEPAGE_URL "git://git.dimitrijedobrota.com/display.git"
LANGUAGES CXX

@@ -13,7 +13,8 @@ project(

include(cmake/project-is-top-level.cmake)
include(cmake/variables.cmake)

find_package(alec 0.1.13 CONFIG REQUIRED)
find_package(alec 0.2.0 CONFIG REQUIRED)
find_package(based 0.2.0 CONFIG REQUIRED)

# ---- Declare library ----

@@ -25,6 +26,7 @@ add_library(

source/window_pivot.cpp
)
target_link_libraries(display_display PUBLIC alec::alec)
target_link_libraries(display_display PUBLIC based::based)
add_library(display::display ALIAS display_display)

include(GenerateExportHeader)

diff --git a/ CMakePresets.json b/ CMakePresets.json

@@ -112,7 +112,7 @@

"cacheVariables": {
"ENABLE_COVERAGE": "ON",
"CMAKE_BUILD_TYPE": "Coverage",
"CMAKE_CXX_FLAGS_COVERAGE": "-Og -g --coverage -fkeep-inline-functions -fkeep-static-functions",
"CMAKE_CXX_FLAGS_COVERAGE": "-O0 -g --coverage -fkeep-inline-functions -fkeep-static-functions",
"CMAKE_EXE_LINKER_FLAGS_COVERAGE": "--coverage",
"CMAKE_SHARED_LINKER_FLAGS_COVERAGE": "--coverage",
"CMAKE_MAP_IMPORTED_CONFIG_COVERAGE": "Coverage;RelWithDebInfo;Release;Debug;"

diff --git a/ example/example.cpp b/ example/example.cpp

@@ -31,7 +31,7 @@ public:

line_empty();
}

std::cout << alec::background_v<alec::Color::DEFAULT>;
std::cout << alec::background_v<alec::color::def>;
std::cout << std::flush;
}
};

@@ -63,10 +63,14 @@ public:

const auto [m, n] = get_grid();

const auto valid = [&](std::size_t xpos, std::size_t ypos)
{ return xpos >= 0 && xpos < n.value() && ypos >= 0 && ypos < m.value(); };
{
return xpos >= 0 && xpos < n.value() && ypos >= 0 && ypos < m.value();
};

const auto get = [&](std::size_t xpos, std::size_t ypos) -> std::uint8_t
{ return valid(xpos, ypos) ? layout[xpos][ypos] : 0xFF; };
{
return valid(xpos, ypos) ? layout[xpos][ypos] : 0xFF;
};

for (std::size_t i = 0; i <= n.value(); i++) {
for (std::size_t j = 0; j <= m.value(); j++) {

@@ -90,7 +94,8 @@ public:

LayoutCustom& append(Args&&... args)
{
return LayoutMulti<LayoutCustom>::template append<LayoutCustom>(
place(size()), std::forward<Args>(args)...);
place(size()), std::forward<Args>(args)...
);
}

void resize(plc_t aplc) override

@@ -212,13 +217,13 @@ int main()

display.render();
while (true) {
const auto evnt = display.get_event();
if (evnt.type() == event::Type::RESIZE) {
std::cout << alec::erase_display_v<alec::Motion::WHOLE>;
if (evnt.type() == event::type::resize) {
std::cout << alec::erase_display_v<alec::motion::whole>;
display.render();
continue;
}

if (evnt.type() == event::Type::KEY && evnt.key() == 'q') {
if (evnt.type() == event::type::key && evnt.key() == 'q') {
break;
}
}

diff --git a/ include/display/layout.hpp b/ include/display/layout.hpp

@@ -119,7 +119,7 @@ public:

{
for (auto& child : m_children) {
child->input(evnt);
if (evnt.type() == event::Type::NONE) {
if (evnt.type() == event::type::none) {
break;
}
}

@@ -154,7 +154,8 @@ protected:

M& append(plc_t aplc, Args&&... args)
{
m_children.emplace_back(
std::make_unique<M>(aplc, std::forward<Args>(args)...));
std::make_unique<M>(aplc, std::forward<Args>(args)...)
);
return get<M>(m_children.size() - 1);
}

diff --git a/ include/display/layout_rigid.hpp b/ include/display/layout_rigid.hpp

@@ -22,8 +22,9 @@ public:

requires(std::is_base_of_v<T, M>)
M& append(Args&&... args)
{
return LayoutMulti<T>::template append<M>(place(this->size()),
std::forward<Args>(args)...);
return LayoutMulti<T>::template append<M>(
place(this->size()), std::forward<Args>(args)...
);
}

void resize(plc_t aplc) override

diff --git a/ include/display/types.hpp b/ include/display/types.hpp

@@ -5,6 +5,7 @@

#include <utility>

#include <alec/alec.hpp>
#include <alec/terminal.hpp>

namespace display
{

@@ -126,10 +127,12 @@ struct pad_t

{
}

pad_t(int leftpos, // NOLINT
int toppos,
int rightpos,
int bottompos)
pad_t(
int leftpos, // NOLINT
int toppos,
int rightpos,
int bottompos
)
: left(leftpos)
, right(rightpos)
, top(toppos)

diff --git a/ source/display.cpp b/ source/display.cpp

@@ -66,7 +66,7 @@ event Display::get_event() // NOLINT

{
if (is_resize_track && m_is_resized) {
Display::reset_resized();
return {event::Type::RESIZE, 0, 0};
return {event::type::resize, 0, 0};
}

return alec::get_event();

diff --git a/ source/window.cpp b/ source/window.cpp

@@ -23,8 +23,8 @@ void Window::render() const


void Window::clear() const
{
std::cout << alec::background_v<alec::Color::DEFAULT>;
std::cout << alec::foreground_v<alec::Color::DEFAULT>;
std::cout << alec::background_v<alec::color::def>;
std::cout << alec::foreground_v<alec::color::def>;

for (auto j = ypos_t(0); j < aypos() + ahgt(); j++) {
set_cursor(axpos(), j) << std::string(awth().value(), ' ');

diff --git a/ vcpkg-configuration.json b/ vcpkg-configuration.json

@@ -9,7 +9,7 @@

"kind": "git",
"repository": "git://git.dimitrijedobrota.com/vcpkg-registry.git",
"baseline": "93159a6024f170bb5fedd97daad8b7dd8dbc99ab",
"packages": [ "alec", "stamen" ]
"packages": [ "alec", "based", "stamen" ]
}
]
}

diff --git a/ vcpkg.json b/ vcpkg.json

@@ -4,7 +4,11 @@

"dependencies": [
{
"name": "alec",
"version>=": "0.1.17"
"version>=": "0.2.0"
},
{
"name": "based",
"version>=": "0.2.0"
}
],
"default-features": [],