-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathgreeting_script.rs
More file actions
109 lines (93 loc) ยท 4.58 KB
/
greeting_script.rs
File metadata and controls
109 lines (93 loc) ยท 4.58 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
use crate::kits::Kit;
use tauri::AppHandle;
/// Simple greeting script that takes user input and shows personalized output
#[tauri::command]
pub async fn greeting_script(app_handle: AppHandle) -> Result<String, String> {
println!("๐ฃ greeting_script: Function called");
let mut kit = Kit::new(app_handle);
// Welcome message
println!("๐ฃ greeting_script: Showing welcome message");
kit.show_message("Welcome", "Welcome to the Greeting Script!")?;
// Get user's name
println!("๐ฃ greeting_script: Asking for name");
let name = kit.ask_input("What's your name?").await?;
println!("๐ฃ greeting_script: Received name: {}", name);
// Get user's age
println!("๐ฃ greeting_script: Asking for age");
let age = kit.ask_number("How old are you?").await?;
println!("๐ฃ greeting_script: Received age: {}", age);
// Ask for favorite hobby
println!("๐ฃ greeting_script: Asking for hobby");
let hobby = kit.ask_select(
"What's your favorite hobby?",
vec!["Reading", "Gaming", "Sports", "Music", "Cooking", "Travel"]
).await?;
println!("๐ฃ greeting_script: Received hobby: {}", hobby);
// Ask for favorite time of day
let time_of_day = kit.ask_select(
"When do you feel most productive?",
vec!["Morning", "Afternoon", "Evening", "Night"]
).await?;
// Generate personalized message based on inputs
let age_group = if age < 18.0 {
"young explorer"
} else if age < 30.0 {
"energetic individual"
} else if age < 50.0 {
"experienced person"
} else {
"wise soul"
};
let hobby_message = match hobby.as_str() {
"Reading" => "Books open up new worlds! ๐",
"Gaming" => "Games are a great way to unwind! ๐ฎ",
"Sports" => "Staying active keeps the mind sharp! โฝ",
"Music" => "Music is the language of the soul! ๐ต",
"Cooking" => "Creating delicious meals is an art! ๐จโ๐ณ",
"Travel" => "Exploring new places broadens horizons! โ๏ธ",
_ => "That's an interesting hobby! ๐"
};
let time_message = match time_of_day.as_str() {
"Morning" => "Early birds catch the worm! ๐
",
"Afternoon" => "Midday energy is powerful! โ๏ธ",
"Evening" => "Sunset vibes are peaceful! ๐",
"Night" => "Night owls have their own magic! ๐",
_ => "Every time has its charm! โฐ"
};
// Create personalized HTML output
let output_html = format!(
r#"
<div style="text-align: center; padding: 2rem; background: linear-gradient(135deg, #667eea 0%, #764ba2 100%); border-radius: 15px; color: white;">
<h1>๐ Hello, {}! ๐</h1>
<div style="background: rgba(255,255,255,0.1); padding: 1.5rem; border-radius: 10px; margin: 1rem 0;">
<h2>Your Personal Profile</h2>
<p style="font-size: 1.2rem;"><strong>Name:</strong> {}</p>
<p style="font-size: 1.2rem;"><strong>Age:</strong> {} years old ({} โจ)</p>
<p style="font-size: 1.2rem;"><strong>Favorite Hobby:</strong> {}</p>
<p style="font-size: 1.2rem;"><strong>Most Productive Time:</strong> {}</p>
</div>
<div style="background: rgba(255,255,255,0.1); padding: 1.5rem; border-radius: 10px; margin: 1rem 0;">
<h3>๐ Personalized Messages ๐</h3>
<p style="font-size: 1.1rem; margin: 0.5rem 0;">{}</p>
<p style="font-size: 1.1rem; margin: 0.5rem 0;">{}</p>
</div>
<div style="margin-top: 2rem; font-size: 1.1rem;">
<p>๐ฏ <strong>Remember:</strong> You're amazing just the way you are!</p>
<p>๐ซ Keep pursuing your passions and have a wonderful day!</p>
</div>
</div>
"#,
name, name, age as i32, age_group, hobby, time_of_day, hobby_message, time_message
);
// Show the personalized output
kit.render_html("Your Personalized Greeting", &output_html).await?;
// Ask if they want to save this information
let save_info = kit.confirm("Would you like to save this greeting for later?").await?;
if save_info {
kit.show_message("Saved!", "Your personalized greeting has been saved! ๐พ").await?;
Ok(format!("Greeting created and saved for {} (age: {}, hobby: {})", name, age as i32, hobby))
} else {
kit.show_message("Thanks!", "Thanks for using the Greeting Script! ๐").await?;
Ok(format!("Greeting created for {} (age: {}, hobby: {})", name, age as i32, hobby))
}
}