157{
158#if defined(_WIN32)
159 DWORD nread{0};
160 std::string ret(4096, '\0');
161 errno = 0;
162 ReadConsole(
Private::in.
handle(), &ret[0],
static_cast<DWORD
>(ret.size()), &nread,
nullptr);
163 return ret.c_str();
164#else
165 #if defined(MAX_INPUT)
166 static const constexpr std::size_t max_input{MAX_INPUT};
167 #else
168 static const constexpr std::size_t max_input{256};
169 #endif
170 #if defined(_POSIX_MAX_INPUT)
171 static const constexpr std::size_t posix_max_input{_POSIX_MAX_INPUT};
172 #else
173 static const constexpr std::size_t posix_max_input{256};
174 #endif
175 static std::size_t nread{std::max(max_input, posix_max_input)};
176 if(
is_stdin_a_tty()) Term::Private::Errno().check_if(::ioctl(
Private::in.
fd(), FIONREAD, &nread) != 0).throw_exception(
"::ioctl(Private::in.fd(), FIONREAD, &nread)");
177 std::string ret(nread, '\0');
178 if(nread != 0)
179 {
180 Term::Private::Errno().check_if(
::read(
Private::in.
fd(), &ret[0], ret.size()) == -1).throw_exception(
"::read(Private::in.fd(), &ret[0], ret.size())");
181 }
182 return ret;
183#endif
184}
Handle handle() const noexcept
std::int32_t fd() const noexcept
bool is_stdin_a_tty()
Check if stdin is a tty.