-
Notifications
You must be signed in to change notification settings - Fork 5
Expand file tree
/
Copy pathinput_output.hpp
More file actions
55 lines (43 loc) · 1.27 KB
/
input_output.hpp
File metadata and controls
55 lines (43 loc) · 1.27 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
#pragma once
#include <iostream>
#include "common.hpp"
// OS-specific libraries.
#include <termios.h>
// Scope object to hide the cursor. This avoids
// cursor twinkling when rewritting the same line
// too frequently.
// If you are within a cursor_hider context you can
// reenable the cursor using cursor_hider(false).
class cursor_hider : noncopyable_nonmovable
{
public:
cursor_hider(bool hide = true);
~cursor_hider();
private:
bool m_hide;
};
// Scope object to use alternative output buffer for
// fullscreen interactive terminal input/output.
class alternative_buffer : noncopyable_nonmovable
{
public:
alternative_buffer();
~alternative_buffer();
private:
struct termios m_previous_termios;
};
// Scope object to control echo of stdin to stdout.
// This should be disabled when entering passwords for example.
class echo_control : noncopyable_nonmovable
{
public:
echo_control(bool echo);
~echo_control();
private:
bool m_echo;
struct termios m_previous_termios;
};
// Display a prompt on stdout and return newline-terminated input received on
// stdin from the user. The `echo` argument controls whether stdin is echoed
// to stdout, use `false` for passwords.
std::string prompt_input(const std::string_view prompt, bool echo = true);