Skip to content

Commit

Permalink
refactor: remove termcolor to use fmt color support
Browse files Browse the repository at this point in the history
  • Loading branch information
SuperFola committed Aug 31, 2024
1 parent e47a4db commit cd81653
Show file tree
Hide file tree
Showing 21 changed files with 252 additions and 246 deletions.
3 changes: 0 additions & 3 deletions .gitmodules
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,6 @@
[submodule "lib/picosha2"]
path = lib/picosha2
url = https://github.com/okdshin/PicoSHA2.git
[submodule "lib/termcolor"]
path = lib/termcolor
url = https://github.com/ikalnytskyi/termcolor.git
[submodule "lib/replxx"]
path = lib/replxx
url = https://github.com/AmokHuginnsson/replxx.git
Expand Down
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,7 @@
- removed `VM::getUserPointer` and `VM::setUserPointer`
- removed `ARK_PROFILER_COUNT` define
- removed useless `\0` escape in strings
- removed `termcolor` dependency to rely on `fmt` for coloring outputs

## [3.5.0] - 2023-02-19
### Added
Expand Down
9 changes: 3 additions & 6 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -102,9 +102,6 @@ endif ()

# Link libraries

add_subdirectory("${ark_SOURCE_DIR}/lib/termcolor" EXCLUDE_FROM_ALL)
target_link_libraries(ArkReactor PUBLIC termcolor)

target_include_directories(ArkReactor
SYSTEM PUBLIC
"${ark_SOURCE_DIR}/lib/picosha2/"
Expand Down Expand Up @@ -179,7 +176,7 @@ if (ARK_TESTS)

add_subdirectory(${ark_SOURCE_DIR}/lib/ut)
target_include_directories(unittests PUBLIC ${ark_SOURCE_DIR}/include)
target_link_libraries(unittests PUBLIC ArkReactor termcolor ut)
target_link_libraries(unittests PUBLIC ArkReactor ut)

add_compile_definitions(BOOST_UT_DISABLE_MODULE)
target_compile_features(unittests PRIVATE cxx_std_20)
Expand All @@ -192,7 +189,7 @@ if (ARK_BENCHMARKS)
CPMAddPackage("gh:google/[email protected]")

add_executable(bench tests/benchmarks/main.cpp)
target_link_libraries(bench PUBLIC ArkReactor termcolor benchmark::benchmark)
target_link_libraries(bench PUBLIC ArkReactor benchmark::benchmark)
target_compile_features(bench PRIVATE cxx_std_20)
target_compile_definitions(bench PRIVATE ARK_TESTS_ROOT="${CMAKE_CURRENT_SOURCE_DIR}/")
enable_lto(bench)
Expand All @@ -209,7 +206,7 @@ if (ARK_BUILD_EXE)
add_subdirectory("${ark_SOURCE_DIR}/lib/clipp" EXCLUDE_FROM_ALL)

target_include_directories(arkscript SYSTEM PUBLIC "${ark_SOURCE_DIR}/lib/clipp/include")
target_link_libraries(arkscript PUBLIC ArkReactor replxx clipp termcolor)
target_link_libraries(arkscript PUBLIC ArkReactor replxx clipp)
target_compile_features(arkscript PRIVATE cxx_std_20)

enable_lto(arkscript)
Expand Down
7 changes: 4 additions & 3 deletions include/Ark/Exceptions.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -111,8 +111,9 @@ namespace Ark
* @param target_line line where the error is
* @param col_start where the error starts on the given line
* @param sym_size bad expression that triggered the error
* @param colorize generate colors or not
*/
ARK_API void makeContext(std::ostream& os, const std::string& code, std::size_t target_line, std::size_t col_start, std::size_t sym_size);
ARK_API void makeContext(std::ostream& os, const std::string& code, std::size_t target_line, std::size_t col_start, std::size_t sym_size, bool colorize);

/**
* @brief Helper used by the compiler to generate a colorized context from a node
Expand All @@ -127,10 +128,10 @@ namespace Ark
* @brief Generate a diagnostic from an error and print it to the standard output
*
* @param e code error
* @param code code of the file in which the error occurred
* @param os output stream
* @param colorize generate colors or not
*/
ARK_API void generate(const CodeError& e, std::string code = "", std::ostream& os = std::cout);
ARK_API void generate(const CodeError& e, std::ostream& os = std::cout, bool colorize = true);
}
}

Expand Down
12 changes: 3 additions & 9 deletions include/Ark/Logger.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -47,27 +47,21 @@ namespace Ark::internal
void info(const char* fmt, Args&&... args)
{
if (shouldInfo())
std::cout << fmt::format("[INFO ][{}] ", m_name)
<< fmt::vformat(fmt, fmt::make_format_args(args...))
<< std::endl;
fmt::println("[INFO ][{}] {}", m_name, fmt::vformat(fmt, fmt::make_format_args(args...)));
}

template <typename... Args>
void debug(const char* fmt, Args&&... args)
{
if (shouldDebug())
std::cout << fmt::format("[DEBUG][{}] ", m_name)
<< fmt::vformat(fmt, fmt::make_format_args(args...))
<< std::endl;
fmt::println("[DEBUG][{}] {}", m_name, fmt::vformat(fmt, fmt::make_format_args(args...)));
}

template <typename... Args>
void trace(const char* fmt, Args&&... args)
{
if (shouldTrace())
std::cout << fmt::format("[TRACE][{}] ", m_name)
<< fmt::vformat(fmt, fmt::make_format_args(args...))
<< std::endl;
fmt::println("[TRACE][{}] {}", m_name, fmt::vformat(fmt, fmt::make_format_args(args...)));
}

private:
Expand Down
19 changes: 0 additions & 19 deletions include/termcolor/proxy.hpp

This file was deleted.

1 change: 0 additions & 1 deletion lib/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ Includes
* [fmt](https://github.com/fmtlib/fmt), MIT License
* [picosha2](https://github.com/okdshin/PicoSHA2), MIT License
* [replxx](https://github.com/AmokHuginnsson/replxx/blob/master/LICENSE.md), MIT License + specifities
* [termcolor](https://github.com/ikalnytskyi/termcolor), BSD (3-clause) License
* [ut](https://github.com/boost-ext/ut), BSL 1.0

All used by [Ark](https://github.com/ArkScript-lang/Ark)
2 changes: 1 addition & 1 deletion lib/modules
1 change: 0 additions & 1 deletion lib/termcolor
Submodule termcolor deleted from 13f559
8 changes: 5 additions & 3 deletions src/arkreactor/Builtins/IO.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,8 @@ namespace Ark::internal::Builtins::IO
Value print(std::vector<Value>& n, VM* vm)
{
for (auto& value : n)
std::cout << value.toString(*vm);
std::cout << '\n';
fmt::print("{}", value.toString(*vm));
fmt::println("");

return nil;
}
Expand All @@ -43,7 +43,7 @@ namespace Ark::internal::Builtins::IO
Value puts_(std::vector<Value>& n, VM* vm)
{
for (auto& value : n)
std::cout << value.toString(*vm);
fmt::print("{}", value.toString(*vm));

return nil;
}
Expand Down Expand Up @@ -189,6 +189,8 @@ namespace Ark::internal::Builtins::IO

std::vector<Value> r;
for (const auto& entry : std::filesystem::directory_iterator(n[0].string()))
// cppcheck-suppress useStlAlgorithm
// We can't use std::transform with a directory_iterator
r.emplace_back(entry.path().string());

return Value(std::move(r));
Expand Down
Loading

0 comments on commit cd81653

Please sign in to comment.