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;
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
Definition terminal.h:69
uvec2 m_size
Size of the terminal in characters.
Definition terminal.h:56
bool show_cursor(void) const
Definition terminal.h:65
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
Definition terminal.cpp:77
bool write(std::size_t n, const char *p) const
Outputs the entire contents of a buffer.
Definition terminal.cpp:66
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.
Definition terminal.cpp:43
bool drain(void) const
Definition terminal.cpp:85
FILE * f
fdopen(3)ed version of fd.
Definition terminal.h:49
local n
Definition dump_lights.lua:5
init
Definition img_common.lua:34
Definition audio.cpp:7
v[1]
Definition math.lua:22
#define NNGN_MOVE_ONLY(x)
Definition utils.h:39
static constexpr auto show_cursor
Definition os.h:29
static constexpr auto hide_cursor
Definition os.h:30
std::chrono::duration< float, typename T::period > fd
Definition timing.cpp:8