aboutsummaryrefslogtreecommitdiff
path: root/src/cmd_manipulate.cc
diff options
context:
space:
mode:
Diffstat (limited to 'src/cmd_manipulate.cc')
-rw-r--r--src/cmd_manipulate.cc21
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 "";
+ }
}