xaizek / pipedial (License: GPLv3 only) (since 2019-01-08)
One more tool for selecting something in console.
Commit 70ce3e4d1b6c3c9c688161d6092dee5e59513f86

Make libcursed suitable for implementing a prompt
Author: xaizek
Author date (UTC): 2019-01-18 13:48
Committer name: xaizek
Committer date (UTC): 2019-01-18 13:48
Parent(s): bc71bcf92be8a837d9bf1043f14f9e5d7611a849
Signing key: 99DC5E4DB05F6BE2
Tree: b9b03ba693c13fe4994e4f935263a4102a41131e
File Lines added Lines deleted
libs/cursed/Prompt.cpp 8 6
libs/cursed/Prompt.hpp 15 14
libs/cursed/Screen.cpp 12 0
libs/cursed/Screen.hpp 5 0
libs/cursed/Window.cpp 12 0
libs/cursed/Window.hpp 7 0
File libs/cursed/Prompt.cpp copied from file libs/cursed/Label.cpp (similarity 82%) (mode: 100644) (index 8fd6496..bf9a9b0)
16 16 // You should have received a copy of the GNU General Public License // You should have received a copy of the GNU General Public License
17 17 // along with libcursed. If not, see <https://www.gnu.org/licenses/>. // along with libcursed. If not, see <https://www.gnu.org/licenses/>.
18 18
19 #include "Label.hpp"
19 #include "Prompt.hpp"
20 20
21 21 #include <string> #include <string>
22 22 #include <utility> #include <utility>
23 23
24 24 using namespace cursed; using namespace cursed;
25 25
26 Label::Label(std::wstring initText) : text(std::move(initText))
26 Prompt::Prompt() : pos(text.size())
27 27 { } { }
28 28
29 29 void void
30 Label::setText(std::wstring newText)
30 Prompt::setText(std::wstring newText, int newPos)
31 31 { {
32 32 text = std::move(newText); text = std::move(newText);
33 pos = newPos;
33 34 } }
34 35
35 36 void void
36 Label::draw()
37 Prompt::draw()
37 38 { {
38 39 werase(win); werase(win);
39 40 mvwprintw(win, 0, 0, "%ls", text.c_str()); mvwprintw(win, 0, 0, "%ls", text.c_str());
41 wmove(win, 0, pos);
40 42 wnoutrefresh(win); wnoutrefresh(win);
41 43 } }
42 44
43 45 int int
44 Label::desiredHeight()
46 Prompt::desiredHeight()
45 47 { {
46 48 return 1; return 1;
47 49 } }
48 50
49 51 void void
50 Label::placed(Pos newPos, Size newSize)
52 Prompt::placed(Pos newPos, Size newSize)
51 53 { {
52 54 win.place(newPos, newSize); win.place(newPos, newSize);
53 55 } }
File libs/cursed/Prompt.hpp copied from file libs/cursed/Label.hpp (similarity 68%) (mode: 100644) (index fd87751..326b52d)
16 16 // You should have received a copy of the GNU General Public License // You should have received a copy of the GNU General Public License
17 17 // along with libcursed. If not, see <https://www.gnu.org/licenses/>. // along with libcursed. If not, see <https://www.gnu.org/licenses/>.
18 18
19 #ifndef LIBCURSED__LABEL_HPP__
20 #define LIBCURSED__LABEL_HPP__
19 #ifndef LIBCURSED__PROMPT_HPP__
20 #define LIBCURSED__PROMPT_HPP__
21 21
22 22 #include <string> #include <string>
23 23
 
