Skip to content

Commit 784bea7

Browse files
committed
feat(rix): update debug facade integration
1 parent 7f50b7b commit 784bea7

10 files changed

Lines changed: 222 additions & 56 deletions

File tree

README.md

Lines changed: 41 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,10 @@ It gives Vix C++ projects a single optional facade object:
99

1010
int main()
1111
{
12-
rix.debug.print("Hello {}", "Rix");
12+
rix.debug.print("Hello", "Rix");
13+
1314
auto table = rix.csv.parse("name,language\nAda,C++\n");
15+
1416
rix.debug.log("loaded {} rows", table.size());
1517
}
1618
```
@@ -64,7 +66,7 @@ vix install
6466

6567
int main()
6668
{
67-
rix.debug.print("Hello {}", "Rix");
69+
rix.debug.print("Hello", "Rix");
6870

6971
const auto message = rix.debug.format("Package: {}", "rix/rix");
7072

@@ -95,16 +97,15 @@ int main()
9597
"Gaspard,Vix\n";
9698

9799
const auto table = rix.csv.parse(input);
100+
98101
rix.debug.log("loaded {} rows", table.size());
99102

100103
for (const auto &row : table)
101104
{
102105
for (const auto &field : row)
103106
{
104-
rix.debug.print.inline_text("{} ", field);
107+
rix.debug.print(field);
105108
}
106-
107-
rix.debug.print();
108109
}
109110

110111
return 0;
@@ -118,7 +119,7 @@ int main()
118119

119120
int main()
120121
{
121-
rix.debug.print("Hello {}", "Rix");
122+
rix.debug.print("Hello", "Rix");
122123

123124
auto text = rix.debug.format("Package: {}", "rix/rix");
124125

@@ -131,6 +132,37 @@ int main()
131132
}
132133
```
133134

135+
## Print and format
136+
137+
`rix.debug.print` does not replace `{}` placeholders.
138+
139+
It prints values separated by spaces:
140+
141+
```cpp
142+
rix.debug.print("Hello", "Rix");
143+
rix.debug.print(1, 2, 3);
144+
```
145+
146+
Output:
147+
148+
```txt
149+
Hello Rix
150+
1 2 3
151+
```
152+
153+
For placeholder formatting, use `rix.debug.format`:
154+
155+
```cpp
156+
auto text = rix.debug.format("Hello {}", "Rix");
157+
rix.debug.print(text);
158+
```
159+
160+
Or use `rix.debug.log` directly:
161+
162+
```cpp
163+
rix.debug.log("Hello {}", "Rix");
164+
```
165+
134166
## Independent packages
135167

136168
Each Rix module can also be used independently.
@@ -167,7 +199,9 @@ vix install
167199
int main()
168200
{
169201
rixlib::debug::Debug debug;
170-
debug.print("Hello {}", "Rix");
202+
203+
debug.print("Hello", "Rix");
204+
debug.log("loaded {} rows", 3);
171205

172206
return 0;
173207
}

examples/basic.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77

88
int main()
99
{
10-
rix.debug.print("Hello {}", "Rix");
10+
rix.debug.print("Hello", "Rix");
1111
rix.debug.log("facade is ready");
1212

1313
return 0;

examples/csv.cpp

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55

66
#include <rix.hpp>
77

8+
#include <sstream>
89
#include <string>
910

1011
namespace
@@ -13,12 +14,19 @@ namespace
1314
{
1415
for (const auto &row : table)
1516
{
16-
for (const auto &field : row)
17+
std::ostringstream line;
18+
19+
for (std::size_t i = 0; i < row.size(); ++i)
1720
{
18-
rix.debug.print.inline_text("{} ", field);
21+
if (i > 0)
22+
{
23+
line << " ";
24+
}
25+
26+
line << row[i];
1927
}
2028

21-
rix.debug.print();
29+
rix.debug.print(line.str());
2230
}
2331
}
2432
}

examples/debug.cpp

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,9 @@
55

66
#include <rix.hpp>
77

