droidtui 0.2.9

A beautiful Terminal User Interface (TUI) for Android development and ADB commands
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
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
use ratatui::{
    buffer::Buffer,
    layout::{Alignment, Rect},
    style::{Color, Style},
    widgets::{Block, BorderType, Paragraph, Widget},
};
use std::time::{Duration, Instant};

#[derive(Debug)]
pub struct EffectsManager {
    pub start_time: Instant,
    pub startup_duration: Duration,
    pub tick_count: u64,
    pub fade_in_start: Option<Instant>,
    pub fade_in_duration: Duration,
    pub slide_in_start: Option<Instant>,
    pub slide_in_duration: Duration,
    pub slide_out_start: Option<Instant>,
    pub slide_out_duration: Duration,
}

impl EffectsManager {
    pub fn new() -> Self {
        Self {
            start_time: Instant::now(),
            startup_duration: Duration::from_millis(2500),
            tick_count: 0,
            fade_in_start: None,
            fade_in_duration: Duration::from_millis(300),
            slide_in_start: None,
            slide_in_duration: Duration::from_millis(250),
            slide_out_start: None,
            slide_out_duration: Duration::from_millis(200),
        }
    }

    pub fn tick(&mut self, _elapsed: Duration) {
        self.tick_count += 1;
    }

    pub fn start_fade_in(&mut self) {
        self.fade_in_start = Some(Instant::now());
    }

    pub fn get_fade_in_progress(&self) -> f32 {
        if let Some(start) = self.fade_in_start {
            let elapsed = start.elapsed();
            if elapsed >= self.fade_in_duration {
                1.0
            } else {
                elapsed.as_millis() as f32 / self.fade_in_duration.as_millis() as f32
            }
        } else {
            1.0
        }
    }

    pub fn is_fade_in_complete(&self) -> bool {
        if let Some(start) = self.fade_in_start {
            start.elapsed() >= self.fade_in_duration
        } else {
            true
        }
    }

    pub fn is_startup_complete(&self) -> bool {
        self.start_time.elapsed() >= self.startup_duration
    }

    pub fn start_slide_in(&mut self) {
        self.slide_in_start = Some(Instant::now());
    }

    pub fn start_slide_out(&mut self) {
        self.slide_out_start = Some(Instant::now());
    }

    pub fn get_slide_in_progress(&self) -> f32 {
        if let Some(start) = self.slide_in_start {
            let elapsed = start.elapsed();
            if elapsed >= self.slide_in_duration {
                1.0
            } else {
                let progress =
                    elapsed.as_millis() as f32 / self.slide_in_duration.as_millis() as f32;
                // Ease out cubic for smooth deceleration
                1.0 - (1.0 - progress).powi(3)
            }
        } else {
            1.0
        }
    }

    pub fn get_slide_out_progress(&self) -> f32 {
        if let Some(start) = self.slide_out_start {
            let elapsed = start.elapsed();
            if elapsed >= self.slide_out_duration {
                1.0
            } else {
                let progress =
                    elapsed.as_millis() as f32 / self.slide_out_duration.as_millis() as f32;
                // Ease in cubic for smooth acceleration
                progress.powi(3)
            }
        } else {
            0.0
        }
    }

    pub fn is_slide_in_complete(&self) -> bool {
        if let Some(start) = self.slide_in_start {
            start.elapsed() >= self.slide_in_duration
        } else {
            true
        }
    }

    pub fn is_slide_out_complete(&self) -> bool {
        if let Some(start) = self.slide_out_start {
            start.elapsed() >= self.slide_out_duration
        } else {
            false
        }
    }

    pub fn reset_slide(&mut self) {
        self.slide_in_start = None;
        self.slide_out_start = None;
    }

    pub fn get_startup_progress(&self) -> f32 {
        let elapsed = self.start_time.elapsed();
        if elapsed >= self.startup_duration {
            1.0
        } else {
            elapsed.as_millis() as f32 / self.startup_duration.as_millis() as f32
        }
    }

    pub fn get_reveal_alpha(&self) -> u8 {
        let progress = self.get_startup_progress();
        (progress * 255.0) as u8
    }

    pub fn get_wave_effect(&self) -> f32 {
        let time = self.tick_count as f32 * 0.1;
        (time.sin() + 1.0) / 2.0
    }
}

impl Default for EffectsManager {
    fn default() -> Self {
        Self::new()
    }
}

// Widget for the startup reveal animation
pub struct RevealWidget<'a> {
    effects_manager: &'a mut EffectsManager,
    subtitle: &'a str,
}

impl<'a> RevealWidget<'a> {
    pub fn new(
        effects_manager: &'a mut EffectsManager,
        _title: &'a str,
        subtitle: &'a str,
    ) -> Self {
        Self {
            effects_manager,
            subtitle,
        }
    }
}

