mirror of
https://github.com/matrix-construct/construct
synced 2025-01-14 00:34:18 +01:00
construct;modules/s_control: Fix output stream related.
This commit is contained in:
parent
05fcdd458a
commit
58af1ae88c
2 changed files with 23 additions and 15 deletions
|
@ -291,25 +291,34 @@ handle_line_bymodule(const string_view &line)
|
|||
*console_module, "console_command"
|
||||
};
|
||||
|
||||
thread_local char buf[32_KiB];
|
||||
std::ostringstream ss;
|
||||
pubsetbuf(ss, buf);
|
||||
std::ostringstream out;
|
||||
out.exceptions(out.badbit | out.failbit | out.eofbit);
|
||||
|
||||
int ret;
|
||||
static const string_view opts;
|
||||
switch((ret = command(ss, line, opts)))
|
||||
switch((ret = command(out, line, opts)))
|
||||
{
|
||||
case 0:
|
||||
case 1:
|
||||
{
|
||||
const string_view out
|
||||
const auto str
|
||||
{
|
||||
view(ss, buf)
|
||||
out.str()
|
||||
};
|
||||
|
||||
std::cout << out;
|
||||
if(endswith(out, '\n'))
|
||||
std::flush(std::cout);
|
||||
else
|
||||
static const size_t mlen(2048);
|
||||
for(size_t off(0); off < str.size(); off += mlen)
|
||||
{
|
||||
const string_view substr
|
||||
{
|
||||
str.data() + off, std::min(str.size() - off, mlen)
|
||||
};
|
||||
|
||||
std::cout << substr << std::flush;
|
||||
ctx::sleep(milliseconds(25));
|
||||
}
|
||||
|
||||
if(!endswith(str, '\n'))
|
||||
std::cout << std::endl;
|
||||
|
||||
return ret;
|
||||
|
@ -321,7 +330,7 @@ handle_line_bymodule(const string_view &line)
|
|||
// we use this code to translate it.
|
||||
case -2: throw bad_command
|
||||
{
|
||||
"%s", view(ss, buf)
|
||||
"%s", out.str()
|
||||
};
|
||||
|
||||
// Command isn't handled by the module; continue handling here
|
||||
|
|
|
@ -179,18 +179,17 @@ noexcept try
|
|||
*console_module, "console_command"
|
||||
};
|
||||
|
||||
const unique_buffer<mutable_buffer> buf{32_KiB};
|
||||
std::ostringstream out;
|
||||
pubsetbuf(out, buf);
|
||||
out.exceptions(out.badbit | out.failbit | out.eofbit);
|
||||
|
||||
out << "<pre>";
|
||||
static const string_view opts{"html"};
|
||||
command(out, body, opts);
|
||||
out << "</pre>";
|
||||
|
||||
const auto str //TODO: X
|
||||
const auto str
|
||||
{
|
||||
replace(view(out, buf), '\n', "<br />")
|
||||
replace(out.str().substr(0, 48_KiB), '\n', "<br />")
|
||||
};
|
||||
|
||||
const string_view alt //TODO: X
|
||||
|
|
Loading…
Reference in a new issue