1
1
use crate :: fl;
2
2
use crate :: picker:: { LAYERS , SCANCODE_LABELS } ;
3
- use backend:: { Key , Keycode } ;
3
+ use backend:: { Key , Keycode , Mods } ;
4
4
5
5
#[ derive( Clone , Copy , Debug , PartialEq , Eq , Hash ) ]
6
6
pub enum Page {
@@ -91,14 +91,7 @@ fn keycode_label(keycode: &Keycode) -> Option<Vec<String>> {
91
91
if mods. is_empty ( ) {
92
92
Some ( vec ! [ SCANCODE_LABELS . get( keycode) ?. clone( ) ] )
93
93
} else {
94
- let mut label = String :: new ( ) ;
95
- for name in mods. mod_names ( ) {
96
- let mod_label = SCANCODE_LABELS . get ( name) ?;
97
- if !label. is_empty ( ) {
98
- label. push_str ( " + " ) ;
99
- }
100
- label. push_str ( mod_label) ;
101
- }
94
+ let mut label = mods_label ( * mods) ;
102
95
if keycode != "NONE" {
103
96
let keycode_label = SCANCODE_LABELS . get ( keycode) ?;
104
97
label. push_str ( " + " ) ;
@@ -108,14 +101,7 @@ fn keycode_label(keycode: &Keycode) -> Option<Vec<String>> {
108
101
}
109
102
}
110
103
Keycode :: MT ( mods, keycode) => {
111
- let mut mods_label = String :: new ( ) ;
112
- for name in mods. mod_names ( ) {
113
- let mod_label = SCANCODE_LABELS . get ( name) ?;
114
- if !mods_label. is_empty ( ) {
115
- mods_label. push_str ( " + " ) ;
116
- }
117
- mods_label. push_str ( mod_label) ;
118
- }
104
+ let mods_label = mods_label ( * mods) ;
119
105
let keycode_label = SCANCODE_LABELS . get ( keycode) ?. clone ( ) ;
120
106
Some ( vec ! [ mods_label, keycode_label] )
121
107
}
@@ -127,3 +113,15 @@ fn keycode_label(keycode: &Keycode) -> Option<Vec<String>> {
127
113
}
128
114
}
129
115
}
116
+
117
+ fn mods_label ( mods : Mods ) -> String {
118
+ let mut label = String :: new ( ) ;
119
+ for name in mods. mod_names ( ) {
120
+ let mod_label = SCANCODE_LABELS . get ( name) . map_or ( "" , String :: as_str) ;
121
+ if !label. is_empty ( ) {
122
+ label. push_str ( " + " ) ;
123
+ }
124
+ label. push_str ( mod_label) ;
125
+ }
126
+ label
127
+ }
0 commit comments