impl<'a> Widget for RevealWidget<'a> {
    fn render(self, area: Rect, buf: &mut Buffer) {
        let progress = self.effects_manager.get_startup_progress();
        let alpha = self.effects_manager.get_reveal_alpha();
        let wave = self.effects_manager.get_wave_effect();

        // Create animated gradient background
        for y in area.top()..area.bottom() {
            for x in area.left()..area.right() {
                let distance_from_center = {
                    let center_x = area.width / 2;
                    let center_y = area.height / 2;
                    let dx = (x - area.left()).abs_diff(center_x) as f32;
                    let dy = (y - area.top()).abs_diff(center_y) as f32;
                    (dx * dx + dy * dy).sqrt()
                };

                let wave_intensity = (wave * 32.0) as u8;
                let base_intensity =
                    ((1.0 - distance_from_center / (area.width as f32)) * alpha as f32) as u8;
                let final_intensity = base_intensity.saturating_add(wave_intensity);

                let color = if progress < 1.0 {
                    // Reveal animation - sweep from center
                    Color::Rgb(0, final_intensity / 4, 0)
                } else {
                    // Completed - gentle pulse
                    Color::Rgb(0, (final_intensity / 6).max(8), 0)
                };

                if let Some(cell) = buf.cell_mut((x, y)) {
                    cell.set_bg(color);
                }
            }
        }

        // ASCII Art for DroidTUI and Android logo
        let ascii_art = r#"
           ██████╗ ██████╗  ██████╗ ██╗██████╗ ████████╗██╗   ██╗██╗
           ██╔══██╗██╔══██╗██╔═══██╗██║██╔══██╗╚══██╔══╝██║   ██║██║
           ██║  ██║██████╔╝██║   ██║██║██║  ██║   ██║   ██║   ██║██║
           ██║  ██║██╔══██╗██║   ██║██║██║  ██║   ██║   ██║   ██║██║
           ██████╔╝██║  ██║╚██████╔╝██║██████╔╝   ██║   ╚██████╔╝██║
           ╚═════╝ ╚═╝  ╚═╝ ╚═════╝ ╚═╝╚═════╝    ╚═╝    ╚═════╝ ╚═╝

              🤖 Android Development Toolkit 🤖
"#;

        // Create the main content with fade-in effect
        let content = if progress < 0.3 {
            // Early phase - just show dots
            "●●●\n\nInitializing...".to_string()
        } else if progress < 0.6 {
            // Mid phase - show ASCII art
            ascii_art.to_string()
        } else if progress < 1.0 {
            // Late phase - show ASCII art with subtitle
            format!("{}\n{}", ascii_art, self.subtitle)
        } else {
            // Complete - show all with instructions
            format!(
                "{}\n{}\n\n⚡ Press any key to continue...",
                ascii_art, self.subtitle
            )
        };

        // Calculate text color based on progress
        let text_color = if progress < 1.0 {
            Color::Rgb(0, alpha, 0)
        } else {
            // Pulse effect when complete
            let pulse = ((self.effects_manager.tick_count / 20) % 2) as u8;
            if pulse == 0 {
                Color::LightGreen
            } else {
                Color::Green
            }
        };

        let block = Block::bordered()
            .title("🌟 Welcome to DroidTUI")
            .title_alignment(Alignment::Center)
            .border_type(BorderType::Rounded)
            .style(Style::default().fg(text_color));

        let paragraph = Paragraph::new(content)
            .block(block)
            .style(Style::default().fg(text_color))
            .alignment(Alignment::Center);

        // Center the content - larger area for ASCII art
        let popup_area = centered_rect(90, 85, area);
        paragraph.render(popup_area, buf);
    }
}

// Helper function to create centered rectangles
fn centered_rect(percent_x: u16, percent_y: u16, r: Rect) -> Rect {
    use ratatui::layout::{Constraint, Direction, Layout};

    let popup_layout = Layout::default()
        .direction(Direction::Vertical)
        .constraints([
            Constraint::Percentage((100 - percent_y) / 2),
            Constraint::Percentage(percent_y),
            Constraint::Percentage((100 - percent_y) / 2),
        ])
        .split(r);

    Layout::default()
        .direction(Direction::Horizontal)
        .constraints([
            Constraint::Percentage((100 - percent_x) / 2),
            Constraint::Percentage(percent_x),
            Constraint::Percentage((100 - percent_x) / 2),
        ])
        .split(popup_layout[1])[1]
}

// Menu highlight effects with consistent green color
pub fn get_selection_color(_tick_count: u64, _position: usize) -> Color {
    // Consistent green color for all selections
    Color::Green
}