8-
#include <string>
9-
108
int main()
119
{
12-
rix.debug.print("Hello {}", "Rix");
10+
rix.debug.print("Hello", "Rix");
1311

1412
const std::string package = rix.debug.format("Package: {}", "rix/rix");
1513

include/rix.hpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,8 @@
1212
*
1313
* @code
1414
* auto table = rix.csv.parse("name,lang\nAda,C++\n");
15-
* rix.debug.print("loaded {} rows", table.size());
15+
* rix.debug.print("loaded rows:", table.size());
16+
* rix.debug.log("loaded {} rows", table.size());
1617
* @endcode
1718
*
1819
* @author Gaspard Kirira

packages/debug/README.md

Lines changed: 154 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -1,83 +1,208 @@
1-
# rix/debug
1+
# @rix/debug
22

3-
Debug printing, formatting, logging, and inspection utilities for Rix.
3+
Debug utilities for Rix.
44

5-
`rix/debug` is part of Rix, the userland package layer for the Vix.cpp ecosystem.
5+
`@rix/debug` provides a small set of developer-focused tools for C++ projects:
66

7-
The source code lives in its own repository. This folder only keeps the official package entry used by the Rix umbrella repository.
7+
- formatted strings
8+
- simple logging
9+
- value inspection
10+
- print helpers
811

9-
## Install
12+
It can be used as an independent Rix package, or through the unified `@rix/rix` facade.
13+
14+
## Installation
1015

1116
```bash
1217
vix add @rix/debug
1318
vix install
1419
```
1520

16-
## Use
21+
## Basic usage
1722

1823
```cpp
1924
#include <rix/debug.hpp>
2025

2126
int main()
2227
{
23-
rixlib::debug::Debug debug;
28+
rixlib::debug::Debug debug{};
2429

25-
debug.print("Hello {}", "Rix");
30+
debug.print("Hello", "Rix");
2631

2732
auto text = debug.format("Package: {}", "rix/debug");
2833

2934
debug.log("loaded {} rows", 3);
3035
debug.log.warn("slow request: {}ms", 120);
3136

3237
debug.inspect(text);
38+
39+
return 0;
3340
}
3441
```
3542

36-
## Repository
43+
Output:
3744

3845
```txt
39-
https://github.com/rixcpp/debug
46+
Hello Rix
47+
[debug] loaded 3 rows
48+
[warn] slow request: 120ms
49+
Package: rix/debug
4050
```
4151

42-
## Package
52+
## Formatting
53+
54+
`debug.format` supports simple placeholder-based formatting.
55+
56+
```cpp
57+
auto message = debug.format("Hello {}", "Rix");
58+
auto result = debug.format("{0} + {0} = {1}", 2, 4);
59+
auto escaped = debug.format("{{ value }} = {}", 42);
60+
```
61+
62+
Supported placeholders:
4363

4464
```txt
45-
rix/debug
65+
{} automatic argument indexing
66+
{0} explicit positional indexing
67+
{{ escaped opening brace
68+
}} escaped closing brace
4669
```
4770

48-
## Namespace
71+
Format specifiers such as `{:>10}` or `{:.2f}` are intentionally not supported.
72+
73+
## Logging
4974

5075
```cpp
51-
rixlib::debug
76+
debug.log("loaded {} rows", 3);
77+
debug.log.info("server started");
78+
debug.log.warn("slow request: {}ms", 120);
79+
debug.log.error("failed: {}", "timeout");
80+
```
81+
82+
Output:
83+
84+
```txt
85+
[debug] loaded 3 rows
86+
[info] server started
87+
[warn] slow request: 120ms
88+
[error] failed: timeout
5289
```
5390

54-
## CMake target
91+
## Printing
92+
93+
`debug.print` is not a formatter.
94+
95+
It prints values separated by spaces.
5596

56-
```cmake
57-
rix::debug
97+
```cpp
98+
debug.print("Hello", "Rix");
99+
debug.print(1, 2, 3);
58100
```
59101

60-
## Manifest
102+
Output:
61103

62104
```txt
63-
packages/debug/vix.json
105+
Hello Rix
106+
1 2 3
64107
```
65108

66-
## Role in Rix
109+
For formatted strings, use `debug.format` or `debug.log`.
67110

68-
Rix does not embed package source code.
111+
```cpp
112+
debug.print(debug.format("Hello {}", "Rix"));
113+
```
69114

70-
The real library lives in:
115+
## Inspection
71116

72-
```txt
73-
github.com/rixcpp/debug
117+
```cpp
118+
debug.inspect(42);
119+
120+
auto value = debug.inspect.to_string(true);
121+
122+
bool ok = debug.inspect.check(42, 42);
123+
```
124+
125+
Inspection is useful for debugging values, containers, optional values, variants, and other supported C++ types.
126+
127+
## Independent API
128+
129+
You can also use the free functions directly.
130+
131+
```cpp
132+
#include <rix/debug.hpp>
133+
134+
int main()
135+
{
136+
rixlib::print("Hello", "Rix");
137+
138+
auto text = rixlib::format("Package: {}", "rix/debug");
139+
140+
rixlib::inspect(text);
141+
142+
return 0;
143+
}
74144
```
75145

76-
The Rix facade mounts this package as:
146+
## Unified Rix facade
147+
148+
When used through `@rix/rix`, the debug package is mounted under `rix.debug`.
77149

78150
```cpp
79-
rix.debug.print(...)
80-
rix.debug.format(...)
81-
rix.debug.log(...)
82-
rix.debug.inspect(...)
151+
#include <rix.hpp>
152+
153+
int main()
154+
{
155+
rix.debug.print("Hello", "Rix");
156+
rix.debug.log("loaded {} rows", 3);
157+
158+
return 0;
159+
}
160+
```
161+
162+
## Design
163+
164+
`@rix/debug` is intentionally small and focused.
165+
166+
It does not try to replace full logging frameworks or formatting libraries. Its role is to provide simple debugging primitives that are easy to use in Rix-based C++ projects.
167+
168+
The package exposes two layers:
169+
170+
```txt
171+
rixlib::format(...)
172+
rixlib::print(...)
173+
rixlib::inspect(...)
83174
```
175+
176+
and the object-style API:
177+
178+
```txt
179+
rixlib::debug::Debug
180+
```
181+
182+
This keeps the package usable on its own while allowing the unified Rix facade to mount it cleanly as:
183+
184+
```txt
185+
rix.debug
186+
```
187+
188+
## Build
189+
190+
```bash
191+
vix build
192+
```
193+
194+
## Run example
195+
196+
```bash
197+
vix run
198+
```
199+
200+
## Tests
201+
202+
```bash
203+
vix tests
204+
```
205+
206+
## License
207+
208+
MIT

0 commit comments

Comments
 (0)