Initial commit

This commit is contained in:
missing 2022-05-02 15:38:39 -05:00
parent 91320cb385
commit 500546048b
4 changed files with 300 additions and 0 deletions

136
Cargo.lock generated Normal file
View file

@ -0,0 +1,136 @@
# This file is automatically @generated by Cargo.
# It is not intended for manual editing.
version = 3
[[package]]
name = "bitflags"
version = "1.3.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "bef38d45163c2f1dde094a7dfd33ccf595c92905c8f8f4fdc18d06fb1037718a"
[[package]]
name = "car"
version = "0.1.0"
dependencies = [
"ctrlc",
"pancurses",
]
[[package]]
name = "cc"
version = "1.0.73"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "2fff2a6927b3bb87f9595d67196a70493f627687a71d87a0d692242c33f58c11"
[[package]]
name = "cfg-if"
version = "1.0.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "baf1de4339761588bc0619e3cbc0120ee582ebb74b53b4efbf79117bd2da40fd"
[[package]]
name = "ctrlc"
version = "3.2.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "b37feaa84e6861e00a1f5e5aa8da3ee56d605c9992d33e082786754828e20865"
dependencies = [
"nix",
"winapi",
]
[[package]]
name = "libc"
version = "0.2.125"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "5916d2ae698f6de9bfb891ad7a8d65c09d232dc58cc4ac433c7da3b2fd84bc2b"
[[package]]
name = "log"
version = "0.4.16"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "6389c490849ff5bc16be905ae24bc913a9c8892e19b2341dbc175e14c341c2b8"
dependencies = [
"cfg-if",
]
[[package]]
name = "ncurses"
version = "5.101.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "5e2c5d34d72657dc4b638a1c25d40aae81e4f1c699062f72f467237920752032"
dependencies = [
"cc",
"libc",
"pkg-config",
]
[[package]]
name = "nix"
version = "0.24.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "8f17df307904acd05aa8e32e97bb20f2a0df1728bbc2d771ae8f9a90463441e9"
dependencies = [
"bitflags",
"cfg-if",
"libc",
]
[[package]]
name = "pancurses"
version = "0.17.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "0352975c36cbacb9ee99bfb709b9db818bed43af57751797f8633649759d13db"
dependencies = [
"libc",
"log",
"ncurses",
"pdcurses-sys",
"winreg",
]
[[package]]
name = "pdcurses-sys"
version = "0.7.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "084dd22796ff60f1225d4eb6329f33afaf4c85419d51d440ab6b8c6f4529166b"
dependencies = [
"cc",
"libc",
]
[[package]]
name = "pkg-config"
version = "0.3.25"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "1df8c4ec4b0627e53bdf214615ad287367e482558cf84b109250b37464dc03ae"
[[package]]
name = "winapi"
version = "0.3.9"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "5c839a674fcd7a98952e593242ea400abe93992746761e38641405d28b00f419"
dependencies = [
"winapi-i686-pc-windows-gnu",
"winapi-x86_64-pc-windows-gnu",
]
[[package]]
name = "winapi-i686-pc-windows-gnu"
version = "0.4.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "ac3b87c63620426dd9b991e5ce0329eff545bccbbb34f3be09ff6fb6ab51b7b6"
[[package]]
name = "winapi-x86_64-pc-windows-gnu"
version = "0.4.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "712e227841d057c1ee1cd2fb22fa7e5a5461ae8e48fa2ca79ec42cfc1931183f"
[[package]]
name = "winreg"
version = "0.5.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "a27a759395c1195c4cc5cda607ef6f8f6498f64e78f7900f5de0a127a424704a"
dependencies = [
"winapi",
]

10
Cargo.toml Normal file
View file

@ -0,0 +1,10 @@
[package]
name = "car"
version = "0.1.0"
edition = "2021"
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
[dependencies]
ctrlc = "3.2.2"
pancurses = "0.17.0"

87
src/car.txt Normal file
View file