// Loading animation characters
pub fn get_loading_spinner(tick_count: u64) -> &'static str {
    let spinner_chars = ["", "", "", "", "", "", "", "", "", ""];
    let index = (tick_count / 8) % spinner_chars.len() as u64;
    spinner_chars[index as usize]
}

// Loading dots animation
pub fn get_loading_dots(tick_count: u64) -> String {
    let dots_count = ((tick_count / 20) % 4) as usize;
    let dots = ".".repeat(dots_count);
    format!("Loading{:<3}", dots)
}

// Progress bar animation
pub fn get_progress_bar(tick_count: u64, width: usize) -> String {
    let progress = ((tick_count / 5) % width as u64) as usize;
    let filled = "".repeat(progress);
    let empty = "".repeat(width.saturating_sub(progress));
    format!("[{}{}]", filled, empty)
}

// Enhanced selection effect with consistent green color
pub fn get_selection_color_with_boost(_tick_count: u64, _position: usize, _boost: u64) -> Color {
    // Always return consistent green color, no boost effects for line selection
    Color::Green
}

// Orbital spinner animation (circles around)
pub fn get_orbital_spinner(tick_count: u64) -> &'static str {
    let orbital_chars = ["", "", "", ""];
    let index = (tick_count / 5) % orbital_chars.len() as u64;
    orbital_chars[index as usize]
}

// Wave animation for loading screen
pub fn get_wave_animation(tick_count: u64) -> String {
    let wave_chars = ["", "", "", "", "", "", "", ""];
    let wave_length = 15;
    let mut wave = String::new();

    for i in 0..wave_length {
        let offset = (tick_count as i32 + i * 2) % (wave_chars.len() as i32 * 2);
        let index = if offset >= wave_chars.len() as i32 {
            (wave_chars.len() as i32 * 2 - offset - 1).max(0)
        } else {
            offset
        } as usize;

        wave.push_str(wave_chars[index.min(wave_chars.len() - 1)]);
    }

    wave
}

// Circular progress indicator
pub fn get_circular_progress(tick_count: u64) -> String {
    let segments = ["", "", "", ""];
    let index = (tick_count / 3) % segments.len() as u64;
    segments[index as usize].to_string()
}

// Dots orbit animation (dots rotating in a circle)
pub fn get_dots_orbit(tick_count: u64) -> String {
    let positions = ["", "", "", "", "", "", "", "", "", ""];
    let index = (tick_count / 4) % positions.len() as u64;
    positions[index as usize].to_string()
}

// Particle effect - expanding dots
pub fn get_particle_effect(tick_count: u64) -> String {
    let cycle = (tick_count / 6) % 8;
    match cycle {
        0 => "·  ·  ·".to_string(),
        1 => " · · · ".to_string(),
        2 => "  ···  ".to_string(),
        3 => "  ███  ".to_string(),
        4 => " █████ ".to_string(),
        5 => "  ███  ".to_string(),
        6 => " · · · ".to_string(),
        _ => "·  ·  ·".to_string(),
    }
}

// Bouncing ball animation
pub fn get_bouncing_ball(tick_count: u64) -> String {
    let positions = [
        "",
        "",
        "",
        "",
        "",
        "",
        "",
        "",
    ];
    let index = (tick_count / 5) % positions.len() as u64;
    positions[index as usize].to_string()
}

// Shimmer effect for selected items
pub fn get_shimmer_intensity(tick_count: u64) -> f32 {
    let phase = (tick_count as f32 * 0.15).sin();
    (phase + 1.0) / 2.0 // Normalize to 0.0-1.0
}

// Get shimmer color for menu item highlight
pub fn get_shimmer_color(tick_count: u64, base_color: Color) -> Color {
    let intensity = get_shimmer_intensity(tick_count);
    let brightness = (200.0 + intensity * 55.0) as u8;

    match base_color {
        Color::Green => Color::Rgb(0, brightness, 0),
        Color::Yellow => Color::Rgb(brightness, brightness, 0),
        _ => base_color,
    }
}

// Slide animation easing function (ease out cubic)
pub fn ease_out_cubic(t: f32) -> f32 {
    1.0 - (1.0 - t).powi(3)
}

// Slide animation easing function (ease in cubic)
pub fn ease_in_cubic(t: f32) -> f32 {
    t.powi(3)
}

// Bounce effect for emphasis
pub fn get_bounce_offset(tick_count: u64, duration_ticks: u64) -> f32 {
    if tick_count >= duration_ticks {
        return 0.0;
    }

    let progress = tick_count as f32 / duration_ticks as f32;
    let bounce = (progress * std::f32::consts::PI * 2.0).sin() * (1.0 - progress);
    bounce * 3.0 // Scale the bounce effect
}