replay: print colored text (#22771)

old-commit-hash: 09858f7f6f
This commit is contained in:
Dean Lee
2021-11-02 18:24:45 +08:00
committed by GitHub
parent 07ffd9c095
commit 526cfdd0fb
2 changed files with 23 additions and 8 deletions

View File

@@ -75,7 +75,22 @@ void keyboardThread(Replay *replay) {
}
}
void replayMessageOutput(QtMsgType type, const QMessageLogContext &context, const QString &msg) {
QByteArray localMsg = msg.toLocal8Bit();
if (type == QtDebugMsg) {
std::cout << "\033[38;5;248m" << localMsg.constData() << "\033[00m" << std::endl;
} else if (type == QtWarningMsg) {
std::cout << "\033[38;5;227m" << localMsg.constData() << "\033[00m" << std::endl;
} else if (type == QtCriticalMsg) {
std::cout << "\033[38;5;196m" << localMsg.constData() << "\033[00m" << std::endl;
} else {
std::cout << localMsg.constData() << std::endl;
}
}
int main(int argc, char *argv[]) {
qInstallMessageHandler(replayMessageOutput);
QApplication app(argc, argv);
std::signal(SIGINT, sigHandler);
std::signal(SIGTERM, sigHandler);

View File

@@ -58,7 +58,7 @@ void Replay::stop() {
bool Replay::load() {
if (!route_->load()) {
qDebug() << "failed to load route" << route_->name() << "from server";
qCritical() << "failed to load route" << route_->name() << "from server";
return false;
}
@@ -68,10 +68,10 @@ bool Replay::load() {
}
}
if (segments_.empty()) {
qDebug() << "no valid segments in route" << route_->name();
qCritical() << "no valid segments in route" << route_->name();
return false;
}
qDebug() << "load route" << route_->name() << "with" << segments_.size() << "valid segments";
qInfo() << "load route" << route_->name() << "with" << segments_.size() << "valid segments";
return true;
}
@@ -100,7 +100,7 @@ void Replay::doSeek(int seconds, bool relative) {
seconds = std::max(0, seconds);
int seg = seconds / 60;
if (segments_.find(seg) == segments_.end()) {
qInfo() << "can't seek to" << seconds << "s, segment" << seg << "is invalid";
qWarning() << "can't seek to" << seconds << "s, segment" << seg << "is invalid";
return true;
}
@@ -114,7 +114,7 @@ void Replay::doSeek(int seconds, bool relative) {
void Replay::pause(bool pause) {
updateEvents([=]() {
qDebug() << (pause ? "paused..." : "resuming");
qInfo() << (pause ? "paused..." : "resuming");
if (pause) {
qInfo() << "at " << currentSeconds() << "s";
}
@@ -132,7 +132,7 @@ void Replay::setCurrentSegment(int n) {
void Replay::segmentLoadFinished(bool success) {
if (!success) {
Segment *seg = qobject_cast<Segment *>(sender());
qInfo() << "failed to load segment " << seg->seg_num << ", removing it from current replay list";
qWarning() << "failed to load segment " << seg->seg_num << ", removing it from current replay list";
segments_.erase(seg->seg_num);
}
queueSegment();
@@ -153,7 +153,7 @@ void Replay::queueSegment() {
auto &[n, seg] = *it;
seg = std::make_unique<Segment>(n, route_->at(n), hasFlag(REPLAY_FLAG_DCAM), hasFlag(REPLAY_FLAG_ECAM), !hasFlag(REPLAY_FLAG_NO_FILE_CACHE));
QObject::connect(seg.get(), &Segment::loadFinished, this, &Replay::segmentLoadFinished);
qInfo() << "loading segment" << n << "...";
qDebug() << "loading segment" << n << "...";
}
break;
}
@@ -220,7 +220,7 @@ void Replay::startStream(const Segment *cur_segment) {
auto bytes = (*it)->bytes();
Params().put("CarParams", (const char *)bytes.begin(), bytes.size());
} else {
qInfo() << "failed to read CarParams from current segment";
qWarning() << "failed to read CarParams from current segment";
}
// start camera server