summaryrefslogtreecommitdiff
path: root/src/cmd3.cc
diff options
context:
space:
mode:
authorBardur Arantsson <bardur@scientician.net>2016-02-13 13:56:52 +0100
committerBardur Arantsson <bardur@scientician.net>2016-02-13 13:56:52 +0100
commit4d237a87eb76eb4c6bcc5d8cbf7544a8f3184f30 (patch)
tree5e87923522f444880a6be4239e162c16312408a4 /src/cmd3.cc
parentf13c5091e4864e957c83a35621365c8b510b80ba (diff)
Reduce file-open/close boilerplate and simplify formatting
- We introduce a show_string() which will allow us to go without actually writing a file if we want to later. - Use cppformat to simplify the output formatting.
Diffstat (limited to 'src/cmd3.cc')
-rw-r--r--src/cmd3.cc31
1 files changed, 11 insertions, 20 deletions
diff --git a/src/cmd3.cc b/src/cmd3.cc
index d6ede5a8..ef0dfa28 100644
--- a/src/cmd3.cc
+++ b/src/cmd3.cc
@@ -40,7 +40,7 @@
#include <cassert>
#include <algorithm>
-#include <boost/filesystem.hpp>
+#include <format.h>
#include <memory>
#include <utility>
@@ -2010,29 +2010,23 @@ void do_cmd_cli(void)
*/
void do_cmd_cli_help()
{
- int i, j;
-
- /* Temporary file */
- auto const file_name_p = boost::filesystem::unique_path();
- auto const file_name = file_name_p.c_str();
+ fmt::MemoryWriter w;
+ for (int i = 0, j = -1; i < cli_total; i++)
+ {
+ if (j < i - 1)
+ {
+ w << "/";
+ }
- /* Open a new file */
- FILE *fff = my_fopen(file_name, "w");
+ w.write("[[[[[G{}]", cli_info[i].comm);
- for (i = 0, j = -1; i < cli_total; i++)
- {
- if (j < i - 1) fprintf(fff, "/");
- fprintf(fff, "[[[[[G%s]", cli_info[i].comm);
if (cli_info[i].descrip != cli_info[i + 1].descrip)
{
- fprintf(fff, " %s\n", cli_info[i].descrip);
+ w.write(" {}\n", cli_info[i].descrip);
j = i;
}
}
- /* Close the file */
- my_fclose(fff);
-
/* Enter "icky" mode */
character_icky = TRUE;
@@ -2040,16 +2034,13 @@ void do_cmd_cli_help()
Term_save();
/* Display the file contents */
- show_file(file_name, "Command line help");
+ show_string(w.c_str(), "Command line help");
/* Restore the screen */
Term_load();
/* Leave "icky" mode */
character_icky = FALSE;
-
- /* Remove the file */
- fd_kill(file_name);
}