From 7e6b8618ea2826131835ded05fbeff2e63f08eb8 Mon Sep 17 00:00:00 2001 From: myk002 Date: Fri, 2 Dec 2022 16:38:12 -0800 Subject: [PATCH 1/3] remove command-prompt --- docs/images/command-prompt.png | Bin 4152 -> 0 bytes docs/plugins/command-prompt.rst | 22 -- plugins/CMakeLists.txt | 1 - plugins/command-prompt.cpp | 359 -------------------------------- 4 files changed, 382 deletions(-) delete mode 100644 docs/images/command-prompt.png delete mode 100644 docs/plugins/command-prompt.rst delete mode 100644 plugins/command-prompt.cpp diff --git a/docs/images/command-prompt.png b/docs/images/command-prompt.png deleted file mode 100644 index 4897609e150a6ce5bb174ca4c2632ef7ac6bb54e..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 4152 zcmYjVc|26#-@mh9W^5Oce8VM_+_4lTksDK{NVepnQkf!YqO|F&8Aawqm~&-v22SjTDbmtt~Rwdc=TM#O^=u@lDE1}ZL_<5)lrpEzUUyt&0Vkb z__fO_Ii2*YUdA#lrOi=BiCswXsfJx zpZDfvfm4plyia9IfBvP+ABBxW{EmXJKTKuHUn7hrb#s9mdDuXvd@V&6s_`MQ&py#Z z7&M;5DtyCOt^Zm9xjjR0Ez^s+BwO3S==O}RfV_%MTXa~e>3!HD!FGx~8peB|$RmNpS({gp zPmX^Z#Y-7(DJL6Ew#PX1rgEc8by5VBCxqWW-&=Xgu?y05UtOUD{T5o*>nwi?X!Qy9 zTlFC2r5Q*!{HC~HdOjhH78S10lw0q=3`FK&J@wr!{u?@@=)OA6kCyti%xWXF`^J|O zPjr`EJx(@~SasDaU(DM`L!N(RDet-o``%(uQvxe%QLr)_-ry9<$td~@cyH0AD>Yak7`8#R>2 zmKtB=YOk0|m5P$5Ytcn^SMK^%!0Xc7y4jFtQSXjCE;P-?&zL?kzrN{l*t+|RD$LRD zriZYGTO4K~sAc?~KI`5b_-ST~{ZHNO0AWze+f9FC#N(HPVn=cL(095zJ~@becT`~M zwIzGLjXIb;ue|{dY6_QsR_RIB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+ zygbvM%0j4hmyX9ab4vejF%CZFpr}5LYDWn;F>ZaTL{+UJEh5dtX3C zs0p%jB*EUZtsApP5VBQg;J>v2{>e$3$pmq~!;+^8@fvM(sdX;Tp;X*zhq%*%Cnceq z=)1baCL(!;j(U?zfyEtzCpGVO0)hW}aVLI)=NiQXkHu|re;<&9x+Gu4;w1-`-W&B3 zORis*`RRrT+Xv9whp!Z#9|}g`*c=s&S; zm4u51v9nNwDcHaLt>!LI$9F)nY_%GgcSGMFIyUA+LI)~E{^ZA=NBmB=Dr_nfqARU>uupLWiO1aHG;l4E?ognU;^;9Yu?Fbv+IX72AJxmOVX>OTGXDZ zQTYge;1*e4aYenSkef~x$9FF0aBeD07^eA57@6x+!z?I@E2?@qa)OA*Q+(y<^V(!` zDd!VOa95QKz3c#~R*{UvP<_1I!RUN_q`g$OWUGyjtc+9Xg}WQ>DK7?!c{H>pm_X+pkFgg;Y~Xy00?8TE0t>PnXor5c9$}5Jkl)-(al|LS7YO8^ t%Su|!e` or `:rb ` -portions of the command already filled in. - -Also see `gui/quickcmd` for a different take on running commands from the UI. - -.. image:: ../images/command-prompt.png diff --git a/plugins/CMakeLists.txt b/plugins/CMakeLists.txt index 465a68eb1..3ad19efb4 100644 --- a/plugins/CMakeLists.txt +++ b/plugins/CMakeLists.txt @@ -104,7 +104,6 @@ if(BUILD_SUPPORTED) dfhack_plugin(cleanconst cleanconst.cpp) dfhack_plugin(cleaners cleaners.cpp) dfhack_plugin(cleanowned cleanowned.cpp) - dfhack_plugin(command-prompt command-prompt.cpp) dfhack_plugin(confirm confirm.cpp LINK_LIBRARIES lua) dfhack_plugin(createitem createitem.cpp) dfhack_plugin(cursecheck cursecheck.cpp) diff --git a/plugins/command-prompt.cpp b/plugins/command-prompt.cpp deleted file mode 100644 index 433b8fba3..000000000 --- a/plugins/command-prompt.cpp +++ /dev/null @@ -1,359 +0,0 @@ -// command-prompt: A one-line command entry at the top of the screen for quick commands - -#include "Core.h" -#include -#include -#include -#include -#include - -#include -#include - -#include -#include -#include -#include -#include - -#include "df/enabler.h" -#include "df/graphic.h" -#include "df/interface_key.h" -#include "df/ui.h" - -using namespace DFHack; -using namespace df::enums; - -DFHACK_PLUGIN("command-prompt"); -REQUIRE_GLOBAL(ui); -REQUIRE_GLOBAL(gps); -REQUIRE_GLOBAL(enabler); - -std::vector command_history; - -class viewscreen_commandpromptst; -class prompt_ostream:public buffered_color_ostream -{ - viewscreen_commandpromptst *parent_; - protected: - void flush_proxy(); - public: - prompt_ostream(viewscreen_commandpromptst* parent) - : parent_(parent) - {} - bool empty() { return buffer.empty(); } -}; -class viewscreen_commandpromptst : public dfhack_viewscreen { -public: - void feed(std::set *events); - - void logic() { - dfhack_viewscreen::logic(); - } - - void render(); - void help() {} - int8_t movies_okay() { return 0; } - - df::unit* getSelectedUnit() { return Gui::getAnyUnit(parent); } - df::item* getSelectedItem() { return Gui::getAnyItem(parent); } - df::building* getSelectedBuilding() { return Gui::getAnyBuilding(parent); } - df::plant* getSelectedPlant() { return Gui::getAnyPlant(parent); } - - std::string getFocusString() { return "commandprompt"; } - viewscreen_commandpromptst(std::string entry) - : submitted(false), is_response(false) - { - show_fps = gps->display_frames; - gps->display_frames = 0; - cursor_pos = entry.size(); - frame = 0; - history_idx = command_history.size(); - if (history_idx > 0) - { - if (command_history[history_idx - 1] == "") - { - command_history.pop_back(); - history_idx--; - } - } - command_history.push_back(entry); - } - ~viewscreen_commandpromptst() - { - gps->display_frames = show_fps; - } - - void add_response(color_value v, std::string s) - { - std::stringstream ss(s); - std::string part; - while (std::getline(ss, part)) - { - responses.push_back(std::make_pair(v, part + '\n')); - } - } - std::string get_entry() - { - return command_history[history_idx]; - } - void set_entry(std::string entry) - { - command_history[history_idx] = entry; - } - void back_word() - { - std::string entry = get_entry(); - if (cursor_pos == 0) - return; - cursor_pos--; - while (cursor_pos > 0 && !isalnum(entry[cursor_pos])) - cursor_pos--; - while (cursor_pos > 0 && isalnum(entry[cursor_pos])) - cursor_pos--; - if (!isalnum(entry[cursor_pos]) && cursor_pos != 0) - cursor_pos++; - } - void forward_word() - { - std::string entry = get_entry(); - int len = entry.size(); - if (cursor_pos == len) - return; - cursor_pos++; - while (cursor_pos <= len && !isalnum(entry[cursor_pos])) - cursor_pos++; - while (cursor_pos <= len && isalnum(entry[cursor_pos])) - cursor_pos++; - if (cursor_pos > len) - cursor_pos = len; - } - -protected: - std::list > responses; - int cursor_pos; - int history_idx; - bool submitted; - bool is_response; - bool show_fps; - int frame; - void submit(); -}; -void prompt_ostream::flush_proxy() -{ - if (buffer.empty()) - return; - for(auto it = buffer.begin(); it != buffer.end(); it++) - parent_->add_response(it->first, it->second); - buffer.clear(); -} -void viewscreen_commandpromptst::render() -{ - ++frame; - if (frame >= enabler->gfps) - frame = 0; - if (Screen::isDismissed(this)) - return; - - dfhack_viewscreen::render(); - - auto dim = Screen::getWindowSize(); - parent->render(); - if (is_response) - { - int y = 0; - for (auto &response : responses) - { - std::vector lines; - word_wrap(&lines, response.second, dim.x); - for (auto &line : lines) - { - Screen::fillRect(Screen::Pen(' ', 7, 0), 0, y, dim.x, y); - Screen::paintString(Screen::Pen(' ', response.first, 0), 0, y, line); - if (++y >= dim.y) - return; - } - } - } - else - { - std::string entry = get_entry(); - Screen::fillRect(Screen::Pen(' ', 7, 0), 0, 0, dim.x, 0); - Screen::paintString(Screen::Pen(' ', 7, 0), 0, 0, "[DFHack]#"); - std::string cursor = (frame < enabler->gfps / 2) ? "_" : " "; - if (cursor_pos < dim.x - 10) - { - Screen::paintString(Screen::Pen(' ', 7, 0), 10, 0, entry); - if (int16_t(entry.size()) > dim.x - 10) - Screen::paintTile(Screen::Pen('\032', 7, 0), dim.x - 1, 0); - if (cursor != " ") - Screen::paintString(Screen::Pen(' ', 10, 0), 10 + cursor_pos, 0, cursor); - } - else - { - size_t start = cursor_pos - dim.x + 10 + 1; - Screen::paintTile(Screen::Pen('\033', 7, 0), 9, 0); - Screen::paintString(Screen::Pen(' ', 7, 0), 10, 0, entry.substr(start)); - if (cursor != " ") - Screen::paintString(Screen::Pen(' ', 10, 0), dim.x - 1, 0, cursor); - } - } -} -void viewscreen_commandpromptst::submit() -{ - CoreSuspendClaimer suspend; - if (is_response) - { - Screen::dismiss(this); - return; - } - if (submitted) - return; - submitted = true; - prompt_ostream out(this); - { - Screen::Hide hide_guard(this, Screen::Hide::RESTORE_AT_TOP); - Core::getInstance().runCommand(out, get_entry()); - } - if (out.empty() && responses.empty()) - Screen::dismiss(this); - else - { - is_response = true; - } -} -void viewscreen_commandpromptst::feed(std::set *events) -{ - int old_pos = cursor_pos; - std::string entry = get_entry(); - bool leave_all = events->count(interface_key::LEAVESCREEN_ALL); - if (leave_all || events->count(interface_key::LEAVESCREEN)) - { - events->clear(); - Screen::dismiss(this); - if (leave_all) - { - events->insert(interface_key::LEAVESCREEN); - parent->feed(events); - events->clear(); - } - //if (command_history.size() && !entry.size()) - // command_history.pop_back(); - return; - } - if (events->count(interface_key::SELECT)) - { - submit(); - return; - } - if (is_response) - return; - for (auto it = events->begin(); it != events->end(); ++it) - { - auto key = *it; - if (key == interface_key::STRING_A000) //delete? - { - if (entry.size() && cursor_pos > 0) - { - entry.erase(cursor_pos - 1, 1); - cursor_pos--; - } - if (size_t(cursor_pos) > entry.size()) - cursor_pos = entry.size(); - continue; - } - int charcode = Screen::keyToChar(key); - if (charcode > 0) - { - entry.insert(cursor_pos, 1, char(charcode)); - cursor_pos++; - set_entry(entry); - return; - } - } - // Prevent number keys from moving cursor - if (events->count(interface_key::CURSOR_RIGHT)) - { - cursor_pos++; - if (size_t(cursor_pos) > entry.size()) - cursor_pos = entry.size(); - } - else if (events->count(interface_key::CURSOR_LEFT)) - { - cursor_pos--; - if (cursor_pos < 0) cursor_pos = 0; - } - else if (events->count(interface_key::CURSOR_RIGHT_FAST)) - { - forward_word(); - } - else if (events->count(interface_key::CURSOR_LEFT_FAST)) - { - back_word(); - } - else if (events->count(interface_key::CUSTOM_CTRL_A)) - { - cursor_pos = 0; - } - else if (events->count(interface_key::CUSTOM_CTRL_E)) - { - cursor_pos = entry.size(); - } - else if (events->count(interface_key::CURSOR_UP)) - { - history_idx--; - if (history_idx < 0) - history_idx = 0; - entry = get_entry(); - cursor_pos = entry.size(); - } - else if (events->count(interface_key::CURSOR_DOWN)) - { - if (size_t(history_idx) < command_history.size() - 1) - { - history_idx++; - if (size_t(history_idx) >= command_history.size()) - history_idx = command_history.size() - 1; - entry = get_entry(); - cursor_pos = entry.size(); - } - } - set_entry(entry); - if (old_pos != cursor_pos) - frame = 0; - -} - -command_result show_prompt(color_ostream &out, std::vector & parameters) -{ - if (Gui::getCurFocus(true) == "dfhack/commandprompt") - { - Screen::dismiss(Gui::getCurViewscreen(true)); - return CR_OK; - } - std::string params; - for(size_t i = 0; i < parameters.size(); i++) - params += parameters[i] + " "; - Screen::show(dts::make_unique(params), plugin_self); - return CR_OK; -} - -DFhackCExport command_result plugin_init(color_ostream &out, std::vector &commands) -{ - commands.push_back(PluginCommand( - "command-prompt", - "Allows you to run a DFHack command from in-game.", - show_prompt, - Gui::anywhere_hotkey)); - return CR_OK; -} - -DFhackCExport command_result plugin_onstatechange(color_ostream &out, state_change_event e) -{ - return CR_OK; -} - -DFhackCExport command_result plugin_shutdown(color_ostream &out) -{ - return CR_OK; -} From f6c1b7880467fa09d474fca45575206adcf2409a Mon Sep 17 00:00:00 2001 From: myk002 Date: Fri, 2 Dec 2022 16:39:18 -0800 Subject: [PATCH 2/3] add entry in Removed docs --- docs/about/Removed.rst | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/docs/about/Removed.rst b/docs/about/Removed.rst index a5fa29a1d..072bd32ab 100644 --- a/docs/about/Removed.rst +++ b/docs/about/Removed.rst @@ -10,6 +10,12 @@ work (e.g. links from the `changelog`). :local: :depth: 1 +.. _command-prompt: + +command-prompt +============== +Replaced by `gui/launcher --minimal `. + .. _deteriorateclothes: deteriorateclothes From a7f7a8d0a1d291ef84e4b46ef31aed425adf9d4d Mon Sep 17 00:00:00 2001 From: myk002 Date: Fri, 2 Dec 2022 16:39:27 -0800 Subject: [PATCH 3/3] remap command-prompt's keybinding to gui/launcher --- data/init/dfhack.keybindings.init | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/data/init/dfhack.keybindings.init b/data/init/dfhack.keybindings.init index f8a35f874..478b78753 100644 --- a/data/init/dfhack.keybindings.init +++ b/data/init/dfhack.keybindings.init @@ -11,13 +11,11 @@ # the GUI command launcher (two bindings since some keyboards don't have `) keybinding add ` gui/launcher keybinding add Ctrl-Shift-D gui/launcher +keybinding add Ctrl-Shift-P "gui/launcher --minimal" # show hotkey popup menu keybinding add Ctrl-Shift-C hotkeys -# a dfhack prompt in df. Sublime text like. -keybinding add Ctrl-Shift-P command-prompt - # on-screen keyboard keybinding add Ctrl-Shift-K gui/cp437-table