1// SPDX-FileCopyrightText: 2023 UnionTech Software Technology Co., Ltd.
2//
3// SPDX-License-Identifier: GPL-3.0-or-later
4
5#include "stdinreadloop.h"
6
7#include <QTextStream>
8
9class StdinReadLoopPrivate
10{
11 friend class StdinReadLoop;
12 QTextStream *stream{nullptr};
13 StdinReadLoopPrivate() = default;
14};
15
16StdinReadLoop::StdinReadLoop()
17 : QThread()
18 , d (new StdinReadLoopPrivate)
19{
20 d->stream = new QTextStream(stdin);
21}
22
23StdinReadLoop::~StdinReadLoop()
24{
25 if (d) {
26 if (d->stream) {
27 delete d->stream;
28 }
29 delete d;
30 }
31}
32
33void StdinReadLoop::run()
34{
35 QString line;
36 while (d->stream->readLineInto(&line)) {
37 Q_EMIT readedLine(line.toLatin1());
38 }
39}
40