@@ -12,19 +12,20 @@ use bluer::{
1212use futures:: FutureExt ;
1313use ratatui:: {
1414 Frame ,
15- layout:: { Alignment , Constraint , Layout , Margin , Rect } ,
16- style:: { Color , Modifier , Style , Stylize } ,
17- text:: { Line , Span } ,
15+ layout:: { Constraint , Layout , Margin , Rect } ,
16+ style:: { Color , Style , Stylize } ,
17+ text:: Line ,
1818 widgets:: {
19- Block , BorderType , Borders , Cell , Clear , Padding , Paragraph , Row , Scrollbar ,
20- ScrollbarOrientation , ScrollbarState , Table , TableState ,
19+ Block , BorderType , Borders , Cell , Padding , Row , Scrollbar , ScrollbarOrientation ,
20+ ScrollbarState , Table , TableState ,
2121 } ,
2222} ;
2323use tokio:: sync:: mpsc:: UnboundedSender ;
2424use tui_input:: Input ;
2525
2626use crate :: {
2727 agent:: AuthAgent ,
28+ alias:: render_set_alias,
2829 bluetooth:: Controller ,
2930 config:: { Config , Width } ,
3031 favorite:: { read_favorite_devices_from_disk, save_favorite_devices_to_disk} ,
@@ -166,99 +167,6 @@ impl App {
166167 }
167168 }
168169
169- pub fn render_set_alias ( & mut self , frame : & mut Frame , area : Rect ) {
170- let block = Layout :: vertical ( [
171- Constraint :: Fill ( 1 ) ,
172- Constraint :: Length ( 6 ) ,
173- Constraint :: Fill ( 1 ) ,
174- ] )
175- . split ( area) ;
176-
177- let block = Layout :: horizontal ( [
178- Constraint :: Fill ( 1 ) ,
179- Constraint :: Max ( 70 ) ,
180- Constraint :: Fill ( 1 ) ,
181- ] )
182- . split ( block[ 1 ] ) [ 1 ] ;
183-
184- let ( text_block, alias_block) = {
185- let chunks = Layout :: vertical (
186- [
187- Constraint :: Length ( 1 ) ,
188- Constraint :: Length ( 3 ) ,
189- Constraint :: Length ( 1 ) ,
190- Constraint :: Length ( 2 ) ,
191- ]
192- . as_ref ( ) ,
193- )
194- . split ( block) ;
195-
196- let area1 = Layout :: horizontal (
197- [
198- Constraint :: Length ( 1 ) ,
199- Constraint :: Fill ( 1 ) ,
200- Constraint :: Length ( 1 ) ,
201- ]
202- . as_ref ( ) ,
203- )
204- . split ( chunks[ 1 ] ) ;
205-
206- let area2 = Layout :: horizontal (
207- [
208- Constraint :: Percentage ( 20 ) ,
209- Constraint :: Fill ( 1 ) ,
210- Constraint :: Percentage ( 20 ) ,
211- ]
212- . as_ref ( ) ,
213- )
214- . split ( chunks[ 2 ] ) ;
215-
216- ( area1[ 1 ] , area2[ 1 ] )
217- } ;
218-
219- frame. render_widget ( Clear , block) ;
220- frame. render_widget (
221- Block :: new ( )
222- . borders ( Borders :: ALL )
223- . border_type ( BorderType :: Thick )
224- . style ( Style :: default ( ) . green ( ) )
225- . border_style ( Style :: default ( ) . fg ( Color :: Green ) ) ,
226- block,
227- ) ;
228-
229- if let Some ( selected_controller) = self . controller_state . selected ( ) {
230- let controller = & self . controllers [ selected_controller] ;
231- if let Some ( index) = self . paired_devices_state . selected ( ) {
232- let name = controller. paired_devices [ index] . alias . as_str ( ) ;
233-
234- let text = Line :: from ( vec ! [
235- Span :: from( "Enter the new name for " ) ,
236- Span :: styled(
237- name,
238- Style :: default ( ) . add_modifier( Modifier :: BOLD | Modifier :: ITALIC ) ,
239- ) ,
240- ] ) ;
241-
242- let msg = Paragraph :: new ( text)
243- . alignment ( Alignment :: Center )
244- . style ( Style :: default ( ) . fg ( Color :: White ) )
245- . block ( Block :: new ( ) . padding ( Padding :: horizontal ( 2 ) ) ) ;
246-
247- let alias = Paragraph :: new ( self . new_alias . value ( ) )
248- . alignment ( Alignment :: Left )
249- . style ( Style :: default ( ) . fg ( Color :: White ) )
250- . block (
251- Block :: new ( )
252- . bg ( Color :: DarkGray )
253- . padding ( Padding :: horizontal ( 2 ) ) ,
254- ) ;
255-
256- frame. render_widget ( msg, text_block) ;
257- frame. render_widget ( alias, alias_block) ;
258- }
259- }
260- }
261-
262170 pub fn render ( & mut self , frame : & mut Frame ) {
263171 if let Some ( selected_controller_index) = self . controller_state . selected ( ) {
264172 let selected_controller = & self . controllers [ selected_controller_index] ;
@@ -685,7 +593,14 @@ impl App {
685593
686594 // Set alias popup
687595 if self . focused_block == FocusedBlock :: SetDeviceAliasBox {
688- self . render_set_alias ( frame, area) ;
596+ render_set_alias (
597+ & self . controllers ,
598+ & self . controller_state ,
599+ & self . paired_devices_state ,
600+ & self . new_alias ,
601+ frame,
602+ area,
603+ ) ;
689604 }
690605
691606 // Request Confirmation
0 commit comments