diff options
author | Your Name <you@example.com> | 2021-05-06 15:12:39 -0400 |
---|---|---|
committer | Your Name <you@example.com> | 2021-05-06 15:12:39 -0400 |
commit | 5ed030a38810e4a3bb9c969db6892065581340c6 (patch) | |
tree | eac8fa93a221d7b4cbccacd18adf7cb83282e04f /src/cmd_manipulate.cc | |
parent | 9f3802690f9dd9452e96d1d7a879291978d66e35 (diff) | |
download | dmtool-5ed030a38810e4a3bb9c969db6892065581340c6.tar.gz dmtool-5ed030a38810e4a3bb9c969db6892065581340c6.tar.bz2 dmtool-5ed030a38810e4a3bb9c969db6892065581340c6.zip |
Implemented edit method
Diffstat (limited to 'src/cmd_manipulate.cc')
-rw-r--r-- | src/cmd_manipulate.cc | 21 |
1 files changed, 21 insertions, 0 deletions
diff --git a/src/cmd_manipulate.cc b/src/cmd_manipulate.cc index fe59ebf..1300008 100644 --- a/src/cmd_manipulate.cc +++ b/src/cmd_manipulate.cc @@ -3,8 +3,12 @@ #include "creature.h" #include "item.h" #include "spellcasting.h" +#include "settings.h" #include <sstream> #include <memory> +#include <cstdlib> +#include <fstream> +#include <iterator> namespace fs = std::filesystem; @@ -183,4 +187,21 @@ namespace cmd { } return text.str(); } + + std::string edit(std::vector<std::string> args) { + auto p = getTruePath(args[0]); + auto e = utils::instantiate<entry::Entry>(p); + auto editor = settings::getString("editor"); + // General workflow: copy notes (text) from e to a temp file, edit it, then copy back. + fs::path tmp("/tmp/dmtool.tmp"); + std::ofstream out(tmp); + out << e->Entry::getText(); + out.close(); + std::system((editor + " " + tmp.string()).c_str()); + std::ifstream in(tmp); + std::string newText(std::istreambuf_iterator<char>{in}, {}); + e->setText(newText); + utils::saveJson(*e, p); + return ""; + } } |