1
- use std:: sync:: Arc ;
1
+ use std:: { fmt :: format , sync:: Arc } ;
2
2
3
3
use anyhow:: Context ;
4
4
@@ -7,13 +7,14 @@ use ratatui::{
7
7
Frame ,
8
8
layout:: { Alignment , Constraint , Direction , Flex , Layout } ,
9
9
style:: { Color , Style , Stylize } ,
10
- text:: Line ,
10
+ text:: { Line , Text } ,
11
11
widgets:: { Block , BorderType , Borders , Cell , Clear , List , Padding , Row , Table , TableState } ,
12
12
} ;
13
13
use tokio:: sync:: mpsc:: UnboundedSender ;
14
14
15
15
use crate :: {
16
16
app:: { AppResult , ColorMode , FocusedBlock } ,
17
+ config:: Config ,
17
18
device:: Device ,
18
19
event:: Event ,
19
20
} ;
@@ -27,10 +28,15 @@ pub struct Adapter {
27
28
pub vendor : Option < String > ,
28
29
pub supported_modes : Vec < String > ,
29
30
pub device : Device ,
31
+ pub config : Arc < Config > ,
30
32
}
31
33
32
34
impl 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 > {
34
40
let adapter = session. adapter ( ) . context ( "No adapter found" ) ?;
35
41
36
42
let is_powered = adapter. is_powered ( ) . await ?;
@@ -48,6 +54,7 @@ impl Adapter {
48
54
vendor,
49
55
supported_modes,
50
56
device,
57
+ config,
51
58
} )
52
59
}
53
60
@@ -431,18 +438,19 @@ impl Adapter {
431
438
color_mode : ColorMode ,
432
439
focused_block : FocusedBlock ,
433
440
) {
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 ) = {
435
442
let chunks = Layout :: default ( )
436
443
. direction ( Direction :: Vertical )
437
444
. constraints ( [
438
445
Constraint :: Length ( 5 ) ,
439
446
Constraint :: Length ( 5 ) ,
440
447
Constraint :: Min ( 5 ) ,
441
448
Constraint :: Min ( 5 ) ,
449
+ Constraint :: Length ( 3 ) ,
442
450
] )
443
451
. margin ( 1 )
444
452
. split ( frame. area ( ) ) ;
445
- ( chunks[ 0 ] , chunks[ 1 ] , chunks[ 2 ] , chunks[ 3 ] )
453
+ ( chunks[ 0 ] , chunks[ 1 ] , chunks[ 2 ] , chunks[ 3 ] , chunks [ 4 ] )
446
454
} ;
447
455
448
456
// Device
@@ -984,6 +992,39 @@ impl Adapter {
984
992
new_networks_block,
985
993
& mut new_networks_state,
986
994
) ;
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) ;
987
1028
}
988
1029
989
1030
pub fn render_adapter ( & self , frame : & mut Frame , color_mode : ColorMode ) {
0 commit comments