Skip to content

Commit 0003a3f

Browse files
Add "Hide password" button.
+ Add an "Hide password" button. + Upgrade FTXUI version to include: ArthurSonzogni/FTXUI@b95a7a4 + And various minor improvements.
1 parent 61793ff commit 0003a3f

2 files changed

Lines changed: 45 additions & 48 deletions

File tree

CMakeLists.txt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ set(FETCHCONTENT_UPDATES_DISCONNECTED TRUE)
99

1010
FetchContent_Declare(ftxui
1111
GIT_REPOSITORY https://github.com/ArthurSonzogni/FTXUI
12-
GIT_TAG 69b0c9e53e523ac43a303964fc9c5bc0da7d5d61
12+
GIT_TAG b95a7a4c6b8e89f5288a96d8b2c0461ad4a69f77
1313
)
1414

1515
FetchContent_GetProperties(ftxui)
@@ -112,4 +112,4 @@ if(ARMHF_DEB)
112112

113113
include(CPack)
114114

115-
endif(ARMHF_DEB)
115+
endif(ARMHF_DEB)

src/ui/panel/passwd/passwd.cpp

Lines changed: 43 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -12,58 +12,55 @@ namespace {
1212

1313
class passwdImpl : public PanelBase {
1414
public:
15-
passwdImpl() : user(getlogin()), view(false) {
16-
InputOption inp_opt;
17-
inp_opt.password = true;
18-
inp_opt.cursor_position = 0;
19-
inp_opt.on_enter = [&] { view = !view; };
20-
input_p = Input(&pass, "Current Password", inp_opt);
21-
input_np = Input(&new_pass, "New Password", inp_opt);
22-
change_ = Button("Change", [&] {
23-
auto cmd = "passwd " + user;
15+
passwdImpl() : user_(getlogin()) {
16+
input_options_.password = &hide_password_;
17+
input_password_old_ =
18+
Input(&password_old_, "Current Password", &input_options_);
19+
input_password_new_ =
20+
Input(&password_new_, "New Password", &input_options_);
21+
hide_password_checkbox_ = Checkbox("Hide password", &hide_password_);
22+
apply_button_ = Button("Apply", [&] {
23+
auto cmd = "passwd " + user_;
2424
FILE* fp = popen(cmd.c_str(), "w");
25-
fprintf(fp, "%s\n", pass.data());
26-
fprintf(fp, "%s\n", new_pass.data());
27-
fprintf(fp, "%s\n", new_pass.data());
25+
fprintf(fp, "%s\n", password_old_.data());
26+
fprintf(fp, "%s\n", password_new_.data());
27+
fprintf(fp, "%s\n", password_new_.data());
2828
pclose(fp);
2929
});
30-
page = Renderer(Container::Vertical({
31-
input_p,
32-
input_np,
33-
change_,
34-
}),
35-
[&] {
36-
if (view) {
37-
return vbox({
38-
text("User: " + user),
39-
text("Pass: " + pass),
40-
text("New : " + new_pass),
41-
input_p->Render(),
42-
input_np->Render(),
43-
change_->Render(),
44-
});
45-
}
46-
return vbox({
47-
text("User: " + user),
48-
input_p->Render(),
49-
input_np->Render(),
50-
change_->Render(),
51-
});
52-
});
53-
Add(page);
54-
};
30+
31+
auto layout = Container::Vertical({
32+
input_password_old_,
33+
input_password_new_,
34+
hide_password_checkbox_,
35+
apply_button_,
36+
});
37+
38+
layout = Renderer(layout, [&] {
39+
return vbox({
40+
hbox(text("User:"), text(user_)),
41+
hbox(text("Old password:"), input_password_old_->Render()),
42+
hbox(text("New password:"), input_password_new_->Render()),
43+
hide_password_checkbox_->Render(),
44+
apply_button_->Render(),
45+
});
46+
});
47+
48+
Add(layout);
49+
}
5550
~passwdImpl() = default;
5651
std::string Title() override { return "Password"; }
5752

5853
private:
59-
Component input_p;
60-
Component input_np;
61-
Component change_;
62-
Component page;
63-
std::string pass;
64-
std::string new_pass;
65-
std::string user;
66-
bool view;
54+
std::string password_old_;
55+
std::string password_new_;
56+
std::string user_;
57+
58+
Component input_password_old_;
59+
Component input_password_new_;
60+
Component hide_password_checkbox_;
61+
Component apply_button_;
62+
InputOption input_options_;
63+
bool hide_password_ = false;
6764
};
6865

6966
} // namespace
@@ -75,4 +72,4 @@ Panel passwd() {
7572

7673
} // namespace panel
7774

78-
} // namespace ui
75+
} // namespace ui

0 commit comments

Comments
 (0)