Skip to content

Commit 1ed7d34

Browse files
committed
tweak keybindings popup widget
1 parent 25faf3f commit 1ed7d34

File tree

3 files changed

+46
-9
lines changed

3 files changed

+46
-9
lines changed

crates/mds-tui/src/keybindings.rs

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
use std::collections::HashMap;
22

33
use ratatui::{
4-
layout::{Alignment, Constraint, Rect},
4+
layout::{Constraint, Rect},
55
style::{Color, Modifier, Style},
66
text::{Line, Span, Text},
77
widgets::{
@@ -79,7 +79,7 @@ impl<'km> KeybindingsPopup<'km> {
7979
Constraint::Length(desired_width.min(screen_width * 60 / 100))
8080
} else if screen_width > 80 {
8181
let percentage = 60 + ((120 - screen_width) * 20 / 40);
82-
Constraint::Percentage(percentage.into())
82+
Constraint::Percentage(percentage)
8383
} else {
8484
Constraint::Percentage(90)
8585
}
@@ -90,7 +90,7 @@ impl<'km> KeybindingsPopup<'km> {
9090
Constraint::Percentage(60)
9191
} else if screen_height > 24 {
9292
let percentage = 70 + ((40 - screen_height) * 15 / 16);
93-
Constraint::Percentage(percentage.into())
93+
Constraint::Percentage(percentage)
9494
} else {
9595
Constraint::Percentage(90)
9696
}
@@ -127,8 +127,6 @@ impl<'a> StatefulWidget for KeybindingsPopup<'a> {
127127
}
128128

129129
let block = Block::default()
130-
.title(" Keybindings ")
131-
.title_alignment(Alignment::Center)
132130
.borders(Borders::ALL)
133131
.border_type(BorderType::Rounded);
134132

@@ -145,10 +143,10 @@ impl<'a> StatefulWidget for KeybindingsPopup<'a> {
145143

146144
let area = util::center(area, width_constraint, height_constraint);
147145

148-
let area = util::center(area, width_constraint, height_constraint);
149-
150146
Clear.render(area, buf);
151147

148+
let inner_area = block.inner(area);
149+
152150
StatefulWidget::render(
153151
Table::new(rows, constraints)
154152
.block(block)
@@ -157,7 +155,9 @@ impl<'a> StatefulWidget for KeybindingsPopup<'a> {
157155
.style(Style::default().add_modifier(Modifier::BOLD))
158156
.bottom_margin(1),
159157
)
160-
.row_highlight_style(Style::default().add_modifier(Modifier::REVERSED)),
158+
.row_highlight_style(
159+
Style::default().add_modifier(Modifier::BOLD | Modifier::UNDERLINED),
160+
),
161161
area,
162162
buf,
163163
state,
@@ -172,6 +172,6 @@ impl<'a> StatefulWidget for KeybindingsPopup<'a> {
172172
.position(state.selected().unwrap_or(0))
173173
.viewport_content_length(viewport_height);
174174

175-
scrollbar.render(area, buf, &mut scrollbar_state);
175+
scrollbar.render(inner_area, buf, &mut scrollbar_state);
176176
}
177177
}

tests/snapshots.rs

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -115,3 +115,16 @@ fn test_render_default_config_editor_box_select_edit() {
115115
let term = draw(model).unwrap();
116116
assert_snapshot!(term.backend());
117117
}
118+
119+
#[test]
120+
fn test_render_default_keybindings_popup() {
121+
let mut model = setup_app(AppConfig::default());
122+
123+
let mut msg: Option<Message> = model.update(Action::Keybindings);
124+
while msg.is_some() {
125+
msg = model.update(msg.unwrap());
126+
}
127+
128+
let term = draw(model).unwrap();
129+
assert_snapshot!(term.backend());
130+
}
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
---
2+
source: tests/snapshots.rs
3+
expression: term.backend()
4+
---
5+
"┌0 IPs discovered────────────────────────────────────────────────────────v1.2.3┐"
6+
"│ ╭──────────────────────────────────────────────────────────────────────╮ │"
7+
"│ │Action Keystroke █│ │"
8+
"│ │ █│ │"
9+
"│ │Close Esc █│ │"
10+
"│ │Config Shift-C █│ │"
11+
"│ │CopyToClipboard Ctrl-C, Ctrl-Shift-C, Y █│ │"
12+
"│ │DecreaseLayoutFill - █│ │"
13+
"│ │DecreaseVerbosity G ║│ │"
14+
"│ │IncreaseLayoutFill + ║│ │"
15+
"│ │IncreaseVerbosity V ║│ │"
16+
"│ │Keybindings ? ║│ │"
17+
"└───│NavigateDown Down, J ║│───┘"
18+
" │NavigateLeft H, Left ║│ "
19+
" Log│NavigatePagedown Pagedown ║│ "
20+
" │NavigatePageup Pageup ║│ "
21+
" │NavigateRight L, Right ║│ "
22+
" │NavigateScrollToBeginning Home ║│ "
23+
" ╰──────────────────────────────────────────────────────────────────────╯ "
24+
" "

0 commit comments

Comments
 (0)