|
|
|
@ -12,7 +12,6 @@
|
|
|
|
|
#include <set>
|
|
|
|
|
#include <list>
|
|
|
|
|
#include <utility>
|
|
|
|
|
#include <vector>
|
|
|
|
|
|
|
|
|
|
#include "df/interface_key.h"
|
|
|
|
|
#include "df/ui.h"
|
|
|
|
@ -26,8 +25,6 @@ using df::global::ui;
|
|
|
|
|
using df::global::gps;
|
|
|
|
|
using df::global::enabler;
|
|
|
|
|
|
|
|
|
|
std::vector<std::string> command_history;
|
|
|
|
|
|
|
|
|
|
class viewscreen_commandpromptst;
|
|
|
|
|
class prompt_ostream:public buffered_color_ostream
|
|
|
|
|
{
|
|
|
|
@ -48,17 +45,15 @@ public:
|
|
|
|
|
|
|
|
|
|
void render();
|
|
|
|
|
void help() { }
|
|
|
|
|
int8_t movies_okay() { return 0; }
|
|
|
|
|
|
|
|
|
|
std::string getFocusString() { return "commandprompt"; }
|
|
|
|
|
int8_t movies_okay() { return 0; }
|
|
|
|
|
viewscreen_commandpromptst(std::string entry):is_response(false),entry(entry)
|
|
|
|
|
{
|
|
|
|
|
show_fps=df::global::gps->display_frames;
|
|
|
|
|
df::global::gps->display_frames=0;
|
|
|
|
|
cursor_pos = 0;
|
|
|
|
|
frame = 0;
|
|
|
|
|
history_idx = command_history.size();
|
|
|
|
|
command_history.push_back("");
|
|
|
|
|
}
|
|
|
|
|
~viewscreen_commandpromptst()
|
|
|
|
|
{
|
|
|
|
@ -77,7 +72,6 @@ public:
|
|
|
|
|
protected:
|
|
|
|
|
std::list<std::pair<color_value,std::string> > responses;
|
|
|
|
|
int cursor_pos;
|
|
|
|
|
int history_idx;
|
|
|
|
|
bool is_response;
|
|
|
|
|
bool show_fps;
|
|
|
|
|
int frame;
|
|
|
|
@ -148,8 +142,6 @@ void viewscreen_commandpromptst::submit()
|
|
|
|
|
//color_ostream_proxy out(Core::getInstance().getConsole());
|
|
|
|
|
prompt_ostream out(this);
|
|
|
|
|
Core::getInstance().runCommand(out, entry);
|
|
|
|
|
command_history.pop_back();
|
|
|
|
|
command_history.push_back(entry);
|
|
|
|
|
if(out.empty() && responses.empty())
|
|
|
|
|
Screen::dismiss(this);
|
|
|
|
|
else
|
|
|
|
@ -173,12 +165,12 @@ void viewscreen_commandpromptst::feed(std::set<df::interface_key> *events)
|
|
|
|
|
}
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
if(events->count(interface_key::SELECT))
|
|
|
|
|
if (events->count(interface_key::SELECT))
|
|
|
|
|
{
|
|
|
|
|
submit();
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
if(is_response)
|
|
|
|
|
if (is_response)
|
|
|
|
|
return;
|
|
|
|
|
for (auto it = events->begin(); it != events->end(); ++it)
|
|
|
|
|
{
|
|
|
|
@ -212,8 +204,7 @@ void viewscreen_commandpromptst::feed(std::set<df::interface_key> *events)
|
|
|
|
|
else if(events->count(interface_key::CURSOR_LEFT))
|
|
|
|
|
{
|
|
|
|
|
cursor_pos--;
|
|
|
|
|
if (cursor_pos < 0)
|
|
|
|
|
cursor_pos = 0;
|
|
|
|
|
if (cursor_pos < 0) cursor_pos = 0;
|
|
|
|
|
}
|
|
|
|
|
else if(events->count(interface_key::CUSTOM_CTRL_A))
|
|
|
|
|
{
|
|
|
|
@ -223,30 +214,6 @@ void viewscreen_commandpromptst::feed(std::set<df::interface_key> *events)
|
|
|
|
|
{
|
|
|
|
|
cursor_pos = entry.size();
|
|
|
|
|
}
|
|
|
|
|
else if(events->count(interface_key::CURSOR_UP))
|
|
|
|
|
{
|
|
|
|
|
if (command_history.back() == "")
|
|
|
|
|
{
|
|
|
|
|
command_history.pop_back();
|
|
|
|
|
command_history.push_back(entry);
|
|
|
|
|
}
|
|
|
|
|
history_idx--;
|
|
|
|
|
if (history_idx < 0)
|
|
|
|
|
history_idx = 0;
|
|
|
|
|
entry = command_history[history_idx];
|
|
|
|
|
cursor_pos = entry.size();
|
|
|
|
|
}
|
|
|
|
|
else if(events->count(interface_key::CURSOR_DOWN))
|
|
|
|
|
{
|
|
|
|
|
if (history_idx < command_history.size() - 1)
|
|
|
|
|
{
|
|
|
|
|
history_idx++;
|
|
|
|
|
if (history_idx >= command_history.size())
|
|
|
|
|
history_idx = command_history.size() - 1;
|
|
|
|
|
entry = command_history[history_idx];
|
|
|
|
|
cursor_pos = entry.size();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
if (old_pos != cursor_pos)
|
|
|
|
|
frame = 0;
|
|
|
|
|
}
|
|
|
|
@ -273,7 +240,6 @@ DFhackCExport command_result plugin_init ( color_ostream &out, std::vector <Plug
|
|
|
|
|
"command-prompt","Shows a command prompt on window.",show_prompt,hotkey_allow_all,
|
|
|
|
|
"command-prompt [entry] - shows a cmd prompt in df window. Entry is used for default prefix (e.g. ':lua')"
|
|
|
|
|
));
|
|
|
|
|
command_history.push_back("");
|
|
|
|
|
return CR_OK;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|