Skip to content

Commit

Permalink
Complete ICU uses & various changes
Browse files Browse the repository at this point in the history
  • Loading branch information
a-n-t-h-o-n-y committed Feb 2, 2024
1 parent 6071cc3 commit 29b4710
Show file tree
Hide file tree
Showing 15 changed files with 180 additions and 162 deletions.
12 changes: 9 additions & 3 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -128,12 +128,14 @@ jobs:
- uses: actions/checkout@v3
with:
submodules: recursive
- name: Install ICU
run: brew install icu4c
- env:
CC: clang
CXX: clang++
run: |
mkdir build && cd build
cmake .. && make termcaps
cmake .. -DICU_ROOT=/usr/local/opt/icu4c && make termcaps
# MacOS-12 GCC
build-MacOS12-gcc12:
Expand All @@ -142,21 +144,25 @@ jobs:
- uses: actions/checkout@v3
with:
submodules: recursive
- name: Install ICU
run: brew install icu4c
- env:
CC: gcc-12
CXX: g++-12
run: |
mkdir build && cd build
cmake .. && make termcaps
cmake .. -DICU_ROOT=/usr/local/opt/icu4c && make termcaps
build-MacOS12-gcc11:
runs-on: macos-12
steps:
- uses: actions/checkout@v3
with:
submodules: recursive
- name: Install ICU
run: brew install icu4c
- env:
CC: gcc-11
CXX: g++-11
run: |
mkdir build && cd build
cmake .. && make termcaps
cmake .. -DICU_ROOT=/usr/local/opt/icu4c && make termcaps
5 changes: 3 additions & 2 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ project(escape LANGUAGES CXX)
# Escape Library
add_library(escape STATIC
include/esc/glyph.hpp
include/esc/detail/any_of.hpp
include/esc/detail/transcode.hpp

src/io.cpp
src/terminfo.cpp
Expand All @@ -14,10 +16,9 @@ add_library(escape STATIC
src/mouse.cpp
src/detail/display.cpp
src/detail/is_urxvt.cpp
src/detail/mb_to_u32.cpp
src/detail/print.cpp
src/detail/transcode.cpp
src/detail/traits_to_int_sequence.cpp
src/detail/u32_to_mb.cpp
src/detail/console_file.cpp
src/detail/signals.cpp
)
Expand Down
17 changes: 17 additions & 0 deletions include/esc/detail/any_of.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
#pragma once

#include <concepts>

namespace esc::detail {

/**
* Concept that checks if T is the same as any of Args.
*
* @details This does not check reference qualifiers, std::decay is used on T.
* @tparam T The type to check.
* @tparam Args The types to check against.
*/
template <typename T, typename... Args>
concept AnyOf = (std::is_same_v<Args, std::decay_t<T>> || ...);

} // namespace esc::detail
12 changes: 0 additions & 12 deletions include/esc/detail/is_any_of.hpp

This file was deleted.

12 changes: 0 additions & 12 deletions include/esc/detail/mb_to_u32.hpp

This file was deleted.

33 changes: 33 additions & 0 deletions include/esc/detail/transcode.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
#pragma once

#include <array>
#include <string>
#include <string_view>

namespace esc::detail {

/**
* Convert the given char32_t to its UTF8 reprensentation.
*
* @param c The char32_t to convert.
* @return The UTF8 bytes.
*/
[[nodiscard]] auto u32_to_u8(char32_t c) -> std::string;

/**
* Convert the given char32_t string to its UTF8 reprensentation.
*
* @param s The char32_t string to convert.
* @return The UTF8 bytes.
*/
[[nodiscard]] auto u32_to_u8(std::u32string_view s) -> std::string;

/**
* Convert a UTF8 array of bytes into a UTF32 char32_t.
*
* @param bytes The UTF8 array of bytes to convert. Unused bytes should be null.
* @return The char32_t bytes.
*/
[[nodiscard]] auto u8_to_u32(std::array<char, 4> bytes) -> char32_t;

} // namespace esc::detail
13 changes: 0 additions & 13 deletions include/esc/detail/u32_to_mb.hpp

This file was deleted.

3 changes: 0 additions & 3 deletions include/esc/io.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,6 @@ namespace esc {
void write(char c);

/// Writes a 4 byte char to the console via stdout.
/** Converts the character to a multi-byte array via std::c32rtomb() and sends
* each resulting char to write(). The conversion uses the current C locale.
* Throws std::runtime_error if there is an error during conversion. */
void write(char32_t c) noexcept(false);

/// Writes each char of \p sv to the console via stdout.
Expand Down
59 changes: 37 additions & 22 deletions include/esc/sequence.hpp
Original file line number Diff line number Diff line change
@@ -1,13 +1,15 @@
#ifndef ESC_SEQUENCE_HPP
#define ESC_SEQUENCE_HPP
#pragma once

#include <concepts>
#include <string>
#include <variant>

#include <esc/brush.hpp>
#include <esc/color.hpp>
#include <esc/color_index.hpp>
#include <esc/default_color.hpp>
#include <esc/detail/is_any_of.hpp>
#include <esc/detail/any_of.hpp>
#include <esc/glyph.hpp>
#include <esc/point.hpp>
#include <esc/trait.hpp>
#include <esc/true_color.hpp>
Expand Down Expand Up @@ -111,30 +113,43 @@ struct Blank_screen {};
/// Return control sequence to set Brush Colors and Traits.
[[nodiscard]] auto escape(Brush b) -> std::string;

// GLYPH -----------------------------------------------------------------------

/// Return control sequence to set Glyph Brush and Symbol.
[[nodiscard]] auto escape(Glyph const& g) -> std::string;

// CONVENIENCE -----------------------------------------------------------------

/**
* Types that can have a control sequence generated for them.
*/
template <typename T>
bool constexpr is_escapable = detail::is_any_of<T,
Cursor_position,
Blank_row,
Blank_screen,
Trait,
Traits,
ColorBG,
ColorFG,
Brush>;

/// Convenience function to concatenate multiple escapable objects at once.
/** Returns a single string containing the escape sequences for all args... */
template <typename... Args>
[[nodiscard]] auto escape(Args... args) -> std::string
concept Escapable = detail::AnyOf<T,
Cursor_position,
Blank_row,
Blank_screen,
Trait,
Traits,
ColorBG,
ColorFG,
Brush,
Glyph>;

/**
* Convenience function to concatenate multiple escapable objects at once.
*
* @details Returns a single string containing the escape sequences for all
* args...
* @tparam Args... A list of escapable types.
* @param args... A list of escapable objects.
* @return A single string containing the escape sequences for all args...
*/
template <Escapable... Args>
[[nodiscard]] auto escape(Args&&... args) -> std::string
{
static_assert(sizeof...(Args) > 0,
"escape(...): Must have at least one argument.");
static_assert((is_escapable<Args> && ...),
"escape(...): All Args... must be escapable types.");
return (escape(args) + ...);
return (escape(std::forward<Args>(args)) + ...);
}

} // namespace esc
#endif // ESC_SEQUENCE_HPP
} // namespace esc
49 changes: 28 additions & 21 deletions include/esc/terminal.hpp
Original file line number Diff line number Diff line change
@@ -1,11 +1,14 @@
#ifndef ESC_TERMINAL_HPP
#define ESC_TERMINAL_HPP
#pragma once

