From 39cefab6117054119d034ff0b7c5238cd8406dca Mon Sep 17 00:00:00 2001 From: cspark Date: Thu, 20 Nov 2025 23:06:21 +0000 Subject: [PATCH] Init cursen --- CMakeLists.txt | 13 ++++++-- README.org | 3 +- default.nix | 7 +++-- main.cpp | 80 ++++++++++++++++++++++++++++++++++++++++++++++++-- run.sh | 2 +- 5 files changed, 95 insertions(+), 10 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index c922b4a..1cdc742 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,6 +1,6 @@ cmake_minimum_required(VERSION 3.23) -project(template) +project(cursen) set(CMAKE_CXX_STANDARD 23) set(CMAKE_EXPORT_COMPILE_COMMANDS ON) @@ -8,9 +8,16 @@ set(CMAKE_EXPORT_COMPILE_COMMANDS ON) #string(REPLACE ":" ";" INCLUDE_LIST $ENV{CMAKE_STDLIB}) #include_directories($ENV{CMAKE_STDLIB}) -add_executable(template) +find_package(PkgConfig REQUIRED) -target_sources(template +pkg_check_modules(notcurses REQUIRED IMPORTED_TARGET notcurses) +pkg_check_modules(notcurses++ REQUIRED IMPORTED_TARGET notcurses++) + +add_executable(cursen) + +target_link_libraries(cursen PRIVATE PkgConfig::notcurses PkgConfig::notcurses++) + +target_sources(cursen PRIVATE main.cpp ) diff --git a/README.org b/README.org index bf84313..62edce0 100644 --- a/README.org +++ b/README.org @@ -1,2 +1 @@ -* Nix C++ Dev Template -Basic C++ CMake template with Nix +* Cursen diff --git a/default.nix b/default.nix index e722ad8..5539087 100644 --- a/default.nix +++ b/default.nix @@ -1,14 +1,17 @@ with (import {}); clangStdenv.mkDerivation { - name = "template"; + name = "cursen"; nativeBuildInputs = with pkgs; [ cmake + pkg-config + + notcurses.dev clang-tools clang ]; # Workaround as Clangd cannot see std header files, so include set of files manually just for Clangd - CXXFLAGS = "-isystem${pkgs.gcc.cc}/include/c++/14.3.0 -isystem${pkgs.gcc.cc}/include/c++/14.3.0/x86_64-unknown-linux-gnu -isystem${pkgs.glibc.dev}/include"; + CXXFLAGS = "-isystem${pkgs.gcc.cc}/include/c++/14.3.0 -isystem${pkgs.gcc.cc}/include/c++/14.3.0/x86_64-unknown-linux-gnu -isystem${pkgs.glibc.dev}/include -I${notcurses.dev}"; } diff --git a/main.cpp b/main.cpp index 8ec9f09..98a923f 100644 --- a/main.cpp +++ b/main.cpp @@ -1,6 +1,82 @@ #include +#include -int main() { - std::cout << "Hello, world!" << std::endl; +using namespace ncpp; + +typedef union Grapheme { + uint8_t utf8[4]; + uint32_t to_uint32 = 0; +} Grapheme; + +inline uint32_t utf32_to_egc(const uint32_t character) { + Grapheme result; + + if (!notcurses_ucs32_to_utf8(&character, 1, result.utf8, 4)) { + std::cerr << "Couldn't convert ucs32 " + std::to_string(character) + "to utf8!" << std::endl; + return EXIT_FAILURE; + }; + + return result.to_uint32; } +int run () +{ + NotCurses nc; + Plane* nc_plane = nc.get_stdplane(); + + Cell corner_ul = Cell(utf32_to_egc(L'┌')); + Cell corner_ur = Cell(utf32_to_egc(L'┐')); + Cell corner_bl = Cell(utf32_to_egc(L'└')); + Cell corner_br = Cell(utf32_to_egc(L'┘')); + Cell horizontal_line = Cell(utf32_to_egc(L'─')); + Cell vertical_line = Cell(utf32_to_egc(L'│')); + nc_plane->perimeter( + corner_ul, + corner_ur, + corner_bl, + corner_br, + horizontal_line, + vertical_line, + 0 + ); + + nc_plane->putstr(0, 1, "channel"); + + nc_plane->putstr(1, 1, "─"); + + /*nc_plane->cursor_move(0, 0); + Cell start; nc_plane->get_at(0, 0, start); + //nc_plane->get_at(0, 0, &end); + nc_plane->vline( + start, + 10 + );*/ + + while (true) { + + nc.render(); + sleep(1); + } + + return 0; +} + +int main () +{ + if (!setlocale (LC_ALL, "")){ + std::cerr << "Couldn't set locale based on user preferences" << std::endl; + return EXIT_FAILURE; + } + + try { + return run (); + } catch (ncpp::init_error &e) { + std::cerr << "Initialization error: " << e.what () << std::endl; + } catch (ncpp::invalid_state_error &e) { + std::cerr << "Invalid state error: " << e.what () << std::endl; + } catch (ncpp::invalid_argument &e) { + std::cerr << "Invalid argument error: " << e.what () << std::endl; + } + + return 1; +} diff --git a/run.sh b/run.sh index 2b9c3be..a47695d 100755 --- a/run.sh +++ b/run.sh @@ -4,4 +4,4 @@ cmake -B build --fresh cmake --build build -./build/discern +./build/cursen