File docs/pipedial.1 changed (mode: 100644) (index 1abc8d0..115f2f6) |
1 |
1 |
.\" Automatically generated by Pandoc 1.17.0.3 |
.\" Automatically generated by Pandoc 1.17.0.3 |
2 |
2 |
.\" |
.\" |
3 |
|
.TH "pipedial" "1" "May 21, 2019" "" "" |
|
|
3 |
|
.TH "pipedial" "1" "July 29, 2020" "" "" |
4 |
4 |
.hy |
.hy |
5 |
5 |
.SH NAME |
.SH NAME |
6 |
6 |
.PP |
.PP |
|
... |
... |
Display version information. |
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 |
39 |
\f[B]/\f[] \-\- start interactive filtering. |
\f[B]/\f[] \-\- start interactive filtering. |
|
40 |
|
Case is respected unless no matches are found. |
40 |
41 |
.PP |
.PP |
41 |
42 |
\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 |
42 |
43 |
element. |
element. |
File src/PipeDial.cpp changed (mode: 100644) (index 398b706..a63c790) |
17 |
17 |
|
|
18 |
18 |
#include "PipeDial.hpp" |
#include "PipeDial.hpp" |
19 |
19 |
|
|
|
20 |
|
#include <algorithm> |
|
21 |
|
#include <locale> |
20 |
22 |
#include <string> |
#include <string> |
21 |
23 |
#include <utility> |
#include <utility> |
22 |
24 |
#include <vector> |
#include <vector> |
|
32 |
34 |
#include "vle/Modes.hpp" |
#include "vle/Modes.hpp" |
33 |
35 |
#include "vle/keys.hpp" |
#include "vle/keys.hpp" |
34 |
36 |
|
|
|
37 |
|
static std::wstring::size_type find(const std::wstring &str, |
|
38 |
|
const std::wstring &what, |
|
39 |
|
bool caseSensitive, |
|
40 |
|
std::wstring::size_type from = 0U); |
|
41 |
|
|
35 |
42 |
PipeDial::PipeDial(std::wstring titleText, std::vector<std::wstring> initLines) |
PipeDial::PipeDial(std::wstring titleText, std::vector<std::wstring> initLines) |
36 |
43 |
: lines(std::move(initLines)), input(cursed::Keypad::Disabled), |
: lines(std::move(initLines)), input(cursed::Keypad::Disabled), |
37 |
44 |
title(std::move(titleText)), quit(false) |
title(std::move(titleText)), quit(false) |
|
... |
... |
PipeDial::buildNormalMode() |
236 |
243 |
} |
} |
237 |
244 |
|
|
238 |
245 |
filtered.clear(); |
filtered.clear(); |
239 |
|
for (const std::wstring &line : lines) { |
|
240 |
|
auto pos = line.find(filter); |
|
241 |
|
if (pos == std::wstring::npos) { |
|
242 |
|
continue; |
|
|
246 |
|
for (int tries = 0; tries < 2; ++tries) { |
|
247 |
|
bool caseSensitive = (tries == 0); |
|
248 |
|
for (const std::wstring &line : lines) { |
|
249 |
|
auto pos = find(line, filter, caseSensitive); |
|
250 |
|
if (pos == std::wstring::npos) { |
|
251 |
|
continue; |
|
252 |
|
} |
|
253 |
|
|
|
254 |
|
cursed::ColorTree item; |
|
255 |
|
decltype(pos) from = 0U; |
|
256 |
|
while (pos != std::wstring::npos) { |
|
257 |
|
item += line.substr(from, pos - from); |
|
258 |
|
item += matchHi(line.substr(pos, filter.size())); |
|
259 |
|
|
|
260 |
|
from = pos + filter.size(); |
|
261 |
|
pos = find(line, filter, caseSensitive, from); |
|
262 |
|
} |
|
263 |
|
item += line.substr(from); |
|
264 |
|
filtered.emplace_back(std::move(item)); |
243 |
265 |
} |
} |
244 |
266 |
|
|
245 |
|
cursed::ColorTree item; |
|
246 |
|
decltype(pos) from = 0U; |
|
247 |
|
while (pos != std::wstring::npos) { |
|
248 |
|
item += line.substr(from, pos - from); |
|
249 |
|
item += matchHi(line.substr(pos, filter.size())); |
|
250 |
|
|
|
251 |
|
from = pos + filter.size(); |
|
252 |
|
pos = line.find(filter, from); |
|
|
267 |
|
if (!filtered.empty()) { |
|
268 |
|
break; |
253 |
269 |
} |
} |
254 |
|
item += line.substr(from); |
|
255 |
|
filtered.emplace_back(std::move(item)); |
|
256 |
270 |
} |
} |
257 |
271 |
filterList.setItems(filtered); |
filterList.setItems(filtered); |
258 |
272 |
}; |
}; |
|
... |
... |
PipeDial::buildNormalMode() |
269 |
283 |
return normalMode; |
return normalMode; |
270 |
284 |
} |
} |
271 |
285 |
|
|
|
286 |
|
// A `std::string::find()`-like function that can do case-insensitive searches. |
|
287 |
|
static std::wstring::size_type |
|
288 |
|
find(const std::wstring &where, const std::wstring &what, bool caseSensitive, |
|
289 |
|
std::wstring::size_type from) |
|
290 |
|
{ |
|
291 |
|
if (caseSensitive) { |
|
292 |
|
return where.find(what, from); |
|
293 |
|
} |
|
294 |
|
|
|
295 |
|
std::locale loc; |
|
296 |
|
auto it = std::search(where.cbegin() + from, where.cend(), |
|
297 |
|
what.cbegin(), what.cend(), |
|
298 |
|
[&loc](wchar_t a, wchar_t b) { |
|
299 |
|
return std::toupper(a, loc) |
|
300 |
|
== std::toupper(b, loc); |
|
301 |
|
}); |
|
302 |
|
if (it == where.cend()) { |
|
303 |
|
return std::wstring::npos; |
|
304 |
|
} |
|
305 |
|
return it - where.cbegin(); |
|
306 |
|
} |
|
307 |
|
|
272 |
308 |
vle::Mode |
vle::Mode |
273 |
309 |
PipeDial::buildHelpMode() |
PipeDial::buildHelpMode() |
274 |
310 |
{ |
{ |