From 461a7ee3e036d5f13956f208bf579a7462ba05b9 Mon Sep 17 00:00:00 2001 From: sha512sum Date: Wed, 28 Feb 2024 22:46:09 +0000 Subject: [PATCH] Return error in Menu --- include/utempl/menu.hpp | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) diff --git a/include/utempl/menu.hpp b/include/utempl/menu.hpp index 3701aad..cfc8f2f 100644 --- a/include/utempl/menu.hpp +++ b/include/utempl/menu.hpp @@ -85,10 +85,10 @@ struct Menu { return Menu>{.functionStorage = this->functionStorage + Tuple(std::forward(f))}; }; template - inline constexpr auto Run(std::istream& in = std::cin, std::FILE* out = stdout) const { + inline constexpr auto Run(std::istream& in = std::cin, std::FILE* out = stdout) const -> std::size_t { using Cleared = std::remove_cvref_t; constexpr auto maxSize = Cleared::GetMaxSize(); - [&](std::index_sequence){ + return [&](std::index_sequence) -> std::size_t { constexpr auto message = ([&](Wrapper){ constexpr auto message = Get(storage); constexpr std::size_t s = maxSize - (message.need ? message.need->size() : CountDigits(I)); @@ -113,9 +113,13 @@ struct Menu { ,str3); return ConstexprString(data); }(Wrapper{}) + ...) + enter; - - std::fwrite(message.begin(), 1, message.size(), out); - std::fflush(out); + auto result = std::fwrite(message.begin(), 1, message.size(), out); + if(result < message.size()) { + return result; + }; + if(std::fflush(out) != 0) { + return EOF; + }; std::string input; std::getline(in, input); ([&](storage)>(Wrapper) { @@ -129,8 +133,10 @@ struct Menu { }; }; }(Wrapper{}), ...); + return 0; }(std::index_sequence_for()); }; + }; } // namespace menu