Uni20
Asynchronous tensor and runtime library.
Loading...
Searching...
No Matches
presentation_example_common.hpp
Go to the documentation of this file.
1#pragma once
2
4
5#include <cstddef>
6#include <cstdio>
7#include <string>
8#include <string_view>
9
11{
13
15{
16 auto policy = presentation::terminal_policy(stdout);
18 policy.wrap_width = width;
19 policy.tab_width = 4;
20 return policy;
21}
22
24{
25 auto policy = terminal_demo_policy(width);
26 policy.glyphs = glyphs;
27 policy.charset = presentation::text_charset::utf8;
28 return policy;
29}
30
31[[nodiscard]] inline terminal::TerminalStyle style(std::string_view spec) { return terminal::TerminalStyle(spec); }
32
33[[nodiscard]] inline std::string repeat(char ch, std::size_t count) { return std::string(count, ch); }
34
35[[nodiscard]] inline std::string width_ruler(std::size_t width)
36{
37 std::string ruler;
38 ruler.reserve(width);
39 for (std::size_t i = 0; i < width; ++i)
40 {
41 ruler.push_back(static_cast<char>('0' + ((i + 1) % 10)));
42 }
43 return ruler;
44}
45
46[[nodiscard]] inline std::size_t detected_terminal_width()
47{
48 int const columns = terminal::columns();
49 return columns > 0 ? static_cast<std::size_t>(columns) : 80;
50}
51
53 terminal::TerminalStyle line_style = {})
54{
55 for (std::size_t i = 0; i < count; ++i)
56 {
57 text.append(glyph, line_style);
58 }
59}
60
61} // namespace uni20::examples::presentation_demo
Definition terminal.hpp:262
A sequence of styled text spans and semantic glyph tokens.
Definition presentation.hpp:216
styled_text & append(std::string_view text, terminal::TerminalStyle style={})
Append a text span.
Definition presentation.cpp:1164
std::size_t width
Definition display.cpp:142
presentation::styled_text text
Definition display.cpp:141
int columns()
Return the output terminal column count.
Definition terminal.cpp:502
Definition presentation_example_common.hpp:11
presentation::output_policy terminal_demo_policy(std::size_t width)
Definition presentation_example_common.hpp:14
std::string repeat(char ch, std::size_t count)
Definition presentation_example_common.hpp:33
void append_glyphs(presentation::styled_text &text, presentation::semantic_glyph glyph, std::size_t count, terminal::TerminalStyle line_style={})
Definition presentation_example_common.hpp:52
presentation::output_policy forced_demo_policy(presentation::glyph_set glyphs, std::size_t width)
Definition presentation_example_common.hpp:23
std::size_t detected_terminal_width()
Definition presentation_example_common.hpp:46
std::string width_ruler(std::size_t width)
Definition presentation_example_common.hpp:35
Definition data_table.cpp:8
semantic_glyph
Names semantic glyphs independently of their rendered spelling.
Definition presentation.hpp:117
output_policy terminal_policy(std::FILE *stream)
Build a policy for terminal rendering.
Definition presentation.cpp:1186
glyph_set
Selects the preferred glyph family for semantic symbols and ornaments.
Definition presentation.hpp:36
terminal::TerminalStyle style
Definition presentation.cpp:2434
std::optional< semantic_glyph > glyph
Definition presentation.cpp:2435
Output policy shared by presentation renderers and layout helpers.
Definition presentation.hpp:186