@@ -3,6 +3,7 @@ mod filter;
3
3
mod float;
4
4
mod floating_text;
5
5
mod hint;
6
+ mod root;
6
7
mod running_command;
7
8
pub mod state;
8
9
mod theme;
@@ -15,18 +16,12 @@ use std::{
15
16
use crate :: theme:: Theme ;
16
17
use clap:: Parser ;
17
18
use crossterm:: {
18
- event:: { self , DisableMouseCapture , Event , KeyCode , KeyEvent , KeyEventKind } ,
19
+ event:: { self , DisableMouseCapture , Event , KeyEventKind } ,
19
20
style:: ResetColor ,
20
21
terminal:: { disable_raw_mode, enable_raw_mode, EnterAlternateScreen , LeaveAlternateScreen } ,
21
22
ExecutableCommand ,
22
23
} ;
23
- use ratatui:: {
24
- backend:: CrosstermBackend ,
25
- layout:: { Alignment , Constraint , Layout } ,
26
- style:: Stylize ,
27
- widgets:: { Paragraph , Wrap } ,
28
- Terminal ,
29
- } ;
24
+ use ratatui:: { backend:: CrosstermBackend , Terminal } ;
30
25
use state:: AppState ;
31
26
32
27
// Linux utility toolbox
@@ -67,67 +62,8 @@ fn run(
67
62
terminal : & mut Terminal < CrosstermBackend < io:: Stdout > > ,
68
63
state : & mut AppState ,
69
64
) -> io:: Result < ( ) > {
70
- if sudo:: check ( ) == sudo:: RunningAs :: Root {
71
- terminal. draw ( |frame| {
72
- let root_warn = Paragraph :: new (
73
- r#"
74
- !!!!!!!!!!!!!! YOU ARE ABOUT TO RUN LINUTIL AS ROOT !!!!!!!!!!!!!!
75
-
76
- This utility prioritizes compatibility with non-root environments.
77
- Some scripts may work without any issues, some may not.
78
- You have been warned!
79
-
80
- !!!!!!!!!!!!!!!!!!!!!! PROCEED WITH CAUTION !!!!!!!!!!!!!!!!!!!!!!
81
-
82
- Press [y] to continue, [n] to abort
83
- "# ,
84
- )
85
- . on_black ( )
86
- . white ( )
87
- . alignment ( Alignment :: Center )
88
- . wrap ( Wrap { trim : true } ) ;
89
-
90
- let rects = Layout :: vertical ( [
91
- Constraint :: Fill ( 1 ) ,
92
- Constraint :: Length ( 10 ) ,
93
- Constraint :: Fill ( 1 ) ,
94
- ] )
95
- . split ( frame. area ( ) ) ;
96
-
97
- let centered = rects[ 1 ] ;
98
-
99
- frame. render_widget ( root_warn, centered) ;
100
- } ) ?;
101
-
102
- loop {
103
- match event:: read ( ) ? {
104
- Event :: Key (
105
- KeyEvent {
106
- code : KeyCode :: Char ( 'y' ) ,
107
- ..
108
- }
109
- | KeyEvent {
110
- code : KeyCode :: Char ( 'Y' ) ,
111
- ..
112
- } ,
113
- ) => {
114
- break ;
115
- }
116
- Event :: Key (
117
- KeyEvent {
118
- code : KeyCode :: Char ( 'n' ) ,
119
- ..
120
- }
121
- | KeyEvent {
122
- code : KeyCode :: Char ( 'N' ) ,
123
- ..
124
- } ,
125
- ) => {
126
- return Ok ( ( ) ) ;
127
- }
128
- _ => { }
129
- }
130
- }
65
+ if !root:: check_root ( terminal) ? {
66
+ return Ok ( ( ) ) ;
131
67
}
132
68
133
69
loop {
0 commit comments