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

Add interactive filtering on `&` key
Less-like key.
Author: xaizek
Author date (UTC): 2019-01-22 17:34
Committer name: xaizek
Committer date (UTC): 2019-01-24 15:40
Parent(s): 3f214e687a2ddeab2b13b0a71cfc64c90aa5c3d5
Signing key: 99DC5E4DB05F6BE2
Tree: e66319e5a689950f6a3ee40a1ef22711afe69dc0
File Lines added Lines deleted
README.md 1 0
docs/04-shortcuts.md 2 0
docs/pipedial.1 3 1
src/PipeDial.cpp 32 1
src/PipeDial.hpp 2 0
File README.md changed (mode: 100644) (index 48a899b..ca7763f)
... ... their existence being rewrites of other tools for no good reason.
14 14 ### Features ### ### Features ###
15 15
16 16 * Very basic Vim-like navigation. * Very basic Vim-like navigation.
17 * Filtering by substring.
17 18
18 19 ### Example ### ### Example ###
19 20
File docs/04-shortcuts.md changed (mode: 100644) (index 2b0df43..354f75c)
... ... Normal Mode
14 14
15 15 **e** -- edit current item and accept the result. **e** -- edit current item and accept the result.
16 16
17 **&** -- start interactive filtering.
18
17 19 **[count]gg** -- put cursor on the first or **[count]**-th element. **[count]gg** -- put cursor on the first or **[count]**-th element.
18 20
19 21 **[count]G** -- put cursor on the last or **[count]**-th element. **[count]G** -- put cursor on the last or **[count]**-th element.
File docs/pipedial.1 changed (mode: 100644) (index 2226281..6bddbb2)
1 1 .\" Automatically generated by Pandoc 1.17.0.3 .\" Automatically generated by Pandoc 1.17.0.3
2 2 .\" .\"
3 .TH "pipedial" "1" "January 18, 2019" "" ""
3 .TH "pipedial" "1" "January 22, 2019" "" ""
4 4 .hy .hy
5 5 .SH NAME .SH NAME
6 6 .PP .PP
 
... ... Display version information.
36 36 .PP .PP
37 37 \f[B]e\f[] \-\- edit current item and accept the result. \f[B]e\f[] \-\- edit current item and accept the result.
38 38 .PP .PP
39 \f[B]&\f[] \-\- start interactive filtering.
40 .PP
39 41 \f[B][count]gg\f[] \-\- put cursor on the first or \f[B][count]\f[]\-th \f[B][count]gg\f[] \-\- put cursor on the first or \f[B][count]\f[]\-th
40 42 element. element.
41 43 .PP .PP
File src/PipeDial.cpp changed (mode: 100644) (index 8052571..484002c)
22 22 #include <utility> #include <utility>
23 23 #include <vector> #include <vector>
24 24
25 #include "cursed/List.hpp"
25 26 #include "cursed/Prompt.hpp" #include "cursed/Prompt.hpp"
26 27 #include "cursed/Track.hpp" #include "cursed/Track.hpp"
27 28
 
... ... h -- enter Help mode.
49 50
50 51 e -- edit current item and accept the result. e -- edit current item and accept the result.
51 52
53 & -- start interactive filtering.
54
52 55 [count]gg -- put cursor on the first or [count]-th element. [count]gg -- put cursor on the first or [count]-th element.
53 56
54 57 [count]G -- put cursor on the last or [count]-th element. [count]G -- put cursor on the last or [count]-th element.
 
... ... Help Mode
63 66 h -- return to Normal mode.)"; h -- return to Normal mode.)";
64 67
65 68 PipeDial::PipeDial(std::wstring titleText, std::vector<std::wstring> lines) PipeDial::PipeDial(std::wstring titleText, std::vector<std::wstring> lines)
66 : title(std::move(titleText)), help(helpText), quit(false)
69 : lines(lines), title(std::move(titleText)), help(helpText), quit(false)
67 70 { {
68 71 list.setItems(std::move(lines)); list.setItems(std::move(lines));
69 72
 
... ... PipeDial::buildNormalMode()
132 135 screen.setMainWidget(&track); screen.setMainWidget(&track);
133 136 } }
134 137 }, "edit and accept" }); }, "edit and accept" });
138 normalMode.addShortcut({ L"&", [&]() {
139 cursed::List filterList;
140 filterList.setItems(lines);
141
142 cursed::Prompt prompt;
143 cursed::Track tmpTrack;
144 tmpTrack.addItem(&title);
145 tmpTrack.addItem(&filterList);
146 tmpTrack.addItem(&prompt);
147
148 std::vector<std::wstring> filtered = lines;
149 auto update = [&](const std::wstring &filter) {
150 filtered.clear();
151 for (const std::wstring &line : lines) {
152 if (line.find(filter) != std::wstring::npos) {
153 filtered.push_back(line);
154 }
155 }
156 filterList.setItems(filtered);
157 };
158
159 PromptRequest request(input, screen, prompt, update);
160 screen.setMainWidget(&tmpTrack);
161 if (request.prompt(L"&/", L"")) {
162 list.setItems(std::move(filtered));
163 }
164 screen.setMainWidget(&track);
165 }, "start interactive filtering" });
135 166
136 167 return normalMode; return normalMode;
137 168 } }
File src/PipeDial.hpp changed (mode: 100644) (index 5e2a893..dcb2ae0)
... ... private:
56 56 vle::Mode buildHelpMode(); vle::Mode buildHelpMode();
57 57
58 58 private: private:
59 std::vector<std::wstring> lines; // Original list of lines.
60
59 61 cursed::Init cursesInit; // Curses initialization manager. cursed::Init cursesInit; // Curses initialization manager.
60 62 cursed::Screen screen; // Screen manager. cursed::Screen screen; // Screen manager.
61 63 cursed::Input input; // Source of input events. cursed::Input input; // Source of input events.
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