Skip to content

Commit 05e4484

Browse files
committed
Add files
1 parent 99bcf5d commit 05e4484

File tree

2 files changed

+63
-0
lines changed

2 files changed

+63
-0
lines changed

LICENSE

+21
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
The MIT License (MIT)
2+
3+
Copyright (c) 2017 Naomichi Agata
4+
5+
Permission is hereby granted, free of charge, to any person obtaining a copy
6+
of this software and associated documentation files (the "Software"), to deal
7+
in the Software without restriction, including without limitation the rights
8+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9+
copies of the Software, and to permit persons to whom the Software is
10+
furnished to do so, subject to the following conditions:
11+
12+
The above copyright notice and this permission notice shall be included in all
13+
copies or substantial portions of the Software.
14+
15+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21+
SOFTWARE.

README.md

+42
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
## termfest
2+
3+
termfest is a thread-safe TUI library that provides simple APIs to render texts in terminal, heavily inspired by nsf/termbox-go.
4+
Currently, termfest doesn't support windows because of my poor windows experience.
5+
6+
termfest has internal buffer for efficient rendering.
7+
Applications can render everything to the buffer every time, and termfest flushes the buffer and renders only the difference between the terminal state and the buffer.
8+
9+
```rust
10+
use termfest::{Termfest, Event};
11+
use termfest::attr::*;
12+
use termfest::key::*;
13+
14+
// first, initialize termfest.
15+
let (fest, events) = Termfest::hold().unwrap();
16+
17+
let mut y = 0;
18+
19+
// events is a receiver of a channel that accepts terminal events like key input.
20+
for ev in events.iter() {
21+
{
22+
// lock the screen.
23+
let mut screen = fest.lock_screen();
24+
// clear the buffer. you can render everything every time.
25+
// termfest can provide efficient rendering.
26+
screen.clear();
27+
// write to the buffer.
28+
let attr = Attribute { fg: Color::Red, ..Attribute::default() };
29+
screen.print(0, y, "Hello, world!", attr);
30+
// when the screen lock is freed, the buffer is flushed.
31+
// (you can flush the buffer with explicit `flush` call.)
32+
}
33+
match ev {
34+
Event::Key(ESC) | Event::Char('q') => break,
35+
Event::Key(ArrowUp) => if y > 0 { y -= 1; },
36+
Event::Key(ArrowDown) => y += 1,
37+
_ => {}
38+
}
39+
}
40+
```
41+
42+
See `examples` for more detail.

0 commit comments

Comments
 (0)