1- use std:: sync:: Arc ;
1+ use std:: { fmt :: format , sync:: Arc } ;
22
33use anyhow:: Context ;
44
@@ -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 , Text } ,
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
@@ -431,18 +438,19 @@ impl Adapter {
431438 color_mode : ColorMode ,
432439 focused_block : FocusedBlock ,
433440 ) {
434- let ( device_block, station_block, known_networks_block, new_networks_block) = {
441+ let ( device_block, station_block, known_networks_block, new_networks_block, help_block ) = {
435442 let chunks = Layout :: default ( )
436443 . direction ( Direction :: Vertical )
437444 . constraints ( [
438445 Constraint :: Length ( 5 ) ,
439446 Constraint :: Length ( 5 ) ,
440447 Constraint :: Min ( 5 ) ,
441448 Constraint :: Min ( 5 ) ,
449+ Constraint :: Length ( 3 ) ,
442450 ] )
443451 . margin ( 1 )
444452 . split ( frame. area ( ) ) ;
445- ( chunks[ 0 ] , chunks[ 1 ] , chunks[ 2 ] , chunks[ 3 ] )
453+ ( chunks[ 0 ] , chunks[ 1 ] , chunks[ 2 ] , chunks[ 3 ] , chunks [ 4 ] )
446454 } ;
447455
448456 // Device
@@ -984,6 +992,39 @@ impl Adapter {
984992 new_networks_block,
985993 & mut new_networks_state,
986994 ) ;
995+
996+ let help_message = match focused_block {
997+ FocusedBlock :: Device => {
998+ format ! (
999+ "⇄: Nav | {}: Scan | {}: Show information | {}: Toggle power" ,
1000+ self . config. station. start_scanning,
1001+ self . config. device. infos,
1002+ self . config. device. toggle_power
1003+ )
1004+ }
1005+ FocusedBlock :: Station => format ! (
1006+ "⇄: Nav | {}: Start Scanning" ,
1007+ self . config. station. start_scanning
1008+ ) ,
1009+ FocusedBlock :: KnownNetworks => format ! (
1010+ "k,↑: Up | j,↓: Down | ⇄: Nav | {}: Connect/Disconnect | {}: Remove | {}: Toggle autoconnect" ,
1011+ if self . config. station. toggle_connect == ' ' {
1012+ "Space"
1013+ } else {
1014+ & self . config. station. toggle_connect. to_string( )
1015+ } ,
1016+ self . config. station. known_network. remove,
1017+ self . config. station. known_network. toggle_autoconnect
1018+ ) ,
1019+ FocusedBlock :: NewNetworks => {
1020+ "k,↑: Up | j,↓: Down | ⇄: Nav | Space: Connect" . to_string ( )
1021+ }
1022+ _ => "" . to_string ( ) ,
1023+ } ;
1024+
1025+ let help_message = Text :: from ( help_message) . centered ( ) . bold ( ) . blue ( ) ;
1026+
1027+ frame. render_widget ( help_message, help_block) ;
9871028 }
9881029
9891030 pub fn render_adapter ( & self , frame : & mut Frame , color_mode : ColorMode ) {
0 commit comments