mirror of
https://github.com/ton-blockchain/ton
synced 2025-03-09 15:40:10 +00:00
updated func and tonlib
This commit is contained in:
parent
493ae2410c
commit
a73d202ba2
50 changed files with 1340 additions and 271 deletions
|
@ -14,7 +14,7 @@
|
|||
You should have received a copy of the GNU Lesser General Public License
|
||||
along with TON Blockchain Library. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
Copyright 2017-2019 Telegram Systems LLP
|
||||
Copyright 2017-2020 Telegram Systems LLP
|
||||
*/
|
||||
#include "terminal.hpp"
|
||||
#include "td/utils/port/StdStreams.h"
|
||||
|
@ -42,7 +42,7 @@ void TerminalLogInterface::append(CSlice slice, int log_level) {
|
|||
} else {
|
||||
color = TC_GREEN;
|
||||
}
|
||||
td::TsCerr() << color << slice << TC_EMPTY;
|
||||
std::cerr << color << slice.c_str() << TC_EMPTY;
|
||||
instance_->reactivate_readline();
|
||||
if (log_level == VERBOSITY_NAME(FATAL)) {
|
||||
process_fatal_error(slice);
|
||||
|
@ -82,6 +82,16 @@ void TerminalIOImpl::output_line(std::string line) {
|
|||
reactivate_readline();
|
||||
}
|
||||
|
||||
void TerminalIOImpl::output_line_stderr(std::string line) {
|
||||
deactivate_readline();
|
||||
if (use_readline_) {
|
||||
Stdout().write(line).ensure();
|
||||
} else {
|
||||
Stderr().write(line).ensure();
|
||||
}
|
||||
reactivate_readline();
|
||||
}
|
||||
|
||||
void TerminalIOImpl::start_up() {
|
||||
instance_ = this;
|
||||
self_ = actor_id(this);
|
||||
|
@ -246,7 +256,7 @@ void TerminalIO::output(std::string line) {
|
|||
std::cout << line;
|
||||
} else {
|
||||
instance_->deactivate_readline();
|
||||
td::TsCerr() << line;
|
||||
std::cout << line;
|
||||
instance_->reactivate_readline();
|
||||
}
|
||||
}
|
||||
|
@ -254,10 +264,40 @@ void TerminalIO::output(std::string line) {
|
|||
void TerminalIO::output(td::Slice line) {
|
||||
auto instance_ = TerminalIOImpl::instance();
|
||||
if (!instance_) {
|
||||
td::TsCerr() << line;
|
||||
std::cout.write(line.begin(), line.size());
|
||||
} else {
|
||||
instance_->deactivate_readline();
|
||||
td::TsCerr() << line;
|
||||
std::cout.write(line.begin(), line.size());
|
||||
instance_->reactivate_readline();
|
||||
}
|
||||
}
|
||||
|
||||
void TerminalIO::output_stderr(std::string line) {
|
||||
auto instance_ = TerminalIOImpl::instance();
|
||||
if (!instance_) {
|
||||
std::cout << line;
|
||||
} else {
|
||||
instance_->deactivate_readline();
|
||||
if (instance_->readline_used()) {
|
||||
std::cout << line;
|
||||
} else {
|
||||
std::cerr << line;
|
||||
}
|
||||
instance_->reactivate_readline();
|
||||
}
|
||||
}
|
||||
|
||||
void TerminalIO::output_stderr(td::Slice line) {
|
||||
auto instance_ = TerminalIOImpl::instance();
|
||||
if (!instance_) {
|
||||
std::cerr.write(line.begin(), line.size());
|
||||
} else {
|
||||
instance_->deactivate_readline();
|
||||
if (instance_->readline_used()) {
|
||||
std::cout.write(line.begin(), line.size());
|
||||
} else {
|
||||
std::cerr.write(line.begin(), line.size());
|
||||
}
|
||||
instance_->reactivate_readline();
|
||||
}
|
||||
}
|
||||
|
@ -265,7 +305,11 @@ void TerminalIO::output(td::Slice line) {
|
|||
TerminalIOOutputter::~TerminalIOOutputter() {
|
||||
if (buffer_) {
|
||||
CHECK(sb_);
|
||||
TerminalIO::output(sb_->as_cslice());
|
||||
if (is_err_) {
|
||||
TerminalIO::output_stderr(sb_->as_cslice());
|
||||
} else {
|
||||
TerminalIO::output(sb_->as_cslice());
|
||||
}
|
||||
delete[] buffer_;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -14,7 +14,7 @@
|
|||
You should have received a copy of the GNU Lesser General Public License
|
||||
along with TON Blockchain Library. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
Copyright 2017-2019 Telegram Systems LLP
|
||||
Copyright 2017-2020 Telegram Systems LLP
|
||||
*/
|
||||
#pragma once
|
||||
|
||||
|
@ -29,8 +29,10 @@ namespace td {
|
|||
class TerminalIOOutputter {
|
||||
public:
|
||||
static const size_t BUFFER_SIZE = 128 * 1024;
|
||||
TerminalIOOutputter()
|
||||
: buffer_(new char[BUFFER_SIZE]), sb_(std::make_unique<StringBuilder>(td::MutableSlice{buffer_, BUFFER_SIZE})) {
|
||||
TerminalIOOutputter(bool is_err)
|
||||
: buffer_(new char[BUFFER_SIZE])
|
||||
, is_err_(is_err)
|
||||
, sb_(std::make_unique<StringBuilder>(td::MutableSlice{buffer_, BUFFER_SIZE})) {
|
||||
}
|
||||
TerminalIOOutputter(TerminalIOOutputter &&X) = default;
|
||||
|
||||
|
@ -58,6 +60,7 @@ class TerminalIOOutputter {
|
|||
|
||||
private:
|
||||
char *buffer_;
|
||||
bool is_err_;
|
||||
std::unique_ptr<StringBuilder> sb_;
|
||||
};
|
||||
|
||||
|
@ -75,11 +78,18 @@ class TerminalIO : public actor::Actor {
|
|||
virtual void update_callback(std::unique_ptr<Callback> callback) = 0;
|
||||
static void output(std::string line);
|
||||
static void output(td::Slice slice);
|
||||
static void output_stderr(std::string line);
|
||||
static void output_stderr(td::Slice slice);
|
||||
static TerminalIOOutputter out() {
|
||||
return TerminalIOOutputter{};
|
||||
return TerminalIOOutputter{false};
|
||||
}
|
||||
static TerminalIOOutputter err() {
|
||||
return TerminalIOOutputter{true};
|
||||
}
|
||||
virtual void output_line(std::string line) = 0;
|
||||
virtual void output_line_stderr(std::string line) = 0;
|
||||
virtual void set_log_interface() = 0;
|
||||
virtual bool readline_used() const = 0;
|
||||
|
||||
static td::actor::ActorOwn<TerminalIO> create(std::string prompt, bool use_readline,
|
||||
std::unique_ptr<Callback> callback);
|
||||
|
|
|
@ -14,7 +14,7 @@
|
|||
You should have received a copy of the GNU Lesser General Public License
|
||||
along with TON Blockchain Library. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
Copyright 2017-2019 Telegram Systems LLP
|
||||
Copyright 2017-2020 Telegram Systems LLP
|
||||
*/
|
||||
#pragma once
|
||||
|
||||
|
@ -45,6 +45,10 @@ class TerminalIOImpl : public TerminalIO, td::ObserverBase {
|
|||
void deactivate_readline();
|
||||
void reactivate_readline();
|
||||
void output_line(std::string line) override;
|
||||
void output_line_stderr(std::string line) override;
|
||||
bool readline_used() const override {
|
||||
return use_readline_;
|
||||
}
|
||||
void set_log_interface() override;
|
||||
//void read_line();
|
||||
void loop() override;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue