droidtui 0.3.1

A beautiful Terminal User Interface (TUI) for Android development and ADB commands
Documentation
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
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
// Removed unused import: get_menu_border_color
use crate::adb::{AdbCommand, PackageFilter};
use ratatui::{
    buffer::Buffer,
    layout::{Alignment, Constraint, Layout, Rect},
    style::{Color, Modifier, Style},
    text::{Line, Span},
    widgets::{Block, List, ListItem, ListState, Paragraph, Widget},
};

#[derive(Debug, Clone)]
pub struct MenuItem {
    pub label: String,
    pub description: String,
    pub command: AdbCommand,
    pub children: Vec<MenuChild>,
}

#[derive(Debug, Clone)]
pub struct MenuChild {
    pub label: String,
    pub description: String,
    pub command: AdbCommand,
}

#[derive(Debug)]
pub struct Menu {
    pub items: Vec<MenuItem>,
    pub state: ListState,
    pub selected: usize,
    pub tick_count: u64,
    pub last_selected: usize,
    pub position_change_boost: u64,
    pub in_child_mode: bool,
    pub child_selected: usize,
    pub child_state: ListState,
}

impl Default for Menu {
    fn default() -> Self {
        let items = vec![
            MenuItem {
                label: "📱 List Devices".to_string(),
                description: "Show all connected Android devices with their status".to_string(),
                command: AdbCommand::ListDevices,
                children: vec![
                    MenuChild {
                        label: "📋 List Connected Devices".to_string(),
                        description: "Show basic device list".to_string(),
                        command: AdbCommand::ListDevices,
                    },
                    MenuChild {
                        label: "📝 Detailed Device Info".to_string(),
                        description: "Show devices with detailed information".to_string(),
                        command: AdbCommand::GetDeviceState,
                    },
                    MenuChild {
                        label: "🔍 Device Serial Numbers".to_string(),
                        description: "List only device serial numbers".to_string(),
                        command: AdbCommand::GetSerialNumber,
                    },
                ],
            },
            MenuItem {
                label: "📋 List Packages".to_string(),
                description: "List all installed packages on the device".to_string(),
                command: AdbCommand::ListPackages {
                    include_path: true,
                    filter: PackageFilter::All,
                },
                children: vec![
                    MenuChild {
                        label: "📦 All Packages".to_string(),
                        description: "List all installed packages".to_string(),
                        command: AdbCommand::ListPackages {
                            include_path: false,
                            filter: PackageFilter::All,
                        },
                    },
                    MenuChild {
                        label: "📁 Packages with Paths".to_string(),
                        description: "List packages with file paths".to_string(),
                        command: AdbCommand::ListPackages {
                            include_path: true,
                            filter: PackageFilter::All,
                        },
                    },
                    MenuChild {
                        label: "👤 User Packages Only".to_string(),
                        description: "List only user-installed packages".to_string(),
                        command: AdbCommand::ListPackages {
                            include_path: false,
                            filter: PackageFilter::User,
                        },
                    },
                    MenuChild {
                        label: "⚙️ System Packages Only".to_string(),
                        description: "List only system packages".to_string(),
                        command: AdbCommand::ListPackages {
                            include_path: false,
                            filter: PackageFilter::System,
                        },
                    },
                ],
            },
            MenuItem {
                label: "🔋 Battery Info".to_string(),
                description: "Display detailed battery information".to_string(),
                command: AdbCommand::GetBatteryInfo,
                children: vec![
                    MenuChild {
                        label: "🔋 Full Battery Status".to_string(),
                        description: "Complete battery information".to_string(),
                        command: AdbCommand::GetBatteryInfo,
                    },
                    MenuChild {
                        label: "⚡ Battery Level".to_string(),
                        description: "Show just battery percentage".to_string(),
                        command: AdbCommand::Shell {
                            command: "dumpsys battery | grep level".to_string(),
                        },
                    },
                    MenuChild {
                        label: "🔌 Charging Status".to_string(),
                        description: "Show charging state".to_string(),
                        command: AdbCommand::Shell {
                            command: "dumpsys battery | grep 'AC powered\\|USB powered\\|status'"
                                .to_string(),
                        },
                    },
                ],
            },
            MenuItem {
                label: "💾 Memory Usage".to_string(),
                description: "Show memory usage statistics".to_string(),
                command: AdbCommand::GetMemoryInfo,
                children: vec![
                    MenuChild {
                        label: "📊 System Memory".to_string(),
                        description: "Overall system memory usage".to_string(),
                        command: AdbCommand::GetMemoryInfo,
                    },
                    MenuChild {
                        label: "📱 Available Memory".to_string(),
                        description: "Show available memory".to_string(),
                        command: AdbCommand::Shell {
                            command: "cat /proc/meminfo | grep -E 'MemTotal|MemFree|MemAvailable'"
                                .to_string(),
                        },
                    },
                    MenuChild {
                        label: "🔝 Top Memory Apps".to_string(),
                        description: "Apps using most memory".to_string(),
                        command: AdbCommand::Shell {
                            command: "dumpsys meminfo | grep -E '(Total|TOTAL)' | head -10"
                                .to_string(),
                        },
                    },
                ],
            },
            MenuItem {
                label: "📊 CPU Info".to_string(),
                description: "Display CPU information and usage".to_string(),
                command: AdbCommand::GetCpuInfo,
                children: vec![
                    MenuChild {
                        label: "🔧 CPU Details".to_string(),
                        description: "Detailed CPU information".to_string(),
                        command: AdbCommand::GetCpuInfo,
                    },
                    MenuChild {
                        label: "⚡ CPU Usage".to_string(),
                        description: "Top processes by CPU usage".to_string(),
                        command: AdbCommand::Shell {
                            command: "ps -eo PID,PPID,USER,COMM | head -20".to_string(),
                        },
                    },
                    MenuChild {
                        label: "📈 Load Average".to_string(),
                        description: "System load average".to_string(),
                        command: AdbCommand::Shell {
                            command: "cat /proc/loadavg".to_string(),
                        },
                    },
                ],
            },
            MenuItem {
                label: "🔗 Network Info".to_string(),
                description: "Show network connectivity information".to_string(),
                command: AdbCommand::GetNetworkInfo,
                children: vec![
                    MenuChild {
                        label: "🌐 Connectivity Status".to_string(),
                        description: "Network connectivity details".to_string(),
                        command: AdbCommand::GetNetworkInfo,
                    },
                    MenuChild {
                        label: "📶 WiFi Info".to_string(),
                        description: "WiFi connection details".to_string(),
                        command: AdbCommand::GetWifiStatus,
                    },
                    MenuChild {
                        label: "🔗 IP Configuration".to_string(),
                        description: "Network interface configuration".to_string(),
                        command: AdbCommand::Shell {
                            command: "ip addr show".to_string(),
                        },
                    },
                ],
            },
            MenuItem {
                label: "📱 Device Properties".to_string(),
                description: "Get all device system properties".to_string(),
                command: AdbCommand::GetDeviceProperties,
                children: vec![
                    MenuChild {
                        label: "📋 All Properties".to_string(),
                        description: "Show all system properties".to_string(),
                        command: AdbCommand::GetDeviceProperties,
                    },
                    MenuChild {
                        label: "🏷️ Device Model".to_string(),
                        description: "Show device model and brand".to_string(),
                        command: AdbCommand::Shell {
                            command: "getprop | grep -E 'ro.product.model|ro.product.brand|ro.product.name'".to_string(),
                        },
                    },
                    MenuChild {
                        label: "🔢 Android Version".to_string(),
                        description: "Show Android version info".to_string(),
                        command: AdbCommand::Shell {
                            command: "getprop | grep -E 'ro.build.version|ro.build.id'"
                                .to_string(),
                        },
                    },
                ],
            },
            MenuItem {
                label: "🎯 Running Processes".to_string(),
                description: "List all running processes".to_string(),
                command: AdbCommand::ListProcesses,
                children: vec![
                    MenuChild {
                        label: "📋 All Processes".to_string(),
                        description: "List all running processes".to_string(),
                        command: AdbCommand::ListProcesses,
                    },
                    MenuChild {
                        label: "🔝 Top Processes".to_string(),
                        description: "Top 20 running processes".to_string(),
                        command: AdbCommand::Shell {
                            command: "ps -A | head -20".to_string(),
                        },
                    },
                    MenuChild {
                        label: "👤 User Processes".to_string(),
                        description: "User application processes only".to_string(),
                        command: AdbCommand::Shell {
                            command: "ps -A | grep -v 'system' | grep -v 'root' | head -15"
                                .to_string(),
                        },
                    },
                    MenuChild {
                        label: "📊 Process Details".to_string(),
                        description: "Detailed process information with formatting".to_string(),
                        command: AdbCommand::Shell {
                            command: "echo 'PID    USER         COMMAND'; echo '---    ----         -------'; ps -A | awk '{printf \"%-6s %-12s %s\\n\", $2, $1, $9}' | head -20".to_string(),
                        },
                    },
                ],
            },
            MenuItem {
                label: "📊 System Services".to_string(),
                description: "List all system services status".to_string(),
                command: AdbCommand::Shell {
                    command: "service list".to_string(),
                },
                children: vec![
                    MenuChild {
                        label: "📋 All Services".to_string(),
                        description: "List all system services".to_string(),
                        command: AdbCommand::Shell {
                            command: "service list".to_string(),
                        },
                    },
                    MenuChild {
                        label: "🔧 Running Services".to_string(),
                        description: "Show only running services".to_string(),
                        command: AdbCommand::Shell {
                            command: "dumpsys activity services".to_string(),
                        },
                    },
                    MenuChild {
                        label: "📱 App Services".to_string(),
                        description: "Application services only".to_string(),
                        command: AdbCommand::Shell {
                            command: "dumpsys activity services | grep -A 5 'ServiceRecord'"
                                .to_string(),
                        },
                    },
                ],
            },
            MenuItem {
                label: "📷 Screenshot".to_string(),
                description: "Take and save device screenshots".to_string(),
                command: AdbCommand::TakeScreenshot,
                children: vec![
                    MenuChild {
                        label: "📸 Take Screenshot".to_string(),
                        description: "Take screenshot and save to device".to_string(),
                        command: AdbCommand::TakeScreenshot,
                    },
                    MenuChild {
                        label: "📐 Screen Resolution".to_string(),
                        description: "Show screen size and density".to_string(),
                        command: AdbCommand::GetScreenResolution,
                    },
                    MenuChild {
                        label: "🖼️ View Screenshot Path".to_string(),
                        description: "Show where screenshots are saved".to_string(),
                        command: AdbCommand::Shell {
                            command: "ls -la /sdcard/screenshot*.png".to_string(),
                        },
                    },
                ],
            },
            MenuItem {
                label: "🔄 Reboot Device".to_string(),
                description: "Reboot the connected device".to_string(),
                command: AdbCommand::Shell {
                    command: "reboot".to_string(),
                },
                children: vec![
                    MenuChild {
                        label: "🔄 Normal Reboot".to_string(),
                        description: "Reboot device normally".to_string(),
                        command: AdbCommand::Shell {
                            command: "reboot".to_string(),
                        },
                    },
                    MenuChild {
                        label: "⚡ Fast Reboot".to_string(),
                        description: "Fast reboot (bootloader)".to_string(),
                        command: AdbCommand::Shell {
                            command: "reboot bootloader".to_string(),
                        },
                    },
                    MenuChild {
                        label: "🔧 Recovery Mode".to_string(),
                        description: "Reboot to recovery mode".to_string(),
                        command: AdbCommand::Shell {
                            command: "reboot recovery".to_string(),
                        },
                    },
                ],
            },
            MenuItem {
                label: "📜 System Log".to_string(),
                description: "View recent system logs (last 100 lines)".to_string(),
                command: AdbCommand::GetSystemLog { lines: 100 },
                children: vec![
                    MenuChild {
                        label: "📜 Recent Logs".to_string(),
                        description: "Last 100 log entries".to_string(),
                        command: AdbCommand::GetSystemLog { lines: 100 },
                    },
                    MenuChild {
                        label: "🚨 Error Logs Only".to_string(),
                        description: "Show only error messages".to_string(),
                        command: AdbCommand::Shell {
                            command: "logcat -d *:E".to_string(),
                        },
                    },
                    MenuChild {
                        label: "⚠️ Warning and Error".to_string(),
                        description: "Show warnings and errors".to_string(),
                        command: AdbCommand::Shell {
                            command: "logcat -d *:W".to_string(),
                        },
                    },
                    MenuChild {
                        label: "🔄 Clear Logs".to_string(),
                        description: "Clear the log buffer".to_string(),
                        command: AdbCommand::Shell {
                            command: "logcat -c".to_string(),
                        },
                    },
                ],
            },
            MenuItem {
                label: "🔍 ADB Version".to_string(),
                description: "Display ADB version information".to_string(),
                command: AdbCommand::GetAdbVersion,
                children: vec![
                    MenuChild {
                        label: "🔍 ADB Version".to_string(),
                        description: "Show ADB version".to_string(),
                        command: AdbCommand::GetAdbVersion,
                    },
                    MenuChild {
                        label: "📋 Server Status".to_string(),
                        description: "Check ADB server status".to_string(),
                        command: AdbCommand::ListDevices,
                    },
                ],
            },
            MenuItem {
                label: "📺 Screen Stream".to_string(),
                description: "Stream device screen in separate window (like scrcpy)".to_string(),
                command: AdbCommand::Shell {
                    command: "STREAM".to_string(),
                },
                children: vec![
                    MenuChild {
                        label: "📺 Start Screen Stream".to_string(),
                        description: "Stream device screen in window (1080x1920, 8Mbps)".to_string(),
                        command: AdbCommand::Shell {
                            command: "STREAM".to_string(),
                        },
                    },
                    MenuChild {
                        label: "🔍 High Quality Stream".to_string(),
                        description: "Higher quality stream (1080x1920, 12Mbps)".to_string(),
                        command: AdbCommand::Shell {
                            command: "STREAM_HD".to_string(),
                        },
                    },
                    MenuChild {
                        label: "⚡ Fast Stream".to_string(),
                        description: "Lower resolution for speed (720x1280, 4Mbps)".to_string(),
                        command: AdbCommand::Shell {
                            command: "STREAM_FAST".to_string(),
                        },
                    },
                ],
            },
        ];

        let mut state = ListState::default();
        state.select(Some(0));

        let mut child_state = ListState::default();
        child_state.select(Some(0));

        Self {
            items,
            state,
            selected: 0,
            tick_count: 0,
            last_selected: 0,
            position_change_boost: 0,
            in_child_mode: false,
            child_selected: 0,
            child_state,
        }
    }
}

impl Menu {
    pub fn new() -> Self {
        Self::default()
    }

    pub fn tick(&mut self) {
        self.tick_count = self.tick_count.wrapping_add(1);
    }

    pub fn next(&mut self) {
        let prev = self.selected;

        if self.in_child_mode {
            let child_count = self.items[self.selected].children.len();
            if self.child_selected < child_count - 1 {
                self.child_selected += 1;
                self.child_state.select(Some(self.child_selected));
            }
        } else if self.selected < self.items.len() - 1 {
            self.selected += 1;
            self.state.select(Some(self.selected));
        }

        // Track movement for effects
        if prev != self.selected {
            self.position_change_boost = 30;
            self.last_selected = prev;
        }
    }

    pub fn previous(&mut self) {
        let prev = self.selected;

        if self.in_child_mode {
            if self.child_selected > 0 {
                self.child_selected -= 1;
                self.child_state.select(Some(self.child_selected));
            }
        } else if self.selected > 0 {
            self.selected -= 1;
            self.state.select(Some(self.selected));
        }

        // Track movement for effects
        if prev != self.selected {
            self.position_change_boost = 30;
            self.last_selected = prev;
        }
    }

    pub fn get_selected_item(&self) -> &MenuItem {
        &self.items[self.selected]
    }

    pub fn get_selected_command(&self) -> AdbCommand {
        if self.in_child_mode && !self.items[self.selected].children.is_empty() {
            self.items[self.selected].children[self.child_selected]
                .command
                .clone()
        } else {
            self.items[self.selected].command.clone()
        }
    }

