Skip to content

Commit bf5f0b0

Browse files
authored
Merge pull request #3 from rerdavies/dev
Dev
2 parents bb7c425 + 084b769 commit bf5f0b0

35 files changed

+3337
-135
lines changed

CMakeLists.txt

+2-4
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
cmake_minimum_required(VERSION 3.16.0)
22
project(nwindows
3-
VERSION 0.0.1
3+
VERSION 0.0.2
44
DESCRIPTION "Modern Text User Interface Library for C++."
55
HOMEPAGE_URL "https://rerdavies.github.io/nwindows/"
66
LANGUAGES CXX
77
)
8-
set(NWINDOWS_RELEASE_QUALIFIER "-beta1")
8+
set(NWINDOWS_RELEASE_QUALIFIER "-beta2")
99

1010

1111

@@ -32,8 +32,6 @@ configure_file(
3232

3333

3434

35-
36-
3735
if (NWINDOWS_STRICT_COMPILER_OPTIONS)
3836

3937
set(CMAKE_CXX_STANDARD 20)

README.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
[![Documentation](https://img.shields.io/badge/documentation-Examples-blue)](https://github.com/rerdavies/nwindows/tree/main/examples)
66
<!--[![Documentation](https://img.shields.io/badge/documentation-Release%20Notes-blue)](https://reravies.github.io/nwindows/) -->
77

8-
*0.0.1-beta1*
8+
*0.0.2-beta2*
99

1010
The *NWindows* library is a C++ text user interface (TUI) library for building console applications on Linux.
1111
The library uses elements to compose user interfaces using an innovative and concise manipulator system. The library provides a rich set of elements with which to build user interfaces.

ReleaseNotes.md

+9
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,14 @@
11
## Release Notes
22

3+
### NWindows 0.0.2-beta2
4+
5+
- Polyfill checkbox/radio-button/dropdon characters on EGA/VGA (Linux) terminals.
6+
- Fallback to ASCII for particularly incapable terminals.
7+
- Back-port to GCC12.2 for Debian Bookworm.
8+
9+
10+
11+
312
### NWindows 0.0.1-beta1
413

514
Initial release of the NWindows Library.

config/NWindowsVersionInfo.hpp.in

+7-6
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,8 @@
2323

2424
#pragma once
2525

26-
#include <format>
26+
#include "nss.hpp"
27+
2728
// Uses Semantic Versioning
2829
#define NWINDOWS_MAJOR_VERSION ${PROJECT_VERSION_MAJOR}
2930
#define NWINDOWS_MINOR_VERSION ${PROJECT_VERSION_MINOR}
@@ -33,10 +34,10 @@
3334

3435

3536
#define NWINDOWS_VERSION_STRING() \
36-
std::format("NWindows {}.{}.{}{}", \
37-
NWINDOWS_MAJOR_VERSION,\
38-
NWINDOWS_MINOR_VERSION,\
39-
NWINDOWS_BUILD_NUMBER,\
40-
NWINDOWS_RELEASE_QUALIFIER)
37+
NSS("NWindows " \
38+
<< NWINDOWS_MAJOR_VERSION \
39+
<< '.' << NWINDOWS_MINOR_VERSION\
40+
<< '.' << NWINDOWS_BUILD_NUMBER\
41+
<< NWINDOWS_RELEASE_QUALIFIER)
4142

4243

docs/src/NWindowsVersionInfo.tsx

+1-1
Original file line numberDiff line numberDiff line change
@@ -21,4 +21,4 @@
2121
* SOFTWARE.
2222
*/
2323

24-
export const NWindowsVersion = "0.0.1-beta1";
24+
export const NWindowsVersion = "0.0.2-beta2";

examples/nwindows_test/CMakeLists.txt

+2
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@ add_executable(nwindows_test
99
edit_text_test_window.cpp
1010
error_test_window.cpp
1111
rendering_test_window.cpp
12+
ascii_fallback_test_window.cpp
13+
console_font_test_window.cpp
1214
)
1315

1416
target_link_libraries(
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,256 @@
1+
/*
2+
* Copyright (c) 2025 Robin E. R. Davies
3+
* All rights reserved.
4+
5+
* Permission is hereby granted, free of charge, to any person obtaining a copy
6+
* of this software and associated documentation files (the "Software"), to deal
7+
* in the Software without restriction, including without limitation the rights
8+
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9+
* copies of the Software, and to permit persons to whom the Software is
10+
* furnished to do so, subject to the following conditions:
11+
12+
* The above copyright notice and this permission notice shall be included in all
13+
* copies or substantial portions of the Software.
14+
15+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16+
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17+
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18+
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19+
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20+
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21+
* SOFTWARE.
22+
*/
23+
24+
#include "tests.hpp"
25+
#include <term.h>
26+
#include <memory.h>
27+
28+
class NAltTextElement: public NElement {
29+
private:
30+
NAltTextElement(int acs)
31+
:NElement("AltText"), acs(acs)
32+
{
33+
}
34+
public:
35+
using self = NAltTextElement;
36+
using super = NElement;
37+
using ptr = std::shared_ptr<self>;
38+
39+
static ptr create(int acs) {
40+
return std::shared_ptr<self>(new NAltTextElement(acs));
41+
}
42+
43+
protected:
44+
virtual NSize measure(const NSize& constraints) override {
45+
return { 1,1 };
46+
}
47+
virtual void render() override {
48+
move(0,0);
49+
print_acs(0,0,this->acs);
50+
}
51+
private:
52+
int acs;
53+
54+
};
55+
56+
class NCharacterTestWindow: public NElement {
57+
private:
58+
NCharacterTestWindow(wchar_t c)
59+
:NElement("CharacterTest"), c(c)
60+
{
61+
}
62+
public:
63+
using self = NCharacterTestWindow;
64+
using super = NElement;
65+
using ptr = std::shared_ptr<self>;
66+
67+
static ptr create(wchar_t c) {
68+
return std::shared_ptr<self>(new NCharacterTestWindow(c));
69+
}
70+
71+
protected:
72+
virtual NSize measure(const NSize& constraints) override {
73+
return { 2,1 };
74+
}
75+
virtual void render() override {
76+
bool valid = window()->can_display_character(this->c);
77+
move(0,0);
78+
wchar_t str[2] = {this->c,0};
79+
if (!valid) {
80+
str[0] = L'X';
81+
}
82+
print(str);
83+
}
84+
private:
85+
wchar_t c;
86+
87+
};
88+
89+
90+
static NElement::ptr character_test(NWindow::ptr parentWindow, const std::string& label, char32_t c)
91+
{
92+
bool supported = parentWindow->can_display_character(c);
93+
return NHorizontalStackElement::create()
94+
| column_gap(1)
95+
| add_child(NTextElement::create(label))
96+
| add_child(NTextElement::create(u32string_to_utf8(std::u32string(1, c))))
97+
| add_child(NCharacterTestWindow::create(c))
98+
| add_child(NTextElement::create(supported ? "Supported" : "Not supported"));
99+
}
100+
101+
static NElement::ptr acs_grid(NWindow::ptr parentWindow)
102+
{
103+
NVerticalStackElement::ptr grid = NVerticalStackElement::create();
104+
for (char32_t c = 0x20; c < 0x80; c += 16)
105+
{
106+
NHorizontalStackElement::ptr row = NHorizontalStackElement::create();
107+
for (int i = 0; i < 16; i++)
108+
{
109+
char32_t cc = c+i;
110+
row->add_child(NAltTextElement::create((int)cc));
111+
}
112+
grid->add_child(row);
113+
}
114+
return grid;
115+
}
116+
117+
static NElement::ptr character_grid(NWindow::ptr parentWindow)
118+
{
119+
NVerticalStackElement::ptr grid = NVerticalStackElement::create();
120+
for (char32_t c = 0x20; c < 0x100; c += 16)
121+
{
122+
NHorizontalStackElement::ptr row = NHorizontalStackElement::create();
123+
for (int i = 0; i < 16; i++)
124+
{
125+
char32_t cc = c+i;
126+
if (cc == 0x7F) cc = 0xFFFD;
127+
if (wcwidth(cc) == -1)
128+
{
129+
cc = 0xFFFD;
130+
}
131+
row->add_child(NTextElement::create(u32string_to_utf8(std::u32string(1, cc))));
132+
}
133+
grid->add_child(row);
134+
}
135+
return grid;
136+
}
137+
138+
static NElement::ptr device_grid(NWindow::ptr parentWindow)
139+
{
140+
NVerticalStackElement::ptr grid = NVerticalStackElement::create();
141+
for (char32_t c = 0xF000; c < 0xF100; c += 16) // special range for device characters on EGA/VGA devices.
142+
{
143+
NHorizontalStackElement::ptr row = NHorizontalStackElement::create();
144+
for (int i = 0; i < 16; i++)
145+
{
146+
char32_t cc = c+i;
147+
if (cc == 0x7F) cc = 0xFFFD;
148+
if (wcwidth(cc) == -1)
149+
{
150+
cc = 0xFFFD;
151+
}
152+
row->add_child(NTextElement::create(u32string_to_utf8(std::u32string(1, cc))));
153+
}
154+
grid->add_child(row);
155+
}
156+
return grid;
157+
}
158+
159+
void ascii_fallback_test_window(NWindow::ptr parentWindow /* = nullptr */)
160+
{
161+
NWindow::ptr window = NWindow::create(parentWindow, 66, AUTO_SIZE);
162+
NTextElement::ptr keyIndicator;
163+
164+
std::string oGrave = u32string_to_utf8(U"o\u0300");
165+
NColorPair boundsColor;
166+
if (parentWindow && parentWindow->max_color_pairs() > 8) {
167+
boundsColor = window->make_color_pair(0xC0C0C0, 0x4040C0);
168+
}
169+
else {
170+
boundsColor = window->make_color_pair(0xE00000, 0x000000);
171+
}
172+
window
173+
| title("ASCII Fallback Test")
174+
| add_child(
175+
NVerticalStackElement::create()
176+
| margin({ 2,1,2,1 })
177+
| row_gap(1)
178+
| add_child(
179+
NTextElement::create("Fallbacks only occur on non-Unicode terminals. ●○ ☑☐ ⏵⏷ ◉🗹□")
180+
| wrap_text()
181+
)
182+
| add_child(
183+
NHorizontalStackElement::create()
184+
| column_gap(2)
185+
| add_child(
186+
NVerticalStackElement::create()
187+
| add_child(
188+
character_test(parentWindow,
189+
"O with Grave: ",
190+
191+
192+
193+
0xF2)
194+
)
195+
| add_child(
196+
character_test(parentWindow,
197+
"Composing accent: ",
198+
0x301)
199+
)
200+
| add_child(
201+
character_test(parentWindow,
202+
"Smile Emjoi: ",
203+
0x1F60A
204+
)
205+
)
206+
| add_child(
207+
character_test(parentWindow,
208+
"Checkbox: ",
209+
U'')
210+
)
211+
| add_child(
212+
character_test(parentWindow,
213+
"Checkbox: ",
214+
U'')
215+
)
216+
| add_child(
217+
character_test(parentWindow,
218+
"RadioButton: ",
219+
U'')
220+
)
221+
)
222+
| add_child(
223+
NVerticalStackElement::create()
224+
| alignment(NAlignment::Start)
225+
| add_child(NCheckboxElement::create("Checkbox", true))
226+
| add_child(NCheckboxElement::create("Checkbox", false))
227+
| add_child(NRadioGroupElement::create(
228+
NOrientation::Vertical,
229+
{ "Radio 1", "Radio 2", "Radio 3" }, 1))
230+
)
231+
)
232+
| add_child(
233+
NHorizontalStackElement::create()
234+
| column_gap(3)
235+
| add_child(character_grid(parentWindow))
236+
| add_child(acs_grid(parentWindow))
237+
| add_child(device_grid(parentWindow))
238+
)
239+
| add_child(
240+
NHorizontalStackElement::create()
241+
| alignment(NAlignment::End)
242+
| add_child(
243+
NButtonElement::create("OK")
244+
//| is_default()
245+
| width(15)
246+
| on_clicked([windowRef = window->weak_ptr()](NMouseButton button, NClickedEventArgs& args) mutable {
247+
args.handled = true;
248+
windowRef.lock()->close();
249+
})
250+
)
251+
)
252+
)
253+
;
254+
255+
}
256+

0 commit comments

Comments
 (0)