1
- use std:: fmt:: Display ;
1
+ use std:: { env , fmt:: Display } ;
2
2
3
3
use bevy:: app:: App ;
4
4
use clap:: { Parser , Subcommand } ;
@@ -9,62 +9,52 @@ use ttysvr::{AppPlugin, SaverVariant};
9
9
#[ command( propagate_version = true ) ]
10
10
struct Cli {
11
11
#[ command( subcommand) ]
12
- subcommand : Subcommands ,
13
- }
12
+ variant : Variant ,
14
13
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 > ,
22
16
}
23
17
24
- #[ derive( Clone , Subcommand ) ]
18
+ #[ derive( Subcommand ) ]
25
19
pub enum Variant {
26
20
Maze ,
27
21
Pipes ,
22
+ Shuffle ,
28
23
}
29
24
30
25
impl Display for Variant {
31
26
fn fmt ( & self , f : & mut std:: fmt:: Formatter < ' _ > ) -> std:: fmt:: Result {
32
27
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" ) ,
35
31
}
36
32
}
37
33
}
38
34
39
35
fn main ( ) {
40
- let Cli { subcommand } = Cli :: parse ( ) ;
36
+ let Cli { variant , init } = Cli :: parse ( ) ;
41
37
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
+ } ;
48
43
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 ! (
54
49
"
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}`
66
54
"
67
- ) ;
68
- }
69
- }
55
+ ) ;
56
+ return ;
57
+ } ;
58
+
59
+ App :: new ( ) . add_plugins ( AppPlugin ( saver_variant) ) . run ( ) ;
70
60
}
0 commit comments