-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathCommandLineWindow.hpp
43 lines (35 loc) · 1.02 KB
/
CommandLineWindow.hpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
#pragma once
#include "windows/OneLineInputWindow.hpp"
#include <memory>
namespace tdcurses {
class CommandLineWindow : public windows::OneLineInputWindow {
public:
class Callback {
public:
virtual ~Callback() = default;
virtual void on_command(std::string command) = 0;
};
bool force_active() const override {
return !is_empty();
}
private:
class Cb : public windows::OneLineInputWindow::Callback {
public:
Cb(std::unique_ptr<CommandLineWindow::Callback> cb) : cb_(std::move(cb)) {
}
void on_answer(OneLineInputWindow *self, std::string text) override {
cb_->on_command(std::move(text));
self->clear();
}
void on_abort(OneLineInputWindow *self, std::string text) override {
self->clear();
}
private:
std::unique_ptr<CommandLineWindow::Callback> cb_;
};
public:
CommandLineWindow(std::unique_ptr<CommandLineWindow::Callback> cb)
: windows::OneLineInputWindow("command: ", false, std::make_unique<Cb>(std::move(cb))) {
}
};
} // namespace tdcurses