Skip to content

Commit e6c822e

Browse files
authored
Merge pull request #7 from RauliL/libterm
Switch from termbox2 to libterm
2 parents 5f15a29 + 41163ef commit e6c822e

11 files changed

Lines changed: 261 additions & 4480 deletions

File tree

.github/workflows/build.yml

Lines changed: 46 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -10,11 +10,14 @@ jobs:
1010
uses: actions/checkout@v6
1111
- name: Install MPFR
1212
run: sudo apt install -y libmpfr6 libmpfr-dev
13-
- name: Build
14-
uses: ashutoshvarma/action-cmake-build@master
13+
- name: Setup CMake
14+
uses: jwlawson/actions-setup-cmake@v2.2.0
1515
with:
16-
build-dir: ${{ runner.workspace }}/build
17-
build-type: Release
16+
cmake-version: '4.2.3'
17+
- name: Configure
18+
run: cmake -B build -DCMAKE_BUILD_TYPE=Release
19+
- name: Build
20+
run: cmake --build build
1821

1922
build-macos:
2023
runs-on: macos-latest
@@ -25,9 +28,44 @@ jobs:
2528
run: brew install mpfr
2629
- name: Export homebrew paths
2730
uses: spezifisch/export-homebrew-build-paths@v1.0.0
31+
- name: Setup CMake
32+
uses: jwlawson/actions-setup-cmake@v2.2.0
33+
with:
34+
cmake-version: '4.2.3'
35+
- name: Configure
36+
run: cmake -B build -DCMAKE_BUILD_TYPE=Release -DCMAKE_POLICY_VERSION_MINIMUM=3.5
2837
- name: Build
29-
uses: ashutoshvarma/action-cmake-build@master
38+
run: cmake --build build
39+
40+
build-windows:
41+
runs-on: windows-latest
42+
steps:
43+
- name: Checkout
44+
uses: actions/checkout@v6
45+
- name: Setup CMake
46+
uses: jwlawson/actions-setup-cmake@v2.2.0
3047
with:
31-
build-dir: ${{ runner.workspace }}/build
32-
build-type: Release
33-
configure-options: -DCMAKE_POLICY_VERSION_MINIMUM=3.5
48+
cmake-version: '4.2.3'
49+
- name: Install MPFR
50+
uses: msys2/setup-msys2@v2
51+
with:
52+
msystem: UCRT64
53+
update: true
54+
install: >-
55+
mingw-w64-ucrt-x86_64-gcc
56+
mingw-w64-ucrt-x86_64-gmp
57+
mingw-w64-ucrt-x86_64-make
58+
mingw-w64-ucrt-x86_64-mpfr
59+
- name: Configure
60+
shell: msys2 {0}
61+
run: |
62+
CMAKE_BIN="$(ls -d /c/hostedtoolcache/windows/cmake/*/x64/cmake-*-windows-x86_64/bin | tail -1)"
63+
export PATH="$CMAKE_BIN:$PATH"
64+
cmake -B build -G "MinGW Makefiles" -DCMAKE_BUILD_TYPE=Release \
65+
-DMPFR_ROOT="$(cygpath -m "$MINGW_PREFIX")"
66+
- name: Build
67+
shell: msys2 {0}
68+
run: |
69+
CMAKE_BIN="$(ls -d /c/hostedtoolcache/windows/cmake/*/x64/cmake-*-windows-x86_64/bin | tail -1)"
70+
export PATH="$CMAKE_BIN:$PATH"
71+
cmake --build build

CMakeLists.txt

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
cmake_minimum_required(VERSION 3.14)
1+
cmake_minimum_required(VERSION 3.32)
22
project(levite C CXX)
33

44
include(FetchContent)
@@ -22,7 +22,14 @@ FetchContent_Declare(
2222
GIT_REPOSITORY
2323
https://github.com/peelonet/peelo-xdg
2424
GIT_TAG
25-
v1.2.0
25+
v1.2.1
26+
)
27+
FetchContent_Declare(
28+
libterm
29+
GIT_REPOSITORY
30+
https://github.com/rizukirr/libterm
31+
GIT_TAG
32+
v0.1.2
2633
)
2734

2835
# We do not want to build Laskin CLI, GUI or any other fluff than the
@@ -32,7 +39,7 @@ set(LASKIN_ENABLE_GUI OFF CACHE BOOL "" FORCE)
3239
set(LASKIN_ENABLE_2CPP OFF CACHE BOOL "" FORCE)
3340
set(LASKIN_ENABLE_WEB OFF CACHE BOOL "" FORCE)
3441

35-
FetchContent_MakeAvailable(laskin rapidcsv PeeloXdg)
42+
FetchContent_MakeAvailable(laskin rapidcsv PeeloXdg libterm)
3643

