Skip to content

Commit 0807b4a

Browse files
committed
Fix scrollbar style
1 parent 0a258f3 commit 0807b4a

File tree

4 files changed

+36
-25
lines changed

4 files changed

+36
-25
lines changed

Cargo.toml

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
[package]
22
name = "passepartui"
33
description = "A TUI for pass"
4-
version = "0.1.2"
4+
version = "0.1.3"
55
edition = "2021"
66
authors = ["Karl Felix Schewe"]
77
readme = "README.md"

README.md

+2-2
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ I started this project as a way to practice programming in Rust while reading th
1010
Therefore this project is still in an alpha version, however user interaction is mostly finished.
1111

1212
`passepartui` relies for all decryption operations on [pass](https://www.passwordstore.org/), one-time passwords (OTP) are handled by [`pass-otp`](https://github.com/tadfisher/pass-otp).
13-
Currently no functionality for manipulating the password store, e.g. adding or deleting a password, is implemented. For those operations use `pass` directly from your terminal (refer to `man pass`).
13+
Currently no functionality for manipulating the password store, e.g. adding or deleting a password, is implemented. For those operations use `pass` directly from your terminal (refer to `man pass`).
1414
More on the current state of development can be found below.
1515

1616
The name `passepartui` is a combination of "passepartout", French for "master key", and "TUI".
@@ -43,7 +43,7 @@ Type `passepartui` to run the app (provided that `~/.cargo/bin` has been added t
4343

4444
### Manual installation
4545

46-
Clone the repository and change to it:
46+
Clone the repository and change to the directory:
4747

4848
```sh
4949
git clone [email protected]:kardwen/passepartui.git

src/components/password_table.rs

+29-22
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
use ratatui::{
22
buffer::Buffer,
33
crossterm::event::{MouseButton, MouseEvent, MouseEventKind},
4-
layout::{Constraint, Position, Rect},
4+
layout::{Constraint, Layout, Position, Rect},
55
style::{Modifier, Style, Stylize},
66
text::{Line, Span, Text},
77
widgets::{
@@ -27,8 +27,8 @@ pub struct PasswordTable<'a> {
2727
scrollbar: Scrollbar<'a>,
2828
scrollbar_state: ScrollbarState,
2929
area: Option<Rect>,
30-
content_area: Option<Rect>,
31-
scrollbar_area: Option<Rect>,
30+
mouse_content_area: Option<Rect>,
31+
mouse_scrollbar_area: Option<Rect>,
3232
}
3333

3434
impl<'a> PasswordTable<'a> {
@@ -40,7 +40,14 @@ impl<'a> PasswordTable<'a> {
4040
let scrollbar_state = ScrollbarState::new(length);
4141
let scrollbar = Scrollbar::default()
4242
.orientation(ScrollbarOrientation::VerticalRight)
43-
.begin_symbol(None)
43+
.begin_style(Style::new().bg(theme.table_header_bg))
44+
.track_style(
45+
Style::new()
46+
.fg(theme.table_track_fg)
47+
.bg(theme.table_track_bg),
48+
)
49+
.thumb_style(Style::new().fg(theme.standard_fg).bg(theme.standard_bg))
50+
.begin_symbol(Some(" "))
4451
.end_symbol(None);
4552
Self {
4653
theme,
@@ -51,8 +58,8 @@ impl<'a> PasswordTable<'a> {
5158
scrollbar,
5259
scrollbar_state,
5360
area: None,
54-
content_area: None,
55-
scrollbar_area: None,
61+
mouse_content_area: None,
62+
mouse_scrollbar_area: None,
5663
}
5764
}
5865

@@ -192,36 +199,36 @@ impl<'a> PasswordTable<'a> {
192199
self.table_state.selected()
193200
}
194201

195-
pub fn scrollbar_area(&self) -> Option<Rect> {
196-
self.scrollbar_area
202+
pub fn mouse_scrollbar_area(&self) -> Option<Rect> {
203+
self.mouse_scrollbar_area
197204
}
198205
}
199206

200207
impl<'a> Widget for &mut PasswordTable<'a> {
201208
fn render(self, area: Rect, buf: &mut Buffer) {
202209
self.area = Some(area);
203210

204-
// Exclude header (height: 1) and scrollbar_area plus tolerance from content_area
205-
let content_area = Rect {
211+
let layout = Layout::horizontal([Constraint::Min(1), Constraint::Length(1)]).split(area);
212+
213+
// Calculate areas for mouse interaction
214+
let mouse_content_area = Rect {
206215
x: area.x,
207216
y: area.y + 1,
208217
width: area.width.saturating_sub(8),
209218
height: area.height.saturating_sub(1),
210219
};
211-
let scrollbar_area_width = 8;
212-
let scrollbar_area = Rect {
213-
x: area.width.saturating_sub(scrollbar_area_width),
214-
width: scrollbar_area_width,
215-
..content_area
220+
let mouse_scrollbar_area = Rect {
221+
x: area.width.saturating_sub(8),
222+
width: 8,
223+
..mouse_content_area
216224
};
217-
self.content_area = Some(content_area);
218-
self.scrollbar_area = Some(scrollbar_area);
219-
220-
StatefulWidget::render(&self.table, area, buf, &mut self.table_state);
225+
self.mouse_content_area = Some(mouse_content_area);
226+
self.mouse_scrollbar_area = Some(mouse_scrollbar_area);
221227

228+
StatefulWidget::render(&self.table, layout[0], buf, &mut self.table_state);
222229
self.scrollbar
223230
.clone()
224-
.render(scrollbar_area, buf, &mut self.scrollbar_state);
231+
.render(layout[1], buf, &mut self.scrollbar_state);
225232
}
226233
}
227234

@@ -230,7 +237,7 @@ impl<'a> MouseSupport for PasswordTable<'a> {
230237
let position = Position::new(event.column, event.row);
231238

232239
// Mouse position on password table contents
233-
if let Some(area) = self.content_area {
240+
if let Some(area) = self.mouse_content_area {
234241
if area.contains(position) {
235242
return match event.kind {
236243
MouseEventKind::Down(MouseButton::Left) => {
@@ -246,7 +253,7 @@ impl<'a> MouseSupport for PasswordTable<'a> {
246253
}
247254

248255
// Mouse position on the scrollbar
249-
if let Some(area) = self.scrollbar_area {
256+
if let Some(area) = self.mouse_scrollbar_area {
250257
if area.contains(position) {
251258
return match event.kind {
252259
MouseEventKind::Down(MouseButton::Left)

src/theme.rs

+4
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,8 @@ pub struct Theme {
3232
pub table_selected_cell_style_fg: Color,
3333
pub table_selected_column_style_fg: Color,
3434
pub table_selected_row_style_fg: Color,
35+
pub table_track_bg: Color,
36+
pub table_track_fg: Color,
3537
}
3638

3739
impl Theme {
@@ -68,6 +70,8 @@ impl Theme {
6870
table_selected_cell_style_fg: tailwind::BLUE.c600,
6971
table_selected_column_style_fg: tailwind::BLUE.c400,
7072
table_selected_row_style_fg: tailwind::BLUE.c400,
73+
table_track_bg: tailwind::SLATE.c800,
74+
table_track_fg: tailwind::SLATE.c400,
7175
}
7276
}
7377
}

0 commit comments

Comments
 (0)