Skip to content

Commit a1089b5

Browse files
committed
replace zshrc strat with eval
1 parent 3be3a30 commit a1089b5

File tree

2 files changed

+47
-47
lines changed

2 files changed

+47
-47
lines changed

src/main.rs

+29-39
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
use std::fmt::Display;
1+
use std::{env, fmt::Display};
22

33
use bevy::app::App;
44
use clap::{Parser, Subcommand};
@@ -9,62 +9,52 @@ use ttysvr::{AppPlugin, SaverVariant};
99
#[command(propagate_version = true)]
1010
struct Cli {
1111
#[command(subcommand)]
12-
subcommand: Subcommands,
13-
}
12+
variant: Variant,
1413

15-
#[derive(Subcommand)]
16-
pub enum Subcommands {
17-
Run {
18-
#[command(subcommand)]
19-
variant: Variant,
20-
},
21-
Init,
14+
#[arg(short, long, global = true, name = "DELAY")]
15+
init: Option<u32>,
2216
}
2317

24-
#[derive(Clone, Subcommand)]
18+
#[derive(Subcommand)]
2519
pub enum Variant {
2620
Maze,
2721
Pipes,
22+
Shuffle,
2823
}
2924

3025
impl Display for Variant {
3126
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
3227
match self {
33-
Variant::Maze { .. } => write!(f, "maze"),
34-
Variant::Pipes { .. } => write!(f, "pipes"),
28+
Variant::Maze => write!(f, "maze"),
29+
Variant::Pipes => write!(f, "pipes"),
30+
Variant::Shuffle => write!(f, "shuffle"),
3531
}
3632
}
3733
}
3834

3935
fn main() {
40-
let Cli { subcommand } = Cli::parse();
36+
let Cli { variant, init } = Cli::parse();
4137

42-
match subcommand {
43-
Subcommands::Run { variant } => {
44-
let saver_variant = match variant {
45-
Variant::Maze => SaverVariant::Maze,
46-
Variant::Pipes => SaverVariant::Pipes,
47-
};
38+
let saver_variant = match variant {
39+
Variant::Maze => SaverVariant::Maze,
40+
Variant::Pipes => SaverVariant::Pipes,
41+
Variant::Shuffle => rand::random(),
42+
};
4843

49-
App::new().add_plugins(AppPlugin(saver_variant)).run();
50-
}
51-
Subcommands::Init => {
52-
#[rustfmt::skip]
53-
println!(
44+
if let Some(delay) = init {
45+
let executable = env::args().next().unwrap_or("ttysvr".into());
46+
47+
#[rustfmt::skip]
48+
println!(
5449
"
55-
# ttysvr
56-
#
57-
# Append this command's output to .zshrc
58-
# e.g. `ttysaver init >> ~/.zshrc && source ~/.zshrc`
59-
#
60-
# call with `svr [variant] [seconds]`
61-
# e.g. `svr maze 1000` for maze screensaver after 1000 seconds.
62-
#
63-
svr() {{ TMOUT=$2; trap \"cargo run -- run $1; zle reset-prompt\" ALRM }}
64-
svr_off() {{ TMOUT=0 }}
65-
# ttysvr end
50+
TMOUT={delay}; trap \"{executable} {variant}; zle reset-prompt\" ALRM
51+
52+
# WRAP THIS COMMAND IN EVAL WITH BACKTICKS (ZSH ONLY)
53+
# EXAMPLE: eval `ttysvr {variant} --init {delay}`
6654
"
67-
);
68-
}
69-
}
55+
);
56+
return;
57+
};
58+
59+
App::new().add_plugins(AppPlugin(saver_variant)).run();
7060
}

src/maze.rs

+18-8
Original file line numberDiff line numberDiff line change
@@ -11,18 +11,28 @@ fn maze_setup_system(
1111
mut meshes: ResMut<Assets<Mesh>>,
1212
mut materials: ResMut<Assets<StandardMaterial>>,
1313
) {
14-
commands.spawn(Camera3dBundle {
15-
camera: Camera {
16-
target: ratatui_render.target("main").unwrap_or_default(),
14+
commands
15+
.spawn(Camera3dBundle {
16+
camera: Camera {
17+
target: ratatui_render.target("main").unwrap_or_default(),
18+
..default()
19+
},
20+
transform: Transform::from_xyz(0., 5., 0.).looking_at(Vec3::ZERO, Vec3::Y),
1721
..default()
18-
},
19-
transform: Transform::from_xyz(0., 5., 0.).looking_at(Vec3::ZERO, Vec3::Y),
20-
..default()
21-
});
22+
})
23+
.with_children(|commands| {
24+
commands.spawn(PointLightBundle {
25+
point_light: PointLight {
26+
intensity: 100_000.,
27+
..default()
28+
},
29+
..default()
30+
});
31+
});
2232

2333
commands.spawn(PbrBundle {
2434
mesh: meshes.add(Cuboid::from_size(Vec3::splat(1.))),
25-
material: materials.add(StandardMaterial::from_color(Color::hsl(220., 0.8, 0.5))),
35+
material: materials.add(StandardMaterial::from_color(Color::hsl(0., 0.5, 0.5))),
2636
..default()
2737
});
2838
}

0 commit comments

Comments
 (0)