    pub fn enter_child_mode(&mut self) {
        if !self.items[self.selected].children.is_empty() {
            self.in_child_mode = true;
            self.child_selected = 0;
            self.child_state.select(Some(0));
        }
    }

    pub fn trigger_fade_in(&mut self) {
        self.position_change_boost = 60;
    }

    pub fn exit_child_mode(&mut self) {
        if self.in_child_mode {
            self.in_child_mode = false;
            self.child_selected = 0;
        }
    }

    pub fn is_in_child_mode(&self) -> bool {
        self.in_child_mode
    }
}

impl Widget for &Menu {
    fn render(self, area: Rect, buf: &mut Buffer) {
        // Create border block
        let block = Block::default()
            .borders(ratatui::widgets::Borders::ALL)
            .border_style(Style::default().fg(Color::Rgb(61, 220, 132)))
            .title(" ADB Commands ");

        let inner = block.inner(area);
        block.render(area, buf);

        if self.in_child_mode {
            // Render child menu
            let selected_item = &self.items[self.selected];

            // Split area for parent indicator and child menu
            let chunks = Layout::default()
                .direction(ratatui::layout::Direction::Vertical)
                .constraints([Constraint::Length(3), Constraint::Min(0)])
                .split(inner);

            // Render parent item indicator
            let parent_text = format!("{} (Press Backspace to return)", selected_item.label);
            let parent_para = Paragraph::new(parent_text)
                .style(
                    Style::default()
                        .fg(Color::Rgb(61, 220, 132))
                        .add_modifier(Modifier::BOLD),
                )
                .alignment(Alignment::Left);
            parent_para.render(chunks[0], buf);

            // Render child items
            let child_items: Vec<ListItem> = selected_item
                .children
                .iter()
                .enumerate()
                .map(|(idx, child)| {
                    let is_selected = idx == self.child_selected;
                    let style = if is_selected {
                        Style::default()
                            .fg(Color::Black)
                            .bg(Color::Rgb(61, 220, 132))
                            .add_modifier(Modifier::BOLD)
                    } else {
                        Style::default().fg(Color::White)
                    };

                    let content =
                        Line::from(vec![Span::raw("  "), Span::styled(&child.label, style)]);

                    ListItem::new(content)
                })
                .collect();

            let child_list = List::new(child_items);
            child_list.render(chunks[1], buf);

            // Render description at bottom
            if !selected_item.children.is_empty() {
                let selected_child = &selected_item.children[self.child_selected];
                let desc_area = Rect {
                    x: inner.x,
                    y: inner.y + inner.height.saturating_sub(3),
                    width: inner.width,
                    height: 3,
                };

                let desc_text = format!("  {}", selected_child.description);
                let desc_para = Paragraph::new(desc_text)
                    .style(Style::default().fg(Color::Gray))
                    .alignment(Alignment::Left);
                desc_para.render(desc_area, buf);
            }
        } else {
            // Render main menu
            let items: Vec<ListItem> = self
                .items
                .iter()
                .enumerate()
                .map(|(idx, item)| {
                    let is_selected = idx == self.selected;
                    let style = if is_selected {
                        Style::default()
                            .fg(Color::Black)
                            .bg(Color::Rgb(61, 220, 132))
                            .add_modifier(Modifier::BOLD)
                    } else {
                        Style::default().fg(Color::White)
                    };

                    let content = Line::from(vec![
                        Span::raw("  "),
                        Span::styled(&item.label, style),
                        if !item.children.is_empty() {
                            Span::raw("")
                        } else {
                            Span::raw("")
                        },
                    ]);

                    ListItem::new(content)
                })
                .collect();

            let list = List::new(items);
            list.render(inner, buf);

            // Render description at bottom
            let selected_item = &self.items[self.selected];
            let desc_area = Rect {
                x: inner.x,
                y: inner.y + inner.height.saturating_sub(3),
                width: inner.width,
                height: 3,
            };

            let desc_text = format!("  {}", selected_item.description);
            let desc_para = Paragraph::new(desc_text)
                .style(Style::default().fg(Color::Gray))
                .alignment(Alignment::Left);
            desc_para.render(desc_area, buf);
        }
    }
}