26 26
27 27 namespace cursed { namespace cursed {
28 28
29 // Static text field.
30 class Label : public Widget
29 // Prompt for requesting input.
30 class Prompt : public Widget
31 31 { {
32 32 public: public:
33 // Constructs a label. Can throw `std::runtime_error`.
34 explicit Label(std::wstring initText = {});
33 // Constructs a prompt. Can throw `std::runtime_error`.
34 explicit Prompt();
35 35
36 Label(const Label &rhs) = delete;
37 Label(Label &&rhs) = delete;
38 Label & operator=(const Label &rhs) = delete;
39 Label & operator=(Label &&rhs) = delete;
36 Prompt(const Prompt &rhs) = delete;
37 Prompt(Prompt &&rhs) = delete;
38 Prompt & operator=(const Prompt &rhs) = delete;
39 Prompt & operator=(Prompt &&rhs) = delete;
40 40
41 41 public: public:
42 // Updates text of the label.
43 void setText(std::wstring newText);
42 // Updates text and cursor position of the prompt.
43 void setText(std::wstring newText, int newPos);
44 44
45 45 // Updates state of this widget to be published on the screen. // Updates state of this widget to be published on the screen.
46 46 virtual void draw() override; virtual void draw() override;
 
... ... private:
56 56
57 57 private: private:
58 58 guts::Window win; // Window object. guts::Window win; // Window object.
59 std::wstring text; // Text of the label.
59 std::wstring text; // Text of the lprompt.
60 int pos; // Cursor position.
60 61 }; };
61 62
62 63 } }
63 64
64 #endif // LIBCURSED__LABEL_HPP__
65 #endif // LIBCURSED__PROMPT_HPP__
File libs/cursed/Screen.cpp changed (mode: 100644) (index 1987a2c..7a564d4)
... ... Screen::draw()
57 57 doupdate(); doupdate();
58 58 } }
59 59 } }
60
61 void
62 Screen::showCursor()
63 {
64 curs_set(1);
65 }
66
67 void
68 Screen::hideCursor()
69 {
70 curs_set(0);
71 }
File libs/cursed/Screen.hpp changed (mode: 100644) (index fab19b1..f20b6c0)
... ... public:
37 37 // Draws main widget and makes screen updates visible on physical screen. // Draws main widget and makes screen updates visible on physical screen.
38 38 void draw(); void draw();
39 39
40 // Makes cursor visible.
41 void showCursor();
42 // Makes cursor invisible.
43 void hideCursor();
44
40 45 private: private:
41 46 Widget *mainWidget = nullptr; // Root of all currently displayed widgets. Widget *mainWidget = nullptr; // Root of all currently displayed widgets.
42 47 }; };
File libs/cursed/Window.cpp changed (mode: 100644) (index 24a8025..549af5f)
... ... void
71 71 wnoutrefresh(w(win.raw())); wnoutrefresh(w(win.raw()));
72 72 } }
73 73
74 void
75 (guts::wtimeout)(Window &win, int delay)
76 {
77 wtimeout(w(win.raw()), delay);
78 }
79
80 int
81 (guts::wget_wch)(Window &win, std::wint_t *wch)
82 {
83 return wget_wch(w(win.raw()), wch);
84 }
85
74 86 void void
75 87 (guts::wattron)(Window &win, Attribs attrs) (guts::wattron)(Window &win, Attribs attrs)
76 88 { {
File libs/cursed/Window.hpp changed (mode: 100644) (index f781dce..e530a9e)
19 19 #ifndef LIBCURSED__WINDOW_HPP__ #ifndef LIBCURSED__WINDOW_HPP__
20 20 #define LIBCURSED__WINDOW_HPP__ #define LIBCURSED__WINDOW_HPP__
21 21
22 #include <cwctype>
23
22 24 namespace cursed { namespace cursed {
23 25
24 26 class Pos; class Pos;
 
... ... void (werase)(Window &win);
63 65 // Publishes changes to be displayed on the next screen update. // Publishes changes to be displayed on the next screen update.
64 66 void (wnoutrefresh)(Window &win); void (wnoutrefresh)(Window &win);
65 67
68 // Sets time to wait for input on a window (negative means block).
69 void (wtimeout)(Window &win, int delay);
70 // Reads input on a window.
71 int (wget_wch)(Window &win, std::wint_t *wch);
72
66 73 // Enables an attribute. // Enables an attribute.
67 74 void (wattron)(Window &win, Attribs attrs); void (wattron)(Window &win, Attribs attrs);
68 75 // Disables an attribute. // Disables an attribute.
Hints

Before first commit, do not forget to setup your git environment:
git config --global user.name "your_name_here"
git config --global user.email "your@email_here"

Clone this repository using HTTP(S):
git clone https://code.reversed.top/user/xaizek/pipedial

Clone this repository using ssh (do not forget to upload a key first):
git clone ssh://rocketgit@code.reversed.top/user/xaizek/pipedial

You are allowed to anonymously push to this repository.
This means that your pushed commits will automatically be transformed into a pull request:
... clone the repository ...
... make some changes and some commits ...
git push origin master