@@ -7,13 +7,14 @@ use ratatui::{
77 Frame ,
88 layout:: { Alignment , Constraint , Direction , Flex , Layout } ,
99 style:: { Color , Style , Stylize } ,
10- text:: Line ,
10+ text:: { Line , Span } ,
1111 widgets:: { Block , BorderType , Borders , Cell , Clear , List , Padding , Row , Table , TableState } ,
1212} ;
1313use tokio:: sync:: mpsc:: UnboundedSender ;
1414
1515use crate :: {
1616 app:: { AppResult , ColorMode , FocusedBlock } ,
17+ config:: Config ,
1718 device:: Device ,
1819 event:: Event ,
1920} ;
@@ -27,10 +28,15 @@ pub struct Adapter {
2728 pub vendor : Option < String > ,
2829 pub supported_modes : Vec < String > ,
2930 pub device : Device ,
31+ pub config : Arc < Config > ,
3032}
3133
3234impl Adapter {
33- pub async fn new ( session : Arc < Session > , sender : UnboundedSender < Event > ) -> AppResult < Self > {
35+ pub async fn new (
36+ session : Arc < Session > ,
37+ sender : UnboundedSender < Event > ,
38+ config : Arc < Config > ,
39+ ) -> AppResult < Self > {
3440 let adapter = session. adapter ( ) . context ( "No adapter found" ) ?;
3541
3642 let is_powered = adapter. is_powered ( ) . await ?;
@@ -48,6 +54,7 @@ impl Adapter {
4854 vendor,
4955 supported_modes,
5056 device,
57+ config,
5158 } )
5259 }
5360
@@ -82,25 +89,27 @@ impl Adapter {
8289 None => false ,
8390 } ;
8491
85- let ( device_block, access_point_block, connected_devices_block) = {
92+ let ( device_block, access_point_block, connected_devices_block, help_block ) = {
8693 let chunks = Layout :: default ( )
8794 . direction ( Direction :: Vertical )
8895 . constraints ( if any_connected_devices {
8996 & [
9097 Constraint :: Percentage ( 33 ) ,
9198 Constraint :: Percentage ( 33 ) ,
9299 Constraint :: Percentage ( 33 ) ,
100+ Constraint :: Length ( 1 ) ,
93101 ]
94102 } else {
95103 & [
96104 Constraint :: Percentage ( 50 ) ,
97105 Constraint :: Percentage ( 50 ) ,
98106 Constraint :: Fill ( 1 ) ,
107+ Constraint :: Length ( 1 ) ,
99108 ]
100109 } )
101110 . margin ( 1 )
102111 . split ( frame. area ( ) ) ;
103- ( chunks[ 0 ] , chunks[ 1 ] , chunks[ 2 ] )
112+ ( chunks[ 0 ] , chunks[ 1 ] , chunks[ 2 ] , chunks [ 3 ] )
104113 } ;
105114
106115 // Device
@@ -423,6 +432,46 @@ impl Adapter {
423432
424433 frame. render_widget ( connected_devices_list, connected_devices_block) ;
425434 }
435+
436+ let help_message = match focused_block {
437+ FocusedBlock :: Device => Line :: from ( vec ! [
438+ Span :: from( self . config. device. infos. to_string( ) ) . bold( ) ,
439+ Span :: from( " Infos" ) ,
440+ Span :: from( " | " ) ,
441+ Span :: from( self . config. device. toggle_power. to_string( ) ) . bold( ) ,
442+ Span :: from( " Toggle Power" ) ,
443+ Span :: from( " | " ) ,
444+ Span :: from( "ctrl+r" ) . bold( ) ,
445+ Span :: from( " Switch Mode" ) ,
446+ Span :: from( " | " ) ,
447+ Span :: from( "⇄" ) . bold( ) ,
448+ Span :: from( " Nav" ) ,
449+ ] ) ,
450+ FocusedBlock :: AdapterInfos | FocusedBlock :: AccessPointInput => Line :: from ( vec ! [
451+ Span :: from( " " ) . bold( ) ,
452+ Span :: from( " Discard" ) ,
453+ Span :: from( " | " ) ,
454+ Span :: from( "⇄" ) . bold( ) ,
455+ Span :: from( " Nav" ) ,
456+ ] ) ,
457+ FocusedBlock :: AccessPoint => Line :: from ( vec ! [
458+ Span :: from( self . config. ap. start. to_string( ) ) . bold( ) ,
459+ Span :: from( " New AP" ) ,
460+ Span :: from( " | " ) ,
461+ Span :: from( self . config. ap. stop. to_string( ) ) . bold( ) ,
462+ Span :: from( " Stop AP" ) ,
463+ Span :: from( " | " ) ,
464+ Span :: from( "ctrl+r" ) . bold( ) ,
465+ Span :: from( " Switch Mode" ) ,
466+ Span :: from( " | " ) ,
467+ Span :: from( "⇄" ) . bold( ) ,
468+ Span :: from( " Nav" ) ,
469+ ] ) ,
470+ _ => Line :: from ( "" ) ,
471+ } ;
472+
473+ let help_message = help_message. centered ( ) . blue ( ) ;
474+ frame. render_widget ( help_message, help_block) ;
426475 }
427476
428477 pub fn render_station_mode (
@@ -431,18 +480,19 @@ impl Adapter {
431480 color_mode : ColorMode ,
432481 focused_block : FocusedBlock ,
433482 ) {
434- let ( device_block, station_block, known_networks_block, new_networks_block) = {
483+ let ( device_block, station_block, known_networks_block, new_networks_block, help_block ) = {
435484 let chunks = Layout :: default ( )
436485 . direction ( Direction :: Vertical )
437486 . constraints ( [
438487 Constraint :: Length ( 5 ) ,
439488 Constraint :: Length ( 5 ) ,
440489 Constraint :: Min ( 5 ) ,
441490 Constraint :: Min ( 5 ) ,
491+ Constraint :: Length ( 1 ) ,
442492 ] )
443493 . margin ( 1 )
444494 . split ( frame. area ( ) ) ;
445- ( chunks[ 0 ] , chunks[ 1 ] , chunks[ 2 ] , chunks[ 3 ] )
495+ ( chunks[ 0 ] , chunks[ 1 ] , chunks[ 2 ] , chunks[ 3 ] , chunks [ 4 ] )
446496 } ;
447497
448498 // Device
@@ -984,6 +1034,99 @@ impl Adapter {
9841034 new_networks_block,
9851035 & mut new_networks_state,
9861036 ) ;
1037+
1038+ let help_message = match focused_block {
1039+ FocusedBlock :: Device => Line :: from ( vec ! [
1040+ Span :: from( self . config. station. start_scanning. to_string( ) ) . bold( ) ,
1041+ Span :: from( " Scan" ) ,
1042+ Span :: from( " | " ) ,
1043+ Span :: from( self . config. device. infos. to_string( ) ) . bold( ) ,
1044+ Span :: from( " Infos" ) ,
1045+ Span :: from( " | " ) ,
1046+ Span :: from( self . config. device. toggle_power. to_string( ) ) . bold( ) ,
1047+ Span :: from( " Toggle Power" ) ,
1048+ Span :: from( " | " ) ,
1049+ Span :: from( "ctrl+r" ) . bold( ) ,
1050+ Span :: from( " Switch Mode" ) ,
1051+ Span :: from( " | " ) ,
1052+ Span :: from( "⇄" ) . bold( ) ,
1053+ Span :: from( " Nav" ) ,
1054+ ] ) ,
1055+ FocusedBlock :: Station => Line :: from ( vec ! [
1056+ Span :: from( self . config. station. start_scanning. to_string( ) ) . bold( ) ,
1057+ Span :: from( " Scan" ) ,
1058+ Span :: from( " | " ) ,
1059+ Span :: from( "ctrl+r" ) . bold( ) ,
1060+ Span :: from( " Switch Mode" ) ,
1061+ Span :: from( " | " ) ,
1062+ Span :: from( "⇄" ) . bold( ) ,
1063+ Span :: from( " Nav" ) ,
1064+ ] ) ,
1065+ FocusedBlock :: KnownNetworks => Line :: from ( vec ! [
1066+ Span :: from( "k," ) . bold( ) ,
1067+ Span :: from( " Up" ) ,
1068+ Span :: from( " | " ) ,
1069+ Span :: from( "j," ) . bold( ) ,
1070+ Span :: from( " Down" ) ,
1071+ Span :: from( " | " ) ,
1072+ Span :: from( if self . config. station. toggle_connect == ' ' {
1073+ " " . to_string( )
1074+ } else {
1075+ self . config. station. toggle_connect. to_string( )
1076+ } )
1077+ . bold( ) ,
1078+ Span :: from( " Connect/Disconnect" ) ,
1079+ Span :: from( " | " ) ,
1080+ Span :: from( self . config. station. known_network. remove. to_string( ) ) . bold( ) ,
1081+ Span :: from( " Remove" ) ,
1082+ Span :: from( " | " ) ,
1083+ Span :: from(
1084+ self . config
1085+ . station
1086+ . known_network
1087+ . toggle_autoconnect
1088+ . to_string( ) ,
1089+ )
1090+ . bold( ) ,
1091+ Span :: from( " Toggle Autoconnect" ) ,
1092+ Span :: from( " | " ) ,
1093+ Span :: from( " " ) . bold( ) ,
1094+ Span :: from( " Discard" ) ,
1095+ Span :: from( " | " ) ,
1096+ Span :: from( "ctrl+r" ) . bold( ) ,
1097+ Span :: from( " Switch Mode" ) ,
1098+ Span :: from( " | " ) ,
1099+ Span :: from( "⇄" ) . bold( ) ,
1100+ Span :: from( " Nav" ) ,
1101+ ] ) ,
1102+ FocusedBlock :: NewNetworks => Line :: from ( vec ! [
1103+ Span :: from( "k," ) . bold( ) ,
1104+ Span :: from( " Up" ) ,
1105+ Span :: from( " | " ) ,
1106+ Span :: from( "j," ) . bold( ) ,
1107+ Span :: from( " Down" ) ,
1108+ Span :: from( " | " ) ,
1109+ Span :: from( " " ) . bold( ) ,
1110+ Span :: from( " Connect" ) ,
1111+ Span :: from( " | " ) ,
1112+ Span :: from( " " ) . bold( ) ,
1113+ Span :: from( " Discard" ) ,
1114+ Span :: from( " | " ) ,
1115+ Span :: from( "ctrl+r" ) . bold( ) ,
1116+ Span :: from( " Switch Mode" ) ,
1117+ Span :: from( " | " ) ,
1118+ Span :: from( "⇄" ) . bold( ) ,
1119+ Span :: from( " Nav" ) ,
1120+ ] ) ,
1121+ FocusedBlock :: AdapterInfos | FocusedBlock :: AuthKey => {
1122+ Line :: from ( vec ! [ Span :: from( " " ) . bold( ) , Span :: from( " Discard" ) ] )
1123+ }
1124+ _ => Line :: from ( "" ) ,
1125+ } ;
1126+
1127+ let help_message = help_message. centered ( ) . blue ( ) ;
1128+
1129+ frame. render_widget ( help_message, help_block) ;
9871130 }
9881131
9891132 pub fn render_adapter ( & self , frame : & mut Frame , color_mode : ColorMode ) {
0 commit comments