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 a218da041827f634ceb1315a75c8547320388d0c
parent 1d05e0bbf99a8b3a2ba1b71945b3ad3683df06d0
author Dimitrije Dobrota < mail@dimitrijedobrota.com >
date Fri, 31 Jan 2025 19:47:31 +0100

Initialize alec

Diffstat:
M .clang-tidy | +++
M CMakeLists.txt | +++++++++++++ -
M example/example.cpp | +++++++++++++ --
M include/display/display.hpp | ++++ ---------------------------------------------------------------
A include/display/pane.hpp | +++++++++++++++
A include/display/widget.hpp | ++++++++++++++++
M source/display.cpp | ++++++++++++ -----

7 files changed, 76 insertions(+), 71 deletions(-)


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

@@ -5,12 +5,15 @@

Checks: "*,\
-google-readability-todo,\
-altera-*,\
-abseil-string-find-str-contains,\
-fuchsia-*,\
fuchsia-multiple-inheritance,\
-llvm-header-guard,\
-llvm-include-order,\
-llvmlibc-*,\
-modernize-use-nodiscard,\
-modernize-use-trailing-return-type,\
-misc-include-cleaner,\
-misc-non-private-member-variables-in-classes"
WarningsAsErrors: ''
CheckOptions:

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

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


project(
display
VERSION 0.1.0
VERSION 0.1.1
DESCRIPTION "TUI library"
HOMEPAGE_URL "https://example.com/"
LANGUAGES CXX

@@ -13,12 +13,15 @@ project(

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

find_package(alec 0.1 CONFIG REQUIRED)

# ---- Declare library ----

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

include(GenerateExportHeader)

@@ -63,6 +66,15 @@ if(NOT CMAKE_SKIP_INSTALL_RULES)

include(cmake/install-rules.cmake)
endif()

# ---- Examples ----

if(PROJECT_IS_TOP_LEVEL)
option(BUILD_EXAMPLES "Build examples tree." "${display_DEVELOPER_MODE}")
if(BUILD_EXAMPLES)
add_subdirectory(example)
endif()
endif()

# ---- Developer mode ----

if(NOT display_DEVELOPER_MODE)

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

@@ -1,3 +1,14 @@

int main(void) {
return 0;
#include <cstdio>

#include "display/display.hpp"

int main()
{
display::start();

(void)std::getchar();

display::stop();

return 0;
}

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

@@ -1,70 +1,11 @@

#pragma once

#include <string>

#include "display/display_export.hpp"

/**
* A note about the MSVC warning C4251:
* This warning should be suppressed for private data members of the project's
* exported classes, because there are too many ways to work around it and all
* involve some kind of trade-off (increased code complexity requiring more
* developer time, writing boilerplate code, longer compile times), but those
* solutions are very situational and solve things in slightly different ways,
* depending on the requirements of the project.
* That is to say, there is no general solution.
*
* What can be done instead is understand where issues could arise where this
* warning is spotting a legitimate bug. I will give the general description of
* this warning's cause and break it down to make it trivial to understand.
*
* C4251 is emitted when an exported class has a non-static data member of a
* non-exported class type.
*
* The exported class in our case is the class below (exported_class), which
* has a non-static data member (m_name) of a non-exported class type
* (std::string).
*
* The rationale here is that the user of the exported class could attempt to
* access (directly, or via an inline member function) a static data member or
* a non-inline member function of the data member, resulting in a linker
* error.
* Inline member function above means member functions that are defined (not
* declared) in the class definition.
*
* Since this exported class never makes these non-exported types available to
* the user, we can safely ignore this warning. It's fine if there are
* non-exported class types as private member variables, because they are only
* accessed by the members of the exported class itself.
*
* The name() method below returns a pointer to the stored null-terminated
* string as a fundamental type (char const), so this is safe to use anywhere.
* The only downside is that you can have dangling pointers if the pointer
* outlives the class instance which stored the string.
*
* Shared libraries are not easy, they need some discipline to get right, but
* they also solve some other problems that make them worth the time invested.
*/

/**
* @brief Reports the name of the library
*
* Please see the note above for considerations when creating shared libraries.
*/
class DISPLAY_EXPORT exported_class
namespace display
{
public:
/**
* @brief Initializes the name field to the name of the project
*/
exported_class();

/**
* @brief Returns a non-owning pointer to the string stored in this class
*/
auto name() const -> char const*;
void start();
void stop();

private:
DISPLAY_SUPPRESS_C4251
std::string m_name;
};
} // namespace display

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

@@ -0,0 +1,15 @@

#pragma once

#include "display/display_export.hpp"

namespace display
{

class DISPLAY_EXPORT pane
{
public:

private:
};

} // namespace display

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

@@ -0,0 +1,16 @@

#pragma once

#include "display/display_export.hpp"

namespace display
{

class DISPLAY_EXPORT widget
{
public:

private:
};

} // namespace display

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

@@ -1,13 +1,20 @@

#include <string>
#include <iostream>

#include "display/display.hpp"

exported_class::exported_class()
: m_name {"display"}
#include <alec/alec.hpp>

namespace display
{

void start()
{
std::cout << alec::abuf_enable_v << alec::cursor_hide_v;
}

auto exported_class::name() const -> char const*
void stop()
{
return m_name.c_str();
std::cout << alec::abuf_disable_v;
}

} // namespace display