nngn
Loading...
Searching...
No Matches
terminal.h
Go to the documentation of this file.
1#ifndef NNGN_OS_TERMINAL_H
2#define NNGN_OS_TERMINAL_H
3
4#include <ranges>
5
6#include "math/vec2.h"
7#include "utils/log.h"
8#include "utils/utils.h"
9
10#include "os.h"
11
12namespace nngn {
13
14using nngn::uvec2;
15
17class Terminal {
18public:
20 Terminal(void) = default;
21 ~Terminal(void);
23 auto size(void) const { return this->m_size; }
25 auto pixel_size(void) const { return this->m_pixel_size; }
30 bool init(int fd);
35 std::tuple<bool, bool> update_size(void);
37 bool write(std::size_t n, const char *p) const;
39 bool write(const std::ranges::sized_range auto &v) const;
40 bool flush(void) const;
41 bool drain(void) const;
42 bool show_cursor(void) const;
43 bool hide_cursor(void) const;
44private:
46 int fd = -1;
48 // XXX why do terminals handle writes via `fwrite` much better?
49 FILE *f = nullptr;
54 int tty_fd = -1;
56 uvec2 m_size = {};
59};
60
61bool Terminal::write(const std::ranges::sized_range auto &v) const {
62 return this->write(std::size(v), std::data(v));
63}
64
65inline bool Terminal::show_cursor(void) const {
67}
68
69inline bool Terminal::hide_cursor(void) const {
71}
72
73}
74
75#endif
Handles interactions with the output terminal.
Definition: terminal.h:17
bool hide_cursor(void) const
bool write(const std::ranges::sized_range auto &v) const
Outputs the entire contents of a range.
uvec2 m_size
Size of the terminal in characters.
Definition: terminal.h:56
bool show_cursor(void) const
FILE * f
fdopen(3)ed version of fd.
Definition: terminal.h:49
bool init(int fd)
Creates an object for a given TTY.
auto pixel_size(void) const
Size of the terminal in pixels.
Definition: terminal.h:25
auto size(void) const
Size of the terminal in characters.
Definition: terminal.h:23
uvec2 m_pixel_size
Size of the terminal in screen pixels, if available.
Definition: terminal.h:58
bool flush(void) const
Terminal(void)=default
bool write(std::size_t n, const char *p) const
Outputs the entire contents of a buffer.
int tty_fd
File descriptor for the controlling TTY.
Definition: terminal.h:54
std::tuple< bool, bool > update_size(void)
Retrieves the terminal size from the operating system.
bool drain(void) const
n
Definition: dump_lights.lua:5
p
Definition: input.lua:29
v[1]
Definition: math.lua:19
std::chrono::duration< float, typename T::period > fd
Definition: timing.cpp:8
#define NNGN_MOVE_ONLY(x)
Definition: utils.h:39
Definition: audio.cpp:7
static constexpr auto hide_cursor
Definition: os.h:30
static constexpr auto show_cursor
Definition: os.h:29