-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.rs
More file actions
211 lines (173 loc) · 6.62 KB
/
Copy pathmain.rs
File metadata and controls
211 lines (173 loc) · 6.62 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
use std::time;
use std::thread;
use std::{io, io::Write, env};
struct Arguments{
style: String,
color: String,
alignment: String,
}
fn main()
{
let options: [&str; 10] = [
"Arch",
"Debian",
"Fedora",
"Gentoo",
"openSUSE",
"Ubuntu",
"freeBSD",
"NixOS",
"Kali",
"Mint",
];
let args: Vec<String> = env::args().collect();
let arguments = input_handling(args);
println!("There you could select multiple options:");
let choise: String = compose_menu(options, arguments);
println!("Distro: {}", choise);
print!("Downloading .iso --> [");
for _ in 1..106 {print!("·");}
print!("]1 TB/s\n");
print!("Do you wanna install and reboot now? (y/n): ");
let mut reboot: String = Default::default();
let _ = io::stdout().flush();
io::stdin()
.read_line(&mut reboot)
.expect("Failed to reboot");
if reboot == "y\n" {
println!("\nrebooting...");
}else {
println!("\nSomething was wrong, rebooting...");
}
print!("\x1B[H");
print!("\x1B[2J");
thread::sleep(time::Duration::from_secs(7));
println!("you got scared, right?");
}
fn input_handling(args: Vec<String>) -> Arguments
{
let mut style: String = Default::default();
let mut color: String = Default::default();
let mut alignment: String = Default::default();
match args.len() {
0 => panic!(), // Should be unreachable;
1 => { // program\n
println!("You missed some arguments:");
print!("Style > ");
let _ = io::stdout().flush();
io::stdin().read_line(&mut style).expect("Failed to read style!");
while style == "\n" {
println!("Not a valid answer, try again!");
io::stdin().read_line(&mut style).expect("Failed to read style!");
}
print!("Color > ");
let _ = io::stdout().flush();
io::stdin().read_line(&mut color).expect("Failed to read color!");
while style == "\n" {
println!("Not a valid answer, try again!");
io::stdin().read_line(&mut color).expect("Failed to read style!");
}
print!("Alignment > ");
let _ = io::stdout().flush();
io::stdin().read_line(&mut alignment).expect("Failed to read color!");
if alignment == "\n" {alignment = "n".to_string()} else {};
style = style.trim().parse().expect("Failed to clean input!");
color = color.trim().parse().expect("Failed to clean input!");
alignment = alignment.trim().parse().expect("Failed to clean input!");
},
2 => { // program [style]\n
println!("You didn't defined the color!");
print!("Color > ");
let _ = io::stdout().flush();
io::stdin().read_line(&mut color).expect("Failed to read color!");
while style == "\n" {
println!("Not a valid answer, try again!");
io::stdin().read_line(&mut color).expect("Failed to read style!");
}
style = args[1 as usize].trim().parse().expect("Failed to clean first argument!");
color = color.trim().parse().expect("Failed to clean input!");
alignment = "n".to_string();
},
3 => { // program [style] [color]\n
style = args[1 as usize].trim().parse().expect("Failed to clean first argument!");
color = args[2 as usize].trim().parse().expect("Failed to clean second argument!");
alignment = "n".to_string();
},
4 => {
style = args[1 as usize].trim().parse().expect("Failed to clean first argument!");
color = args[2 as usize].trim().parse().expect("Failed to clean second argument!");
alignment = args[3 as usize].trim().parse().expect("Failed to clean second argument!");
}
5.. => println!("Too much arguments!"),
}
let mut color_n: u8 =
match &color as &str {
"red" => 31, // Red
"green" => 32, // Green
"yellow" => 33, // Yellow
"blue" => 34, // Blue
"white" => 37, // White
"b-red" => 91, // Bright Red
"b-green" => 92, // Bright Green
"b-yellow" => 93, // Bright Yellow
"b-blue" => 94, // Bright Blue
"b-white" => 97, // Bright White
_other => 39, // Default
};
let mut color: String = Default::default();
match &style as &str {
"background" => {
style = " ".to_string();
if color_n == 31
|| color_n == 32
|| color_n == 33 // --> Bright colors.
|| color_n == 37
|| color_n == 91
|| color_n == 92
|| color_n == 93
|| color_n == 97
|| color_n == 39 {style += "\x1b[30m"} else {}
if color_n == 39 {color_n = 47} else {color_n += 10;}
color = color_n.to_string();
},
"foreground" => style = " ".to_string(),
"item" => style = " *\x1b[22m\x1b[39m".to_string(),
"bullet" => style = "=>\x1b[22m\x1b[39m".to_string(),
"simple" => style = " >\x1b[22m\x1b[39m".to_string(),
_other => panic!(),
};
if style != "background" {color = color_n.to_string();} else {}
return Arguments{style, color, alignment};
}
fn compose_menu(options: [&str; 10], arguments: Arguments) -> String
{
let mut line: u8 = 0;
let spacing: String = if arguments.alignment == "l" {"".to_string()} else if arguments.alignment == "r" {" ".to_string()} else {" ".to_string()};
loop{
for i in 0..10 {
if i == line {
println!("\x1b[{1}m{2}{3}{}\x1b[0m", options[i as usize], arguments.color, arguments.style, spacing);
}else{
println!(" {}", options[i as usize]);
}
}
let _ = io::stdout().flush();
let mut input: String = Default::default();
io::stdin()
.read_line(&mut input)
.expect("Failed to read input!");
if input == "\x1B[A\n" {
if line == 0 {} else {line -= 1;}
}else if input == "\x1B[B\n" {
if line == 9 {} else {line += 1};
}else if input == "\n"{
println!("You choosed this one: {}", options[line as usize]);
return options[line as usize].to_string();
}
for _i in 1..12 {
print!("");
print!("\x1B[2K\x1B[A");
}
if line == 67 {println!("{}", arguments.style);} else {}
}
}