Skip to content

Commit 5de4871

Browse files
committed
feat: add standalone Reply REPL module
1 parent ed8e1c9 commit 5de4871

22 files changed

Lines changed: 6159 additions & 0 deletions

CMakeLists.txt

Lines changed: 170 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,170 @@
1+
# @file CMakeLists.txt
2+
# @author Gaspard Kirira
3+
#
4+
# Copyright 2025, Gaspard Kirira. All rights reserved.
5+
# https://github.com/vixcpp/reply
6+
# Use of this source code is governed by an MIT license
7+
# that can be found in the LICENSE file.
8+
#
9+
# ====================================================================
10+
# Vix Reply
11+
# ====================================================================
12+
13+
cmake_minimum_required(VERSION 3.20)
14+
15+
if (CMAKE_SOURCE_DIR STREQUAL CMAKE_CURRENT_SOURCE_DIR)
16+
project(vix_reply VERSION 0.1.0 LANGUAGES CXX)
17+
endif()
18+
19+
include(GNUInstallDirs)
20+
include(CheckCXXCompilerFlag)
21+
22+
set(CMAKE_CXX_STANDARD 20)
23+
set(CMAKE_CXX_STANDARD_REQUIRED ON)
24+
25+
option(VIX_REPLY_BUILD_TESTS "Build Vix Reply tests" OFF)
26+
option(VIX_REPLY_BUILD_EXAMPLES "Build Vix Reply examples" OFF)
27+
option(VIX_REPLY_ENABLE_LTO "Enable LTO in Release builds" OFF)
28+
29+
file(GLOB_RECURSE VIX_REPLY_SOURCES
30+
CONFIGURE_DEPENDS
31+
"${CMAKE_CURRENT_SOURCE_DIR}/src/*.cpp"
32+
)
33+
34+
add_library(vix_reply STATIC ${VIX_REPLY_SOURCES})
35+
add_library(vix::reply ALIAS vix_reply)
36+
37+
target_include_directories(vix_reply
38+
PUBLIC
39+
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/include>
40+
$<INSTALL_INTERFACE:${CMAKE_INSTALL_INCLUDEDIR}>
41+
)
42+
43+
target_compile_features(vix_reply PUBLIC cxx_std_20)
44+
45+
# ----------------------------------------------------
46+
# Warnings
47+
# ----------------------------------------------------
48+
function(vix_reply_add_flag_if_supported target flag)
49+
string(REGEX REPLACE "[^A-Za-z0-9]" "_" flag_var "${flag}")
50+
set(test_var "HAVE_VIX_REPLY_${flag_var}")
51+
52+
check_cxx_compiler_flag("${flag}" ${test_var})
53+
54+
if (${test_var})
55+
target_compile_options(${target} PRIVATE "${flag}")
56+
endif()
57+
endfunction()
58+
59+
if (MSVC)
60+
vix_reply_add_flag_if_supported(vix_reply /W4)
61+
vix_reply_add_flag_if_supported(vix_reply /permissive-)
62+
else()
63+
vix_reply_add_flag_if_supported(vix_reply -Wall)
64+
vix_reply_add_flag_if_supported(vix_reply -Wextra)
65+
vix_reply_add_flag_if_supported(vix_reply -Wshadow)
66+
vix_reply_add_flag_if_supported(vix_reply -Wconversion)
67+
vix_reply_add_flag_if_supported(vix_reply -Wformat=2)
68+
vix_reply_add_flag_if_supported(vix_reply -Wpedantic)
69+
endif()
70+
71+
# ----------------------------------------------------
72+
# Dependencies
73+
# ----------------------------------------------------
74+
find_package(nlohmann_json CONFIG QUIET)
75+
76+
if (TARGET nlohmann_json::nlohmann_json)
77+
target_link_libraries(vix_reply PUBLIC nlohmann_json::nlohmann_json)
78+
else()
79+
message(STATUS "[reply] nlohmann_json package not found, expecting nlohmann/json.hpp to be available in include paths")
80+
endif()
81+
82+
# ----------------------------------------------------
83+
# Version string
84+
# ----------------------------------------------------
85+
set(_VIX_REPLY_VERSION "dev")
86+
87+
if (DEFINED VIX_REPLY_VERSION AND NOT "${VIX_REPLY_VERSION}" STREQUAL "")
88+
set(_VIX_REPLY_VERSION "${VIX_REPLY_VERSION}")
89+
90+
elseif (DEFINED ENV{VIX_REPLY_VERSION} AND NOT "$ENV{VIX_REPLY_VERSION}" STREQUAL "")
91+
set(_VIX_REPLY_VERSION "$ENV{VIX_REPLY_VERSION}")
92+
93+
elseif (DEFINED PROJECT_VERSION AND NOT "${PROJECT_VERSION}" STREQUAL "")
94+
set(_VIX_REPLY_VERSION "v${PROJECT_VERSION}")
95+
96+
else()
97+
find_package(Git QUIET)
98+
99+
if (Git_FOUND)
100+
execute_process(
101+
COMMAND "${GIT_EXECUTABLE}" describe --tags --always
102+
WORKING_DIRECTORY "${CMAKE_CURRENT_LIST_DIR}"
103+
OUTPUT_VARIABLE _GIT_DESCRIBE
104+
OUTPUT_STRIP_TRAILING_WHITESPACE
105+
ERROR_QUIET
106+
)
107+
108+
if (_GIT_DESCRIBE)
109+
set(_VIX_REPLY_VERSION "${_GIT_DESCRIBE}")
110+
endif()
111+
endif()
112+
endif()
113+
114+
message(STATUS "Vix Reply version: ${_VIX_REPLY_VERSION}")
115+
116+
target_compile_definitions(vix_reply
117+
PRIVATE
118+
VIX_REPLY_VERSION="${_VIX_REPLY_VERSION}"
119+
)
120+
121+
# ----------------------------------------------------
122+
# LTO
123+
# ----------------------------------------------------
124+
if (VIX_REPLY_ENABLE_LTO AND CMAKE_BUILD_TYPE STREQUAL "Release")
125+
include(CheckIPOSupported)
126+
check_ipo_supported(RESULT _ipo_ok OUTPUT _ipo_msg)
127+
128+
if (_ipo_ok)
129+
set_property(TARGET vix_reply PROPERTY INTERPROCEDURAL_OPTIMIZATION TRUE)
130+
else()
131+
message(WARNING "[reply] IPO/LTO not supported: ${_ipo_msg}")
132+
endif()
133+
endif()
134+
135+
# ----------------------------------------------------
136+
# Tests
137+
# ----------------------------------------------------
138+
if (VIX_REPLY_BUILD_TESTS AND EXISTS "${CMAKE_CURRENT_SOURCE_DIR}/tests/CMakeLists.txt")
139+
enable_testing()
140+
add_subdirectory(tests)
141+
endif()
142+
143+
# ----------------------------------------------------
144+
# Examples
145+
# ----------------------------------------------------
146+
if (VIX_REPLY_BUILD_EXAMPLES AND EXISTS "${CMAKE_CURRENT_SOURCE_DIR}/examples/CMakeLists.txt")
147+
add_subdirectory(examples)
148+
endif()
149+
150+
# ----------------------------------------------------
151+
# Install
152+
# ----------------------------------------------------
153+
install(TARGETS vix_reply
154+
EXPORT vix_reply_targets
155+
ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR}
156+
LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
157+
RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}
158+
)
159+
160+
install(DIRECTORY include/
161+
DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}
162+
)
163+
164+
install(EXPORT vix_reply_targets
165+
FILE vix_replyTargets.cmake
166+
NAMESPACE vix::
167+
DESTINATION ${CMAKE_INSTALL_LIBDIR}/cmake/vix_reply
168+
)
169+
170+
message(STATUS "Vix Reply configured.")

