Skip to content

Commit eefbb78

Browse files
committed
Add piece sets
1 parent 0275c24 commit eefbb78

File tree

1 file changed

+73
-15
lines changed

1 file changed

+73
-15
lines changed

src/main.rs

Lines changed: 73 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -20,16 +20,70 @@ use std::{
2020
time::Duration,
2121
};
2222

23-
// Index via [DIRECTION OF THE PREVIOUS PART][CURRENT DIRECTION]
24-
const PIPE_MAP: [[char; 4]; 4] = [
25-
// Up
26-
['║', '║', '╔', '╗'],
27-
// Down
28-
['║', '║', '╚', '╝'],
29-
// Right
30-
['╝', '╗', '═', '═'],
31-
// Left
32-
['╚', '╔', '═', '═'],
23+
/// Map of different piece sets.
24+
///
25+
/// Index via [PIPE_SET_IDX][DIRECTION OF THE PREVIOUS PART][CURRENT DIRECTION]
26+
const PIPE_MAP: [[[char; 4]; 4]; 6] = [
27+
[
28+
// Up
29+
['#', '#', '#', '#'],
30+
// Down
31+
['#', '#', '#', '#'],
32+
// Right
33+
['#', '#', '#', '#'],
34+
// Left
35+
['#', '#', '#', '#'],
36+
],
37+
[
38+
// Up
39+
['•', '•', '•', '•'],
40+
// Down
41+
['•', '•', '•', '•'],
42+
// Right
43+
['•', '•', '•', '•'],
44+
// Left
45+
['•', '•', '•', '•'],
46+
],
47+
[
48+
// Up
49+
['│', '│', '┌', '┐'],
50+
// Down
51+
['│', '│', '└', '┘'],
52+
// Right
53+
['┘', '┐', '─', '─'],
54+
// Left
55+
['└', '┌', '─', '─'],
56+
],
57+
[
58+
// Up
59+
['│', '│', '╭', '╮'],
60+
// Down
61+
['│', '│', '╰', '╯'],
62+
// Right
63+
['╯', '╮', '─', '─'],
64+
// Left
65+
['╰', '╭', '─', '─'],
66+
],
67+
[
68+
// Up
69+
['║', '║', '╔', '╗'],
70+
// Down
71+
['║', '║', '╚', '╝'],
72+
// Right
73+
['╝', '╗', '═', '═'],
74+
// Left
75+
['╚', '╔', '═', '═'],
76+
],
77+
[
78+
// Up
79+
['┃', '┃', '┏', '┓'],
80+
// Down
81+
['┃', '┃', '┗', '┛'],
82+
// Right
83+
['┛', '┓', '━', '━'],
84+
// Left
85+
['┗', '┏', '━', '━'],
86+
],
3387
];
3488

3589
#[derive(Copy, Clone, Eq, PartialEq, Debug, Default)]
@@ -284,6 +338,9 @@ struct Config {
284338
/// The RGB option is for terminals, which support true color, i.e., all 16 million colors.
285339
#[arg(short, long, default_value_t, value_enum, verbatim_doc_comment)]
286340
palette: ColorPalette,
341+
/// Frames per second
342+
#[arg(short = 'P', long, default_value_t = 5, value_parser = 0..=5)]
343+
piece_set: i64,
287344
}
288345

289346
/// Represents the screensaver application
@@ -372,7 +429,9 @@ impl Screensaver {
372429
let piece = &mut state.pipe_piece;
373430

374431
canv.move_to(piece.pos)?;
375-
canv.put_char(PIPE_MAP[piece.prev_dir as usize][piece.dir as usize])?;
432+
canv.put_char(
433+
PIPE_MAP[cfg.piece_set as usize][piece.prev_dir as usize][piece.dir as usize],
434+
)?;
376435

377436
state.drawn_pieces += 1;
378437

@@ -397,9 +456,7 @@ impl Screensaver {
397456
if poll(Duration::from_millis(delay)).wrap_err("cannot poll events")? {
398457
match read().wrap_err("cannot read event")? {
399458
Event::Key(event) => match event.code {
400-
KeyCode::Esc | KeyCode::Char('q') | KeyCode::Char('Q') => {
401-
quit = true
402-
}
459+
KeyCode::Esc | KeyCode::Char('q') | KeyCode::Char('Q') => quit = true,
403460
KeyCode::Char(' ') => pause = !pause,
404461
_ => (),
405462
},
@@ -431,7 +488,8 @@ fn main() -> Result<()> {
431488
let mut app = Screensaver::new(canv, cfg);
432489
let r = app.run();
433490

434-
app.deinit().wrap_err("cannot restore the terminal previous state")?;
491+
app.deinit()
492+
.wrap_err("cannot restore the terminal previous state")?;
435493

436494
r
437495
}

0 commit comments

Comments
 (0)