@@ -3,10 +3,7 @@ use tuirealm::{
33 Component , Event , Frame , MockComponent , State ,
44 command:: { Cmd , CmdResult , Direction , Position } ,
55 event:: { Key , KeyEvent } ,
6- props:: {
7- Alignment , AttrValue , Attribute , BorderType , Borders , Color , InputType , Layout , Props ,
8- Style ,
9- } ,
6+ props:: { Alignment , AttrValue , Attribute , BorderType , Borders , Color , InputType , Layout , Props , Style } ,
107 ratatui:: {
118 layout:: { Constraint , Direction as LayoutDirection , Rect } ,
129 widgets:: Block ,
@@ -38,15 +35,9 @@ impl LoginPopup {
3835 client_secret_input : Box :: new ( ClientSecretInput :: default ( ) ) ,
3936 active_input : ActiveInput :: ClientId ,
4037 } ;
38+ popup. client_id_input . attr ( Attribute :: Focus , AttrValue :: Flag ( true ) ) ;
4139 popup
42- . client_id_input
43- . attr ( Attribute :: Focus , AttrValue :: Flag ( true ) ) ;
44- popup
45- . borders (
46- Borders :: default ( )
47- . modifiers ( BorderType :: Thick )
48- . color ( Color :: Green ) ,
49- )
40+ . borders ( Borders :: default ( ) . modifiers ( BorderType :: Thick ) . color ( Color :: Green ) )
5041 . title ( "Login" , Alignment :: Left )
5142 . layout (
5243 Layout :: default ( )
@@ -86,17 +77,13 @@ impl LoginPopup {
8677 pub fn focus_next ( & mut self ) {
8778 self . active_input = match self . active_input {
8879 ActiveInput :: ClientId => {
89- self . client_id_input
90- . attr ( Attribute :: Focus , AttrValue :: Flag ( false ) ) ;
91- self . client_secret_input
92- . attr ( Attribute :: Focus , AttrValue :: Flag ( true ) ) ;
80+ self . client_id_input . attr ( Attribute :: Focus , AttrValue :: Flag ( false ) ) ;
81+ self . client_secret_input . attr ( Attribute :: Focus , AttrValue :: Flag ( true ) ) ;
9382 ActiveInput :: ClientSecret
9483 }
9584 ActiveInput :: ClientSecret => {
96- self . client_secret_input
97- . attr ( Attribute :: Focus , AttrValue :: Flag ( false ) ) ;
98- self . client_id_input
99- . attr ( Attribute :: Focus , AttrValue :: Flag ( true ) ) ;
85+ self . client_secret_input . attr ( Attribute :: Focus , AttrValue :: Flag ( false ) ) ;
86+ self . client_id_input . attr ( Attribute :: Focus , AttrValue :: Flag ( true ) ) ;
10087 ActiveInput :: ClientId
10188 }
10289 } ;
@@ -158,47 +145,26 @@ impl MockComponent for LoginPopup {
158145impl Component < Msg , UserEvent > for LoginPopup {
159146 fn on ( & mut self , ev : tuirealm:: Event < UserEvent > ) -> Option < Msg > {
160147 let _ = match ev {
148+ Event :: Keyboard ( KeyEvent { code : Key :: Left , .. } ) => self . perform ( Cmd :: Move ( Direction :: Left ) ) ,
149+ Event :: Keyboard ( KeyEvent { code : Key :: Right , .. } ) => self . perform ( Cmd :: Move ( Direction :: Right ) ) ,
150+ Event :: Keyboard ( KeyEvent { code : Key :: Home , .. } ) => self . perform ( Cmd :: GoTo ( Position :: Begin ) ) ,
151+ Event :: Keyboard ( KeyEvent { code : Key :: End , .. } ) => self . perform ( Cmd :: GoTo ( Position :: End ) ) ,
152+ Event :: Keyboard ( KeyEvent { code : Key :: Delete , .. } ) => self . perform ( Cmd :: Cancel ) ,
161153 Event :: Keyboard ( KeyEvent {
162- code : Key :: Left , ..
163- } ) => self . perform ( Cmd :: Move ( Direction :: Left ) ) ,
164- Event :: Keyboard ( KeyEvent {
165- code : Key :: Right , ..
166- } ) => self . perform ( Cmd :: Move ( Direction :: Right ) ) ,
167- Event :: Keyboard ( KeyEvent {
168- code : Key :: Home , ..
169- } ) => self . perform ( Cmd :: GoTo ( Position :: Begin ) ) ,
170- Event :: Keyboard ( KeyEvent { code : Key :: End , .. } ) => {
171- self . perform ( Cmd :: GoTo ( Position :: End ) )
172- }
173- Event :: Keyboard ( KeyEvent {
174- code : Key :: Delete , ..
175- } ) => self . perform ( Cmd :: Cancel ) ,
176- Event :: Keyboard ( KeyEvent {
177- code : Key :: Backspace ,
178- ..
154+ code : Key :: Backspace , ..
179155 } ) => self . perform ( Cmd :: Delete ) ,
180156 Event :: Keyboard ( KeyEvent {
181- code : Key :: Char ( ch) ,
182- ..
157+ code : Key :: Char ( ch) , ..
183158 } ) => self . perform ( Cmd :: Type ( ch) ) ,
184159 Event :: Keyboard ( KeyEvent { code : Key :: Tab , .. } ) => {
185160 self . focus_next ( ) ;
186161 CmdResult :: None
187162 }
188- Event :: Keyboard ( KeyEvent {
189- code : Key :: Enter , ..
190- } ) => {
163+ Event :: Keyboard ( KeyEvent { code : Key :: Enter , .. } ) => {
191164 //todo send data
192165 let client_id = self . client_id_input . state ( ) . unwrap_one ( ) . unwrap_string ( ) ;
193- let client_secret = self
194- . client_secret_input
195- . state ( )
196- . unwrap_one ( )
197- . unwrap_string ( ) ;
198- return Some ( Msg :: LoginPopup ( LoginPopupMsg :: LoginDone (
199- client_id,
200- client_secret,
201- ) ) ) ;
166+ let client_secret = self . client_secret_input . state ( ) . unwrap_one ( ) . unwrap_string ( ) ;
167+ return Some ( Msg :: LoginPopup ( LoginPopupMsg :: LoginDone ( client_id, client_secret) ) ) ;
202168 }
203169 Event :: Keyboard ( KeyEvent { code : Key :: Esc , .. } ) => {
204170 return Some ( Msg :: LoginPopup ( LoginPopupMsg :: Closed ) ) ;
0 commit comments