Skip to content

Commit c01b357

Browse files
authored
Copy OTP Uri from QRCode page (#422)
This PR implements OTP Uri clipboard copy by pressing enter in the QRCode screen.
2 parents 53c11a1 + 34fe258 commit c01b357

File tree

9 files changed

+417
-350
lines changed

9 files changed

+417
-350
lines changed

src/interface/app.rs

Lines changed: 22 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,8 @@ const LARGE_APPLICATION_WIDTH: u16 = 75;
2121
/// Application result type.
2222
pub type AppResult<T> = Result<T, Box<dyn error::Error>>;
2323

24+
const DEFAULT_QRCODE_LABEL: &str = "Press enter to copy the OTP URI code";
25+
2426
/// Application.
2527
pub struct App<'a> {
2628
/// Is the application running?
@@ -36,6 +38,9 @@ pub struct App<'a> {
3638
pub(crate) search_query: String,
3739
pub(crate) focus: Focus,
3840
pub(crate) popup: Popup,
41+
42+
/// Info text in the QRCode page
43+
pub(crate) qr_code_page_label: &'static str,
3944
}
4045

4146
pub struct Popup {
@@ -60,7 +65,7 @@ impl<'a> App<'a> {
6065
progress: percentage(),
6166
label_text: String::from(""),
6267
print_percentage: true,
63-
current_page: Main,
68+
current_page: Page::default(),
6469
search_query: String::from(""),
6570
focus: Focus::MainPage,
6671
popup: Popup {
@@ -69,9 +74,16 @@ impl<'a> App<'a> {
6974
percent_x: 60,
7075
percent_y: 20,
7176
},
77+
qr_code_page_label: DEFAULT_QRCODE_LABEL,
7278
}
7379
}
7480

81+
pub(crate) fn reset(&mut self) {
82+
self.current_page = Page::default();
83+
self.print_percentage = true;
84+
self.qr_code_page_label = DEFAULT_QRCODE_LABEL;
85+
}
86+
7587
/// Handles the tick event of the terminal.
7688
pub fn tick(&mut self, force_update: bool) {
7789
// Update progress bar
@@ -105,11 +117,15 @@ impl<'a> App<'a> {
105117
} else {
106118
format!("{} - {}", &element.issuer, &element.label)
107119
};
108-
Paragraph::new(element.get_qrcode())
109-
.block(Block::default().title(title).borders(Borders::ALL))
110-
.style(Style::default().fg(Color::White).bg(Color::Reset))
111-
.alignment(Alignment::Center)
112-
.wrap(Wrap { trim: true })
120+
Paragraph::new(format!(
121+
"{}\n{}",
122+
element.get_qrcode(),
123+
self.qr_code_page_label
124+
))
125+
.block(Block::default().title(title).borders(Borders::ALL))
126+
.style(Style::default().fg(Color::White).bg(Color::Reset))
127+
.alignment(Alignment::Center)
128+
.wrap(Wrap { trim: true })
113129
})
114130
.unwrap_or_else(|| {
115131
Paragraph::new("No element is selected")

src/interface/enums.rs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,3 +18,9 @@ pub enum Page {
1818
Main,
1919
Qrcode,
2020
}
21+
22+
impl Default for Page {
23+
fn default() -> Self {
24+
Self::Main
25+
}
26+
}

0 commit comments

Comments
 (0)