From 676586f2034ff112b309dccc430893d73e919191 Mon Sep 17 00:00:00 2001 From: Felix Morgner Date: Tue, 22 Sep 2026 18:06:51 +0200 Subject: apps: extract applications --- CMakeLists.txt | 15 ++++++--------- apps/echo.cpp | 36 ++++++++++++++++++++++++++++++++++++ ttwhy/main.cpp | 36 ------------------------------------ 3 files changed, 42 insertions(+), 45 deletions(-) create mode 100644 apps/echo.cpp delete mode 100644 ttwhy/main.cpp diff --git a/CMakeLists.txt b/CMakeLists.txt index 138a84a..337086f 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -81,9 +81,6 @@ target_sources("ttwhy-core" PUBLIC "ttwhy/scanners/terminal_scanner.cppm" ) -target_include_directories("ttwhy-core" PUBLIC - "${CMAKE_SOURCE_DIR}" -) target_compile_features("ttwhy-core" PUBLIC "cxx_std_23" @@ -101,16 +98,16 @@ target_compile_options("ttwhy-core" PUBLIC "$<$:-pedantic-errors>" ) -### Main Executable +### Applications -add_executable("ttwhy") -add_executable("ttwhy::app" ALIAS "ttwhy") +add_executable("ttwhy-echo") +add_executable("ttwhy::echo" ALIAS "ttwhy-echo") -target_sources("ttwhy" PRIVATE - "ttwhy/main.cpp" +target_sources("ttwhy-echo" PRIVATE + "apps/echo.cpp" ) -target_link_libraries("ttwhy" PRIVATE +target_link_libraries("ttwhy-echo" PRIVATE "ttwhy::lib" ) diff --git a/apps/echo.cpp b/apps/echo.cpp new file mode 100644 index 0000000..ab635a7 --- /dev/null +++ b/apps/echo.cpp @@ -0,0 +1,36 @@ +#include +#include + +#include + +import ttwhy.io; +import ttwhy.routers; + +auto app(int in, int out, int error) -> asio::awaitable +{ + using namespace asio::experimental::awaitable_operators; + + auto terminal_attributes = ttwhy::io::scoped_attributes{fileno(stdin)} // + .canonical_mode(false) + .echo(false); + + auto executor = co_await asio::this_coro::executor; + + auto input_stream = asio::posix::stream_descriptor{executor, in}; + auto output_stream = asio::posix::stream_descriptor{executor, out}; + auto error_stream = asio::posix::stream_descriptor{executor, error}; + + auto router = ttwhy::routers::echo{output_stream}; + + co_await (ttwhy::io::handle_signals(error_stream, terminal_attributes) || + ttwhy::io::read_events(input_stream, router)); +} + +auto main() -> int +{ + auto context = asio::io_context{}; + + asio::co_spawn(context, app(::fileno(::stdin), ::fileno(::stdout), ::fileno(::stderr)), asio::detached); + + context.run(); +} diff --git a/ttwhy/main.cpp b/ttwhy/main.cpp deleted file mode 100644 index ab635a7..0000000 --- a/ttwhy/main.cpp +++ /dev/null @@ -1,36 +0,0 @@ -#include -#include - -#include - -import ttwhy.io; -import ttwhy.routers; - -auto app(int in, int out, int error) -> asio::awaitable -{ - using namespace asio::experimental::awaitable_operators; - - auto terminal_attributes = ttwhy::io::scoped_attributes{fileno(stdin)} // - .canonical_mode(false) - .echo(false); - - auto executor = co_await asio::this_coro::executor; - - auto input_stream = asio::posix::stream_descriptor{executor, in}; - auto output_stream = asio::posix::stream_descriptor{executor, out}; - auto error_stream = asio::posix::stream_descriptor{executor, error}; - - auto router = ttwhy::routers::echo{output_stream}; - - co_await (ttwhy::io::handle_signals(error_stream, terminal_attributes) || - ttwhy::io::read_events(input_stream, router)); -} - -auto main() -> int -{ - auto context = asio::io_context{}; - - asio::co_spawn(context, app(::fileno(::stdin), ::fileno(::stdout), ::fileno(::stderr)), asio::detached); - - context.run(); -} -- cgit v1.2.3