From 1fcaac9d2ec39ebc9f32657c867589162dffd0b8 Mon Sep 17 00:00:00 2001 From: lethosor Date: Sun, 25 May 2014 21:52:16 -0400 Subject: [PATCH 1/9] OS X Console: Implement back/forward one word escape sequences --- library/Console-darwin.cpp | 36 ++++++++++++++++++++++++++++++++++-- 1 file changed, 34 insertions(+), 2 deletions(-) diff --git a/library/Console-darwin.cpp b/library/Console-darwin.cpp index 86cd657a1..081d4833e 100644 --- a/library/Console-darwin.cpp +++ b/library/Console-darwin.cpp @@ -478,14 +478,46 @@ namespace DFHack break; case 27: // escape sequence lock->unlock(); - if(!read_char(seq[0]) || !read_char(seq[1])) + if (!read_char(seq[0])) { lock->lock(); return -2; } lock->lock(); - if(seq[0] == '[') + if (seq[0] == 'b') { + // Back one word + if (raw_cursor == 0) + break; + raw_cursor--; + while (raw_cursor > 0 && !isalnum(raw_buffer[raw_cursor])) + raw_cursor--; + while (raw_cursor > 0 && isalnum(raw_buffer[raw_cursor])) + raw_cursor--; + if (!isalnum(raw_buffer[raw_cursor])) + raw_cursor++; + prompt_refresh(); + } + else if (seq[0] == 'f') + { + // Forward one word + int len = raw_buffer.size(); + if (raw_cursor == len) + break; + raw_cursor++; + while (raw_cursor <= len && !isalnum(raw_buffer[raw_cursor])) + raw_cursor++; + while (raw_cursor <= len && isalnum(raw_buffer[raw_cursor])) + raw_cursor++; + prompt_refresh(); + } + else if(seq[0] == '[') + { + if (!read_char(seq[1])) + { + lock->lock(); + return -2; + } if (seq[1] == 'D') { left_arrow: From 58b9c02ce5dc518c0904cc405fe8128d7d1592f6 Mon Sep 17 00:00:00 2001 From: lethosor Date: Sun, 25 May 2014 22:10:40 -0400 Subject: [PATCH 2/9] Migrate esc-b/f sequences to Linux --- library/Console-linux.cpp | 36 ++++++++++++++++++++++++++++++++++-- 1 file changed, 34 insertions(+), 2 deletions(-) diff --git a/library/Console-linux.cpp b/library/Console-linux.cpp index f32fa1c2a..a49b5dbdd 100644 --- a/library/Console-linux.cpp +++ b/library/Console-linux.cpp @@ -480,14 +480,46 @@ namespace DFHack break; case 27: // escape sequence lock->unlock(); - if(!read_char(seq[0]) || !read_char(seq[1])) + if (!read_char(seq[0])) { lock->lock(); return -2; } lock->lock(); - if(seq[0] == '[') + if (seq[0] == 'b') { + // Back one word + if (raw_cursor == 0) + break; + raw_cursor--; + while (raw_cursor > 0 && !isalnum(raw_buffer[raw_cursor])) + raw_cursor--; + while (raw_cursor > 0 && isalnum(raw_buffer[raw_cursor])) + raw_cursor--; + if (!isalnum(raw_buffer[raw_cursor])) + raw_cursor++; + prompt_refresh(); + } + else if (seq[0] == 'f') + { + // Forward one word + int len = raw_buffer.size(); + if (raw_cursor == len) + break; + raw_cursor++; + while (raw_cursor <= len && !isalnum(raw_buffer[raw_cursor])) + raw_cursor++; + while (raw_cursor <= len && isalnum(raw_buffer[raw_cursor])) + raw_cursor++; + prompt_refresh(); + } + else if(seq[0] == '[') + { + if (!read_char(seq[1])) + { + lock->lock(); + return -2; + } if (seq[1] == 'D') { left_arrow: From d320fe71d11274d33c1d8ff3f59e8122478fdb4c Mon Sep 17 00:00:00 2001 From: lethosor Date: Sun, 25 May 2014 23:39:34 -0400 Subject: [PATCH 3/9] Implement extended arrow key sequences --- library/Console-darwin.cpp | 69 ++++++++++++++++++++++++++------------ 1 file changed, 48 insertions(+), 21 deletions(-) diff --git a/library/Console-darwin.cpp b/library/Console-darwin.cpp index 081d4833e..f36973d5c 100644 --- a/library/Console-darwin.cpp +++ b/library/Console-darwin.cpp @@ -305,6 +305,33 @@ namespace DFHack } /// beep. maybe? //void beep (void); + void back_word() + { + if (raw_cursor == 0) + return; + raw_cursor--; + while (raw_cursor > 0 && !isalnum(raw_buffer[raw_cursor])) + raw_cursor--; + while (raw_cursor > 0 && isalnum(raw_buffer[raw_cursor])) + raw_cursor--; + if (!isalnum(raw_buffer[raw_cursor]) && raw_cursor != 0) + raw_cursor++; + prompt_refresh(); + } + void forward_word() + { + int len = raw_buffer.size(); + if (raw_cursor == len) + return; + raw_cursor++; + while (raw_cursor <= len && !isalnum(raw_buffer[raw_cursor])) + raw_cursor++; + while (raw_cursor <= len && isalnum(raw_buffer[raw_cursor])) + raw_cursor++; + if (raw_cursor > len) + raw_cursor = len; + prompt_refresh(); + } /// A simple line edit (raw mode) int lineedit(const std::string& prompt, std::string& output, recursive_mutex * lock, CommandHistory & ch) { @@ -486,30 +513,11 @@ namespace DFHack lock->lock(); if (seq[0] == 'b') { - // Back one word - if (raw_cursor == 0) - break; - raw_cursor--; - while (raw_cursor > 0 && !isalnum(raw_buffer[raw_cursor])) - raw_cursor--; - while (raw_cursor > 0 && isalnum(raw_buffer[raw_cursor])) - raw_cursor--; - if (!isalnum(raw_buffer[raw_cursor])) - raw_cursor++; - prompt_refresh(); + back_word(); } else if (seq[0] == 'f') { - // Forward one word - int len = raw_buffer.size(); - if (raw_cursor == len) - break; - raw_cursor++; - while (raw_cursor <= len && !isalnum(raw_buffer[raw_cursor])) - raw_cursor++; - while (raw_cursor <= len && isalnum(raw_buffer[raw_cursor])) - raw_cursor++; - prompt_refresh(); + forward_word(); } else if(seq[0] == '[') { @@ -577,6 +585,7 @@ namespace DFHack else if (seq[1] > '0' && seq[1] < '7') { // extended escape + unsigned char seq3[3]; lock->unlock(); if(!read_char(seq2)) { @@ -593,6 +602,24 @@ namespace DFHack prompt_refresh(); } } + if (!read_char(seq3[0]) || !read_char(seq3[1])) + { + lock->lock(); + return -2; + } + if (seq2 == ';') + { + // Format: esc [ n ; n DIRECTION + // Ignore first character (second "n") + if (seq3[1] == 'C') + { + forward_word(); + } + else if (seq3[1] == 'D') + { + back_word(); + } + } } } break; From bdca1ee7095ddc2dd5c6e4f8d84812cf69b774a6 Mon Sep 17 00:00:00 2001 From: lethosor Date: Mon, 26 May 2014 10:03:28 -0400 Subject: [PATCH 4/9] Linux: Extended back/forward word sequences --- library/Console-linux.cpp | 69 +++++++++++++++++++++++++++------------ 1 file changed, 48 insertions(+), 21 deletions(-) diff --git a/library/Console-linux.cpp b/library/Console-linux.cpp index a49b5dbdd..d4005af3c 100644 --- a/library/Console-linux.cpp +++ b/library/Console-linux.cpp @@ -307,6 +307,33 @@ namespace DFHack } /// beep. maybe? //void beep (void); + void back_word() + { + if (raw_cursor == 0) + return; + raw_cursor--; + while (raw_cursor > 0 && !isalnum(raw_buffer[raw_cursor])) + raw_cursor--; + while (raw_cursor > 0 && isalnum(raw_buffer[raw_cursor])) + raw_cursor--; + if (!isalnum(raw_buffer[raw_cursor]) && raw_cursor != 0) + raw_cursor++; + prompt_refresh(); + } + void forward_word() + { + int len = raw_buffer.size(); + if (raw_cursor == len) + return; + raw_cursor++; + while (raw_cursor <= len && !isalnum(raw_buffer[raw_cursor])) + raw_cursor++; + while (raw_cursor <= len && isalnum(raw_buffer[raw_cursor])) + raw_cursor++; + if (raw_cursor > len) + raw_cursor = len; + prompt_refresh(); + } /// A simple line edit (raw mode) int lineedit(const std::string& prompt, std::string& output, recursive_mutex * lock, CommandHistory & ch) { @@ -488,30 +515,11 @@ namespace DFHack lock->lock(); if (seq[0] == 'b') { - // Back one word - if (raw_cursor == 0) - break; - raw_cursor--; - while (raw_cursor > 0 && !isalnum(raw_buffer[raw_cursor])) - raw_cursor--; - while (raw_cursor > 0 && isalnum(raw_buffer[raw_cursor])) - raw_cursor--; - if (!isalnum(raw_buffer[raw_cursor])) - raw_cursor++; - prompt_refresh(); + back_word(); } else if (seq[0] == 'f') { - // Forward one word - int len = raw_buffer.size(); - if (raw_cursor == len) - break; - raw_cursor++; - while (raw_cursor <= len && !isalnum(raw_buffer[raw_cursor])) - raw_cursor++; - while (raw_cursor <= len && isalnum(raw_buffer[raw_cursor])) - raw_cursor++; - prompt_refresh(); + forward_word(); } else if(seq[0] == '[') { @@ -579,6 +587,7 @@ namespace DFHack else if (seq[1] > '0' && seq[1] < '7') { // extended escape + unsigned char seq3[3]; lock->unlock(); if(!read_char(seq2)) { @@ -595,6 +604,24 @@ namespace DFHack prompt_refresh(); } } + if (!read_char(seq3[0]) || !read_char(seq3[1])) + { + lock->lock(); + return -2; + } + if (seq2 == ';') + { + // Format: esc [ n ; n DIRECTION + // Ignore first character (second "n") + if (seq3[1] == 'C') + { + forward_word(); + } + else if (seq3[1] == 'D') + { + back_word(); + } + } } } break; From 49bbd41bc38392cefaed869e89428a5cc0e74b91 Mon Sep 17 00:00:00 2001 From: Warmist Date: Mon, 2 Jun 2014 17:57:59 +0300 Subject: [PATCH 5/9] Added a way to change the mod install directory (and changed the default to hack/mods) and added simpler way to add to init.lua --- scripts/gui/mod-manager.lua | 52 +++++++++++++++++++++++++++++++++---- 1 file changed, 47 insertions(+), 5 deletions(-) diff --git a/scripts/gui/mod-manager.lua b/scripts/gui/mod-manager.lua index 6d56d88a6..210109807 100644 --- a/scripts/gui/mod-manager.lua +++ b/scripts/gui/mod-manager.lua @@ -1,8 +1,29 @@ +-- a graphical mod manager for df local gui=require 'gui' local widgets=require 'gui.widgets' local entity_file=dfhack.getDFPath().."/raw/objects/entity_default.txt" local init_file=dfhack.getDFPath().."/raw/init.lua" +local mod_dir=dfhack.getDFPath().."/hack/mods" +--[[ mod format: lua script that defines: + name - a name that is displayed in list + author - mod author, also displayed + description - mod description + OPTIONAL: + raws_list - a list (table) of file names that need to be copied over to df raws + patch_entity - a chunk of text to patch entity TODO: add settings to which entities to add + patch_init - a chunk of lua to add to lua init + patch_dofile - a list (table) of files to add to lua init as "dofile" + patch_files - a table of files to patch: + filename - a filename (in raws folder) to patch + patch - what to add + after - a string after which to insert + MORE OPTIONAL: + guard - a token that is used in raw files to find editions and remove them on uninstall + guard_init - a token for lua file + [pre|post]_(un)install - callback functions. Can trigger more complicated behavior +]] + function fileExists(filename) local file=io.open(filename,"rb") if file==nil then @@ -12,6 +33,10 @@ function fileExists(filename) return true end end +if not fileExists(init_file) then + local initFile=io.open(initFileName,"a") + initFile:close() +end function copyFile(from,to) --oh so primitive local filefrom=io.open(from,"rb") local fileto=io.open(to,"w+b") @@ -27,6 +52,16 @@ function patchInit(initFileName,patch_guard,code) code,patch_guard[2])) initFile:close() end +function patchDofile( initFileName,patch_guard,dofile_list ) + local initFile=io.open(initFileName,"a") + initFile:write(patch_guard[1].."\n") + for _,v in ipairs(dofile_list) do + local fixed_path=mod_dir:gsub("\\","/") + initFile:write(string.format("dofile('%s/%s')\n",fixed_path,v)) + end + initFile:write(patch_guard[2].."\n") + initFile:close() +end function patchFile(file_name,patch_guard,after_string,code) local input_lines=patch_guard[1].."\n"..code.."\n"..patch_guard[2] @@ -109,15 +144,19 @@ manager=defclass(manager,gui.FramedScreen) function manager:init(args) self.mods={} local mods=self.mods - local mlist=dfhack.internal.getDir("mods") + local mlist=dfhack.internal.getDir(mod_dir) + + if #mlist==0 then + qerror("Mod directory not found! Are you sure it is in:"..mod_dir) + end for k,v in ipairs(mlist) do if v~="." and v~=".." then - local f,modData=pcall(dofile,"mods/".. v .. "/init.lua") + local f,modData=pcall(dofile,mod_dir.."/".. v .. "/init.lua") if f then mods[modData.name]=modData modData.guard=modData.guard or {">>"..modData.name.." patch","< Date: Fri, 6 Jun 2014 14:24:57 -0500 Subject: [PATCH 6/9] Sync with structures change --- plugins/strangemood.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/plugins/strangemood.cpp b/plugins/strangemood.cpp index 35d1e15b8..81840b67b 100644 --- a/plugins/strangemood.cpp +++ b/plugins/strangemood.cpp @@ -126,7 +126,7 @@ int getCreatedMetalBars (int32_t idx) return 0; } -void selectWord (const df::world_raws::T_language::T_word_table &table, int32_t &word, df::enum_field &part, int mode) +void selectWord (const df::language_word_table &table, int32_t &word, df::enum_field &part, int mode) { if (table.parts[mode].size()) { @@ -142,7 +142,7 @@ void selectWord (const df::world_raws::T_language::T_word_table &table, int32_t } } -void generateName(df::language_name &output, int language, int mode, const df::world_raws::T_language::T_word_table &table1, const df::world_raws::T_language::T_word_table &table2) +void generateName(df::language_name &output, int language, int mode, const df::language_word_table &table1, const df::language_word_table &table2) { for (int i = 0; i < 100; i++) { From 0e3fb79f0e620a2e7cc4c8557b6f2d795e24e919 Mon Sep 17 00:00:00 2001 From: Alexander Gavrilov Date: Tue, 10 Jun 2014 12:52:17 +0400 Subject: [PATCH 7/9] Update structures --- library/xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/library/xml b/library/xml index 93f89c7c5..851f52d5e 160000 --- a/library/xml +++ b/library/xml @@ -1 +1 @@ -Subproject commit 93f89c7c56f366ac8f68e883c9f853a76e12f00a +Subproject commit 851f52d5e9eae6fc81adadd10e53bd2cc42bfd21 From 08b4279c4dc5334658a43f6a1a6eba7bb1095ac1 Mon Sep 17 00:00:00 2001 From: Alexander Gavrilov Date: Tue, 10 Jun 2014 13:10:10 +0400 Subject: [PATCH 8/9] Document better how to access fields of the interposed class. --- library/include/VTableInterpose.h | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/library/include/VTableInterpose.h b/library/include/VTableInterpose.h index f93eb4176..ec950bfe2 100644 --- a/library/include/VTableInterpose.h +++ b/library/include/VTableInterpose.h @@ -42,12 +42,16 @@ namespace DFHack struct my_hack : df::someclass { typedef df::someclass interpose_base; - DEFINE_VMETHOD_INTERPOSE(void, foo, (int arg)) { + // You may define additional methods here, but NOT non-static fields + + DEFINE_VMETHOD_INTERPOSE(int, foo, (int arg)) { // If needed by the code, claim the suspend lock. // DO NOT USE THE USUAL CoreSuspender, OR IT WILL DEADLOCK! // CoreSuspendClaimer suspend; ... - INTERPOSE_NEXT(foo)(arg) // call the original + ... this->field ... // access fields of the df::someclass object + ... + int orig_retval = INTERPOSE_NEXT(foo)(arg); // call the original method ... } }; From da6219e5a187e9fd58e2a3a820968a9b5bcd0af9 Mon Sep 17 00:00:00 2001 From: Alexander Gavrilov Date: Tue, 10 Jun 2014 13:32:15 +0400 Subject: [PATCH 9/9] Mention a couple of features in NEWS --- NEWS | 2 ++ 1 file changed, 2 insertions(+) diff --git a/NEWS b/NEWS index 757a9277f..75c751900 100644 --- a/NEWS +++ b/NEWS @@ -7,6 +7,7 @@ DFHack future - support for multiple raw/init.d/*.lua init scripts in one save. - eventful now has a more friendly way of making custom sidebars - new plugin: building-hacks. Allows to add custom functionality and/or animations to buildings. + - on Linux and OSX the console now supports moving the cursor back and forward by a whole word. New scripts: - gui/mod-manager: allows installing/uninstalling mods into df from df/mods directory. @@ -28,6 +29,7 @@ DFHack future New plugins: - rendermax: replace the renderer with something else. Most interesting is "rendermax light"- a lighting engine for df. + - stockflow (by eswald): queues manager jobs of the configured type based on the state of a stockpile. Misc improvements: - digfort: improved csv parsing, add start() comment handling