From 7487bab9ae12fb7e0586a88684ce43b5392aa0f1 Mon Sep 17 00:00:00 2001 From: Timofey Date: Wed, 10 Aug 2022 22:02:39 +0300 Subject: [PATCH] Add realization open editor --- src/utils/editor.cpp | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-) diff --git a/src/utils/editor.cpp b/src/utils/editor.cpp index aff39ef..01731ed 100644 --- a/src/utils/editor.cpp +++ b/src/utils/editor.cpp @@ -1,9 +1,22 @@ #include +#define SIGPIPE_ALWAYS_IGNORE +#include +#undef SIGPIPE_ALWAYS_IGNORE + #include namespace utils { void OpenEditor(const std::string& file) { - std::cout << "Open file " << file << " TODO" << std::endl; -} + std::string editors[] = {"nvim", "vim", "vi"}; + + cppshell::Shell shell; + + for (auto& editor : editors) { + shell.Execute(editor + " " + file); + if (shell.GetExitCodeLastCommand() == 0) { + break; + } + } } +} // namespace utils