include/vix/reply/api/ReplApi.hpp

Lines changed: 97 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,97 @@
1+
/**
2+
* @file ReplApi.hpp
3+
* @brief Basic public API helpers exposed inside the Vix Reply REPL.
4+
*
5+
* @author Gaspard Kirira
6+
*
7+
* Copyright 2025, Gaspard Kirira. All rights reserved.
8+
* https://github.com/vixcpp/reply
9+
*
10+
* Use of this source code is governed by an MIT license
11+
* that can be found in the LICENSE file.
12+
*
13+
* Vix Reply
14+
*/
15+
16+
#ifndef VIX_REPLY_API_REPL_API_HPP
17+
#define VIX_REPLY_API_REPL_API_HPP
18+
19+
#include <filesystem>
20+
#include <optional>
21+
#include <string>
22+
#include <string_view>
23+
24+
namespace vix::reply::api
25+
{
26+
/**
27+
* @brief Prints text to stdout without adding a newline.
28+
*
29+
* @param s Text to print.
30+
*/
31+
void print(std::string_view s);
32+
33+
/**
34+
* @brief Prints text to stdout and appends a newline.
35+
*
36+
* @param s Text to print before the newline.
37+
*/
38+
void println(std::string_view s = {});
39+
40+
/**
41+
* @brief Prints text to stderr without adding a newline.
42+
*
43+
* @param s Text to print.
44+
*/
45+
void eprint(std::string_view s);
46+
47+
/**
48+
* @brief Prints text to stderr and appends a newline.
49+
*
50+
* @param s Text to print before the newline.
51+
*/
52+
void eprintln(std::string_view s = {});
53+
54+
/**
55+
* @brief Prints an integer to stdout without adding a newline.
56+
*
57+
* @param value Integer value to print.
58+
*/
59+
void print_int(long long value);
60+
61+
/**
62+
* @brief Prints an integer to stdout and appends a newline.
63+
*
64+
* @param value Integer value to print.
65+
*/
66+
void println_int(long long value);
67+
68+
/**
69+
* @brief Reads one line from stdin.
70+
*
71+
* @return The read line, or std::nullopt on EOF.
72+
*/
73+
std::optional<std::string> readln();
74+
75+
/**
76+
* @brief Clears the terminal screen.
77+
*/
78+
void clear();
79+
80+
/**
81+
* @brief Returns the current working directory.
82+
*
83+
* @return Current working directory path.
84+
*/
85+
std::filesystem::path pwd();
86+
87+
/**
88+
* @brief Changes the current working directory.
89+
*
90+
* @param path Target directory.
91+
* @param err Optional output string receiving the error message on failure.
92+
* @return True on success, false on failure.
93+
*/
94+
bool cd(const std::filesystem::path &path, std::string *err = nullptr);
95+
}
96+
97+
#endif

0 commit comments

Comments
 (0)