@ -0,0 +1,87 @@
__
_------------------"-----...__
_="_=" / / / \ \ "-_ \
_="_=" O / / | \o/ _\" "-_\.,
___....-----""""| /____/|__| | |___|_.-" | _|
/_." _______ | -- | -- _/_____ |_|
| // | \\ | | // | \\ |
| ||"-_|_-"|| | | ||"-_|_-"|| |
\___|| / \ ||__|_____________|_________|| / \ ||____/
\/___\/ \/___\/
__
_------------------"-----...__
_="_=" / / / \ \ "-_ \
_="_=" O / / | \o/ _\" "-_\.,
___....-----""""| /____/|__| | |___|_.-" | _|
/_." _______ | -- | -- _/_____ |_|
| // \ \\ | | // \ \\ |
| ||--_|--"|| | | ||--_|--"|| |
\___|| / \ ||__|_____________|_________|| / \ ||____/
\_|__\/ \_|__\/
__
_------------------"-----...__
_="_=" / / / \ \ "-_ \
_="_=" O / / | \o/ _\" "-_\.,
___....-----""""| /____/|__| | |___|_.-" | _|
/_." _______ | -- | -- _/_____ |_|
| // \ \\ | | // \ \\ |
| || _\-"`|| | | || _\-"`|| |
\___||-" /\__||__|_____________|_________||-" /\__||____/
\_/___/ \_/___/
__
_------------------"-----...__
_="_=" / / / \ \ "-_ \
_="_=" O / / | \o/ _\" "-_\.,
___....-----""""| /____/|__| | |___|_.-" | _|
/_." _______ | -- | -- _/_____ |_|
| // | /\\ | | // | /\\ |
| || \_" || | | || \_" || |
\___||_-"/-__||__|_____________|_________||_-"/-__||____/
\__|__/ \__|__/
__
_------------------"-----...__
_="_=" / / / \ \ "-_ \
_="_=" O / / | \o/ _\" "-_\.,
___....-----""""| /____/|__| | |___|_.-" | _|
/_." _______ | -- | -- _/_____ |_|
| //\ /\\ | | //\ /\\ |
| || \ / || | | || \ / || |
\___||_-"|"-_||__|_____________|_________||_-"|"-_||____/
\__|__/ \__|__/
__
_------------------"-----...__
_="_=" / / / \ \ "-_ \
_="_=" O / / | \o/ _\" "-_\.,
___....-----""""| /____/|__| | |___|_.-" | _|
/_." _______ | -- | -- _/_____ |_|
| //_ | \\ | | //_ | \\ |
| || "_/ || | | || "_/ || |
\___||_--|"--||__|_____________|_________||_--|"--||____/
\__\__/ \__\__/
__
_------------------"-----...__
_="_=" / / / \ \ "-_ \
_="_=" O / / | \o/ _\" "-_\.,
___....-----""""| /____/|__| | |___|_.-" | _|
/_." _______ | -- | -- _/_____ |_|
| // / \\ | | // / \\ |
| ||`"-/_ || | | ||`"-/_ || |
\___||__/\ "-||__|_____________|_________||__/\ "-||____/
\___\_/ \___\_/
__
_------------------"-----...__
_="_=" / / / \ \ "-_ \
_="_=" O / / | \o/ _\" "-_\.,
___....-----""""| /____/|__| | |___|_.-" | _|
/_." _______ | -- | -- _/_____ |_|
| // | \\ | | // | \\ |
| ||""-/_-"|| | | ||""-/_-"|| |
\___|| _"\ ||__|_____________|_________|| _"\ ||____/
\/__|_/ \/__|_/

67
src/main.rs Normal file
View file

@ -0,0 +1,67 @@
use std::{time::{Instant, Duration}, fmt::format, thread};
use pancurses::{initscr, noecho, curs_set, cbreak, Input, endwin, Window};
const DATA: &str = include_str!("car.txt");
const EXTRA: i32 = 5;
fn main() {
// want it to keep running even if this fails
let _ = ctrlc::set_handler(||());
let longest_line = DATA.lines().map(<str>::len).max().unwrap_or_default();
let mut data = DATA.split("\n\n").cycle();
let window = initscr();
noecho();
curs_set(0);
cbreak();
window.nodelay(true);
let mut x = window.get_max_x() + EXTRA;
let base_y = window.get_max_y() / 2;
let mut next_tick = Instant::now();
for frame in data {
next_tick += Duration::from_millis(50);
x -= 1;
if x < -(longest_line as i32 + EXTRA) {
break;
}
window.clear();
print(&window, base_y - frame.lines().count() as i32 / 2, x, frame);
window.refresh();
thread::sleep(next_tick - Instant::now());
}
endwin();
}
/// prints to the window, multiline works, cutoff at the edge works
///
/// assumes 1 bytes chars
fn print<T: AsRef<str>>(window: &Window, mut y: i32, x: i32, data: T) {
let data = data.as_ref();
let cols = window.get_max_x();
for line in data.lines() {
if x < 0 { // off the left edge
window.mvprintw(y, 0, &line.get(-x as usize..).unwrap_or(""));
} else if x > cols {
// extra case to prevent subtraction with overflow below
} else if x + line.len() as i32 > cols { // off the right edge
window.mvprintw(y, x, &line[..cols as usize - x as usize]);
} else { // normal
window.mvprintw(y, x, line);
}
y += 1;
}
}