mirror of
https://github.com/mhx/dwarfs.git
synced 2025-09-08 03:49:44 -04:00
chore: support using real terminal in test_iolayer
This commit is contained in:
parent
3dbe63b7df
commit
f3b8dc29e4
@ -240,6 +240,7 @@ class test_iolayer {
|
||||
std::string out() const;
|
||||
std::string err() const;
|
||||
|
||||
void use_real_terminal(bool use);
|
||||
void set_in(std::string in);
|
||||
void set_terminal_fancy(bool fancy);
|
||||
void set_terminal_width(size_t width);
|
||||
@ -259,6 +260,7 @@ class test_iolayer {
|
||||
std::ostringstream out_;
|
||||
std::ostringstream err_;
|
||||
std::unique_ptr<iolayer> iol_;
|
||||
std::shared_ptr<terminal const> real_term_;
|
||||
};
|
||||
|
||||
extern std::map<std::string, simplestat> statmap;
|
||||
|
@ -20,6 +20,7 @@
|
||||
*/
|
||||
|
||||
#include <array>
|
||||
#include <iostream>
|
||||
|
||||
#include <fmt/format.h>
|
||||
|
||||
@ -316,18 +317,33 @@ test_iolayer::~test_iolayer() = default;
|
||||
|
||||
iolayer const& test_iolayer::get() {
|
||||
if (!iol_) {
|
||||
iol_ = std::make_unique<iolayer>(iolayer{
|
||||
.os = os_,
|
||||
.term = term_,
|
||||
.file = fa_,
|
||||
.in = in_,
|
||||
.out = out_,
|
||||
.err = err_,
|
||||
});
|
||||
if (real_term_) {
|
||||
iol_ = std::make_unique<iolayer>(iolayer{
|
||||
.os = os_,
|
||||
.term = real_term_,
|
||||
.file = fa_,
|
||||
.in = std::cin,
|
||||
.out = std::cout,
|
||||
.err = std::cerr,
|
||||
});
|
||||
} else {
|
||||
iol_ = std::make_unique<iolayer>(iolayer{
|
||||
.os = os_,
|
||||
.term = term_,
|
||||
.file = fa_,
|
||||
.in = in_,
|
||||
.out = out_,
|
||||
.err = err_,
|
||||
});
|
||||
}
|
||||
}
|
||||
return *iol_;
|
||||
}
|
||||
|
||||
void test_iolayer::use_real_terminal(bool use) {
|
||||
real_term_ = terminal::create();
|
||||
}
|
||||
|
||||
void test_iolayer::set_terminal_fancy(bool fancy) { term_->set_fancy(fancy); }
|
||||
void test_iolayer::set_terminal_width(size_t width) { term_->set_width(width); }
|
||||
void test_iolayer::set_in(std::string in) { in_.str(std::move(in)); }
|
||||
|
Loading…
x
Reference in New Issue
Block a user