3744
add_executable(
3845
levite
@@ -47,7 +54,6 @@ add_executable(
4754
./src/setting.cpp
4855
./src/screen.cpp
4956
./src/sheet.cpp
50-
./src/termbox2.cpp
5157
./src/utils.cpp
5258
)
5359

@@ -69,6 +75,7 @@ target_link_libraries(
6975
laskin
7076
rapidcsv
7177
PeeloXdg
78+
Libterm::libterm
7279
)
7380

7481
install(

src/color.cpp

Lines changed: 34 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -27,29 +27,31 @@
2727
#include <string>
2828
#include <unordered_map>
2929

30-
#include "./termbox2.h"
30+
#include <libterm/libterm.h>
31+
32+
#include "./color.hpp"
3133

3234
static const std::unordered_map<std::u32string, int> mapping =
3335
{
34-
{ U"default", TB_DEFAULT },
35-
{ U"black", TB_BLACK },
36-
{ U"red", TB_RED },
37-
{ U"green", TB_GREEN },
38-
{ U"yellow", TB_YELLOW },
39-
{ U"blue", TB_BLUE },
40-
{ U"magenta", TB_MAGENTA },
41-
{ U"cyan", TB_CYAN },
42-
{ U"white", TB_WHITE },
36+
{ U"default", LT_DEFAULT },
37+
{ U"black", LT_BLACK },
38+
{ U"red", LT_RED },
39+
{ U"green", LT_GREEN },
40+
{ U"yellow", LT_YELLOW },
41+
{ U"blue", LT_BLUE },
42+
{ U"magenta", LT_MAGENTA },
43+
{ U"cyan", LT_CYAN },
44+
{ U"white", LT_WHITE },
4345

44-
{ U"bright", TB_DEFAULT | TB_BRIGHT },
45-
{ U"bright-black", TB_BLACK | TB_BRIGHT },
46-
{ U"bright-red", TB_RED | TB_BRIGHT },
47-
{ U"bright-green", TB_GREEN | TB_BRIGHT },
48-
{ U"bright-yellow", TB_YELLOW | TB_BRIGHT },
49-
{ U"bright-blue", TB_BLUE | TB_BRIGHT },
50-
{ U"bright-magenta", TB_MAGENTA | TB_BRIGHT },
51-
{ U"bright-cyan", TB_CYAN | TB_BRIGHT },
52-
{ U"bright-white", TB_WHITE | TB_BRIGHT },
46+
{ U"bright", LT_DEFAULT | color::BRIGHT },
47+
{ U"bright-black", LT_BLACK | color::BRIGHT },
48+
{ U"bright-red", LT_RED | color::BRIGHT },
49+
{ U"bright-green", LT_GREEN | color::BRIGHT },
50+
{ U"bright-yellow", LT_YELLOW | color::BRIGHT },
51+
{ U"bright-blue", LT_BLUE | color::BRIGHT },
52+
{ U"bright-magenta", LT_MAGENTA | color::BRIGHT },
53+
{ U"bright-cyan", LT_CYAN | color::BRIGHT },
54+
{ U"bright-white", LT_WHITE | color::BRIGHT },
5355
};
5456

5557
namespace color
@@ -80,4 +82,17 @@ namespace color
8082

8183
return U"unknown";
8284
}
85+
86+
lt_attr
87+
to_lt_attr(int color)
88+
{
89+
lt_attr attr = static_cast<lt_attr>(color & ~BRIGHT);
90+
91+
if (color & BRIGHT)
92+
{
93+
attr |= LT_BOLD;
94+
}
95+
96+
return attr;
97+
}
8398
}

src/color.hpp

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,9 +28,16 @@
2828
#include <optional>
2929
#include <string>
3030

31+
#include <libterm/libterm.h>
32+
3133
namespace color
3234
{
35+
/* Internal bright-color flag (termbox2's TB_BRIGHT has no libterm equivalent). */
36+
constexpr int BRIGHT = 0x100;
37+
3338
std::optional<int> find_by_name(const std::u32string& name);
3439

3540
std::u32string get_name(int color);
41+
42+
lt_attr to_lt_attr(int color);
3643
}

src/command.cpp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,10 +27,11 @@
2727

2828
#include <peelo/unicode/encoding/utf8.hpp>
2929

30+
#include <libterm/libterm.h>
31+
3032
#include "./screen.hpp"
3133
#include "./setting.hpp"
3234
#include "./sheet.hpp"
33-
#include "./termbox2.h"
3435
#include "./utils.hpp"
3536

3637
using command_callback = void(*)(
@@ -85,7 +86,7 @@ cmd_quit(
8586
message = U"File modified.";
8687
return;
8788
}
88-
tb_shutdown();
89+
lt_shutdown();
8990
std::exit(EXIT_SUCCESS);
9091
}
9192

0 commit comments

Comments
 (0)