@@ -12,58 +12,55 @@ namespace {
1212
1313class 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