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
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
// Copyright (C) 2023 Mateo Lafalce
//
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with this program. If not, see <https://www.gnu.org/licenses/>.
//!
//! [<img alt="crates.io" src="https://img.shields.io/crates/v/k_board.svg?style=for-the-badge&color=fc8d62&logo=rust" height="20">](https://crates.io/crates/k_board)
//! [<img alt="github" src="https://img.shields.io/badge/github-mateolafalce/k__board-8da0cb?style=for-the-badge&labelColor=555555&logo=github" height="20">](https://github.com/mateolafalce/k_board)
//! [<img alt="docs.rs" src="https://img.shields.io/badge/docs.rs-k__board-66c2a5?style=for-the-badge&labelColor=555555&logo=docs.rs" height="20">](https://docs.rs/k_board)
//!
//! A lightweight keyboard mannager developed for dynamic programs by listening to keyboard events in raw mode (without the need to press enter). The handler has all the standard events of a western keyboard.
//!
//! - Gnu/Linux
//!
//! # Examples
//!
//! ```rust,ignore
//! use k_board::{keyboard::Keyboard, keys::Keys};
//!
//!fn main() {
//! menu(0);
//! for key in Keyboard::new() {
//! match key {
//! Keys::Up => menu(0),
//! Keys::Down => menu(1),
//! Keys::Enter => break,
//! _ => {}
//! }
//! }
//!}
//!
//!fn menu(operation: u8) {
//! std::process::Command::new("clear").status().unwrap();
//! let mut op: Vec<char> = vec!['*', ' '];
//! if operation == 1 {
//! op[0] = ' ';
//! op[1] = '*';
//! }
//! println!(
//! "[{}] I use k_board lightweight software\n[{}] I use heavyweight software",
//! op[0], op[1]
//! );
//!}
//! ```
//!
//! # Contributing
//! Feel free to contribute to the repository. Make each modification to the code formatted with code before with `cargo fmt`. Below, a fragment that allows you to visualize in hexadecimal the key or the event executed on your keyboard:
//!
//! ```rust,ignore
//!use k_board::termio::{restore_termios, setup_raw_mode, termios};
//!use std::io::{Read, Write};
//!
//!fn main() -> std::io::Result<()> {
//! println!("Press a key or an keyboard event!");
//! loop {
//! let _ = get_key();
//! }
//!}
//!
//!pub fn get_key() -> std::io::Result<()> {
//! let termios_enviroment: termios = setup_raw_mode()?;
//! std::io::stdout().flush().unwrap();
//! let mut buffer: [u8; 3] = [0; 3];
//! #[allow(clippy::unused_io_amount)]
//! std::io::stdin().read(&mut buffer)?;
//! if buffer[0] != 0x00 {
//! println!(
//! "[0x{:x?}, 0x{:x?}, 0x{:x?}]",
//! buffer[0], buffer[1], buffer[2]
//! );
//! }
//! std::io::stdout().flush().unwrap();
//! restore_termios(&termios_enviroment)?;
//! Ok(())
//!}
//! ```
//!
use crate::;
use ;