Skip to content

Commit

Permalink
Make changes for v0.1.5
Browse files Browse the repository at this point in the history
    * Fix file popup state change
    * Reduce width of search field by 5
    * Move alpha version indicator
    * Change table labels
    * Fine-tuning of scrollbar
  • Loading branch information
kardwen committed Dec 2, 2024
1 parent 565541c commit 6369797
Show file tree
Hide file tree
Showing 8 changed files with 58 additions and 45 deletions.
2 changes: 1 addition & 1 deletion Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
[package]
name = "passepartui"
description = "A TUI for pass"
version = "0.1.4"
version = "0.1.5"
edition = "2021"
authors = ["Karl Felix Schewe"]
readme = "README.md"
Expand Down
9 changes: 2 additions & 7 deletions src/components/dashboard.rs
Original file line number Diff line number Diff line change
Expand Up @@ -161,10 +161,6 @@ impl<'a> Dashboard<'a> {
}

fn update_pass_details(&mut self, pass_id: String, message: String) {
if !self.password_details.show_secrets {
return;
}

match self.get_selected_info() {
Some(info) if pass_id == info.pass_id => (),
_ => return,
Expand Down Expand Up @@ -200,7 +196,7 @@ impl<'a> Dashboard<'a> {
// let remainder = lines.fold(String::default(), |a, b| a + b);
// if !remainder.is_empty() {}

self.password_details.number_of_lines = Some(count);
self.password_details.line_count = Some(count);
}

fn show_pass_secrets(&mut self) {
Expand Down Expand Up @@ -356,7 +352,6 @@ impl<'a> Component for Dashboard<'a> {
// Open file popup and fetch details
NavigationAction::File => {
self.app_state.overlay = OverlayState::File;
self.show_pass_secrets();
Some(Action::Password(PasswordAction::Fetch))
}
NavigationAction::Leave => match self.app_state {
Expand Down Expand Up @@ -532,7 +527,7 @@ impl<'a> Widget for &mut Dashboard<'a> {
// Search field
match self.app_state.search {
SearchState::Active | SearchState::Suspended => {
let search_width = 40.min(area.width);
let search_width = 35.min(area.width);
let popup_area = Rect {
x: area.width.saturating_sub(search_width + 1),
y: 3.min(area.height),
Expand Down
11 changes: 6 additions & 5 deletions src/components/menu.rs
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
use ratatui::{
buffer::Buffer, crossterm::event::MouseEvent, layout::Rect, style::Stylize, widgets::Widget,
};

use crate::{
actions::{Action, NavigationAction},
components::{Button, MouseSupport},
theme::Theme,
};
use ratatui::{
buffer::Buffer, crossterm::event::MouseEvent, layout::Rect, style::Stylize, widgets::Widget,
};

#[derive(Debug, Default, Clone)]
pub struct Menu<'a> {
Expand Down Expand Up @@ -60,8 +61,8 @@ impl<'a> Widget for &mut Menu<'a> {
fn render(self, area: Rect, buf: &mut Buffer) {
self.area = Some(area);

// Title bar and menu
let title = "passepartui α "
// Logo
let title = "passepartui "
.bold()
.into_right_aligned_line()
.fg(self.theme.menu_logo_fg)
Expand Down
38 changes: 23 additions & 15 deletions src/components/password_details.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ use details_field::DetailsField;
pub struct PasswordDetails<'a> {
pub show_secrets: bool,
pub pass_id: Option<String>,
pub number_of_lines: Option<usize>,
pub line_count: Option<usize>,
pub password: Option<String>,
pub one_time_password: Option<String>,
pub login: Option<String>,
Expand Down Expand Up @@ -124,7 +124,7 @@ impl PasswordDetails<'_> {
Self {
show_secrets: false,
pass_id: None,
number_of_lines: None,
line_count: None,
password: None,
one_time_password: None,
login: None,
Expand All @@ -141,7 +141,7 @@ impl PasswordDetails<'_> {
// Does not reset pass id
pub fn clear_secrets(&mut self) {
self.show_secrets = false;
self.number_of_lines = None;
self.line_count = None;
self.password = None;
self.one_time_password = None;
self.login = None;
Expand All @@ -150,7 +150,7 @@ impl PasswordDetails<'_> {
pub fn reset(&mut self) {
self.show_secrets = false;
self.pass_id = None;
self.number_of_lines = None;
self.line_count = None;
self.password = None;
self.one_time_password = None;
self.login = None;
Expand Down Expand Up @@ -201,10 +201,12 @@ impl Widget for &mut PasswordDetails<'_> {
}

// Number of lines field
if let Some(number) = &self.number_of_lines {
let field_area = left_layout[1];
self.lines_field.set_content(&number.to_string());
self.lines_field.render(field_area, buf);
if let Some(number) = &self.line_count {
if self.show_secrets {
let field_area = left_layout[1];
self.lines_field.set_content(&number.to_string());
self.lines_field.render(field_area, buf);
}
}

// Hint
Expand Down Expand Up @@ -237,7 +239,9 @@ impl Widget for &mut PasswordDetails<'_> {
// Password field
if self.pass_id.is_some() {
let field_area = right_areas.next().expect("counted before");
if let Some(password) = &self.password {
if !self.show_secrets {
self.password_field.reset_content()
} else if let Some(password) = &self.password {
self.password_field.set_content(password);
} else {
self.password_field.reset_content()
Expand All @@ -247,16 +251,20 @@ impl Widget for &mut PasswordDetails<'_> {

// One-time password field
if let Some(ref otp) = self.one_time_password {
let field_area = right_areas.next().expect("counted before");
self.otp_field.set_content(otp);
self.otp_field.render(*field_area, buf);
if self.show_secrets {
let field_area = right_areas.next().expect("counted before");
self.otp_field.set_content(otp);
self.otp_field.render(*field_area, buf);
}
}

// Login field
if let Some(ref login) = self.login {
let field_area = right_areas.next().expect("counted before");
self.login_field.set_content(login);
self.login_field.render(*field_area, buf);
if self.show_secrets {
let field_area = right_areas.next().expect("counted before");
self.login_field.set_content(login);
self.login_field.render(*field_area, buf);
}
}
}
}
Expand Down
27 changes: 14 additions & 13 deletions src/components/password_table.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ pub struct PasswordTable<'a> {
scrollbar_state: ScrollbarState,
area: Option<Rect>,
mouse_content_area: Option<Rect>,
mouse_scrollbar_area: Option<Rect>,
mouse_track_area: Option<Rect>,
}

impl<'a> PasswordTable<'a> {
Expand All @@ -46,7 +46,7 @@ impl<'a> PasswordTable<'a> {
scrollbar_state,
area: None,
mouse_content_area: None,
mouse_scrollbar_area: None,
mouse_track_area: None,
}
}

Expand Down Expand Up @@ -157,7 +157,7 @@ impl<'a> PasswordTable<'a> {
let selected_cell_style = Style::default()
.add_modifier(Modifier::REVERSED)
.fg(theme.table_selected_cell_style_fg);
let header = ["Password", "Last modified (UTC)"]
let header = ["Password file", "Last modified (UTC)"]
.into_iter()
.map(Cell::from)
.collect::<Row>()
Expand Down Expand Up @@ -185,19 +185,20 @@ impl<'a> PasswordTable<'a> {
pub fn selected(&self) -> Option<usize> {
self.table_state.selected()
}

pub fn mouse_scrollbar_area(&self) -> Option<Rect> {
self.mouse_scrollbar_area
}
}

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

let [table_area, s_area] =
let [table_area, right_area] =
Layout::horizontal([Constraint::Min(1), Constraint::Length(1)]).areas(area);
let [above_track_area, track_area] =
Layout::vertical([Constraint::Length(1), Constraint::Min(1)]).areas(right_area);
buf.set_style(above_track_area, Style::new().bg(theme.table_header_bg));
// Draw handle event when no row is displayed
buf.set_style(track_area, Style::new().bg(theme.standard_fg));

// Calculate areas for mouse interaction
let mouse_content_area = Rect {
Expand All @@ -206,13 +207,13 @@ impl<'a> Widget for &mut PasswordTable<'a> {
width: area.width.saturating_sub(8),
height: area.height.saturating_sub(1),
};
let mouse_scrollbar_area = Rect {
let mouse_track_area = Rect {
x: area.width.saturating_sub(8),
width: 8,
..mouse_content_area
};
self.mouse_content_area = Some(mouse_content_area);
self.mouse_scrollbar_area = Some(mouse_scrollbar_area);
self.mouse_track_area = Some(mouse_track_area);

StatefulWidget::render(&self.table, table_area, buf, &mut self.table_state);

Expand All @@ -225,9 +226,9 @@ impl<'a> Widget for &mut PasswordTable<'a> {
.bg(theme.table_track_bg),
)
.thumb_style(Style::new().fg(theme.standard_fg).bg(theme.standard_bg))
.begin_symbol(Some(" "))
.begin_symbol(None)
.end_symbol(None)
.render(s_area, buf, &mut self.scrollbar_state);
.render(track_area, buf, &mut self.scrollbar_state);
}
}

Expand All @@ -252,7 +253,7 @@ impl<'a> MouseSupport for PasswordTable<'a> {
}

// Mouse position on the scrollbar
if let Some(area) = self.mouse_scrollbar_area {
if let Some(area) = self.mouse_track_area {
if area.contains(position) {
return match event.kind {
MouseEventKind::Down(MouseButton::Left)
Expand Down
12 changes: 10 additions & 2 deletions src/components/status_bar.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@ use crate::theme::Theme;
use ratatui::{
buffer::Buffer,
layout::Rect,
style::Style,
style::{Style, Stylize},
text::Line,
widgets::{Paragraph, Widget},
};

Expand Down Expand Up @@ -32,7 +33,14 @@ impl StatusBar {
impl Widget for &mut StatusBar {
fn render(self, area: Rect, buf: &mut Buffer) {
let theme = self.theme;
Paragraph::new(&*self.text)
Paragraph::new(Line::from(&*self.text))
.style(
Style::default()
.bg(theme.status_bar_bg)
.fg(theme.status_bar_fg),
)
.render(area, buf);
Paragraph::new(Line::from("α").right_aligned().fg(theme.menu_logo_fg))
.style(
Style::default()
.bg(theme.status_bar_bg)
Expand Down
2 changes: 1 addition & 1 deletion src/theme.rs
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ impl Theme {
table_selected_cell_style_fg: tailwind::BLUE.c600,
table_selected_column_style_fg: tailwind::BLUE.c400,
table_selected_row_style_fg: tailwind::BLUE.c400,
table_track_bg: tailwind::SLATE.c900,
table_track_bg: tailwind::SLATE.c800,
table_track_fg: tailwind::SLATE.c400,
}
}
Expand Down

0 comments on commit 6369797

Please sign in to comment.