#include <concepts>

#include <esc/area.hpp>
#include <esc/detail/is_any_of.hpp>
#include <esc/detail/any_of.hpp>
#include <esc/mouse.hpp>

/** \file
* Terminal Specific Settings. */
* Terminal Specific Settings.
*/

namespace esc {

Expand Down Expand Up @@ -75,25 +78,30 @@ void set(MouseMode);

// CONVENIENCE -----------------------------------------------------------------

/**
* Types that represent a setting on the terminal.
*/
template <typename T>
bool constexpr is_setable = detail::is_any_of<T,
Echo,
Input_buffer,
Signals,
Screen_buffer,
Cursor,
MouseMode,
KeyMode>;

/// Convenience function to set multiple properties at once.
template <typename... Args>
void set(Args... args)
concept Setable = detail::AnyOf<T,
Echo,
Input_buffer,
Signals,
Screen_buffer,
Cursor,
MouseMode,
KeyMode>;

/**
* Convenience function to set multiple properties at once.
* @tparam Args The types of the properties to set.
* @param args The properties to set.
*/
template <Setable... Args>
auto set(Args&&... args) -> void
{
static_assert(sizeof...(Args) > 0,
"set(...): Must have at least one argument.");
static_assert((is_setable<Args> && ...),
"set(...): All Args... must be setable types.");
(set(args), ...);
(set(std::forward<Args>(args)), ...);
}

// INITIALIZE ------------------------------------------------------------------
Expand Down Expand Up @@ -182,5 +190,4 @@ auto terminal_height() -> int;
/// Return the width and height of the terminal screen.
[[nodiscard]] auto terminal_area() -> Area;

} // namespace esc
#endif // ESC_TERMINAL_HPP
} // namespace esc
36 changes: 0 additions & 36 deletions src/detail/mb_to_u32.cpp

This file was deleted.

Loading

0 comments on commit 29b4710

Please sign in to comment.