From 5ed030a38810e4a3bb9c969db6892065581340c6 Mon Sep 17 00:00:00 2001 From: Your Name Date: Thu, 6 May 2021 15:12:39 -0400 Subject: Implemented edit method --- src/cmd_manipulate.cc | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) (limited to 'src/cmd_manipulate.cc') 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 #include +#include +#include +#include namespace fs = std::filesystem; @@ -183,4 +187,21 @@ namespace cmd { } return text.str(); } + + std::string edit(std::vector args) { + auto p = getTruePath(args[0]); + auto e = utils::instantiate(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{in}, {}); + e->setText(newText); + utils::saveJson(*e, p); + return ""; + } } -- cgit v1.2.3