MCPcopy Create free account
hub / github.com/KDE/kid3 / blockingReadLine

Method blockingReadLine

src/app/cli/standardiohandler.cpp:113–162  ·  view source on GitHub ↗

* Read the next line. */

Source from the content-addressed store, hash-verified

111 * Read the next line.
112 */
113void StandardIOHandler::blockingReadLine()
114{
115 if (!m_consoleMode) {
116 QTextStream stdIn(stdin, QIODevice::ReadOnly);
117 QString line = stdIn.readLine();
118 emit lineReady(line);
119 return;
120 }
121#ifdef HAVE_READLINE
122 char* lineRead = ::readline(m_prompt);
123 if (!lineRead) {
124 // EOF
125 emit lineReady(QString());
126 return;
127 }
128 if (*lineRead) {
129 ::add_history(lineRead);
130 }
131 QString line = QString::fromLocal8Bit(lineRead);
132#if RL_READLINE_VERSION >= 0x0600
133 ::rl_free(lineRead);
134#else
135 ::free(lineRead);
136#endif
137#elif defined Q_OS_WIN32
138 WriteConsoleA(GetStdHandle(STD_OUTPUT_HANDLE),
139 m_prompt, qstrlen(m_prompt), 0, 0);
140 const int numCharsInBuf = 512;
141 wchar_t buf[numCharsInBuf];
142 DWORD numCharsRead;
143 QString line;
144 do {
145 ReadConsoleW(GetStdHandle(STD_INPUT_HANDLE),
146 buf, numCharsInBuf, &numCharsRead, 0);
147 line += QString::fromWCharArray(buf, numCharsRead);
148 } while (numCharsRead > 0 && line[line.length() - 1] != QLatin1Char('\n'));
149 while (line.length() > 0 &&
150 (line[line.length() - 1] == QLatin1Char('\r') ||
151 line[line.length() - 1] == QLatin1Char('\n'))) {
152 line.truncate(line.length() - 1);
153 }
154#else
155 QTextStream stdOut(stdout, QIODevice::WriteOnly);
156 stdOut << m_prompt;
157 stdOut.flush();
158 QTextStream stdIn(stdin, QIODevice::ReadOnly);
159 QString line = stdIn.readLine();
160#endif
161 emit lineReady(line);
162}
163
164/**
165 * Write a line to standard output.

Callers

nothing calls this directly

Calls 4

truncateMethod · 0.80
QStringClass · 0.50
readLineMethod · 0.45
lengthMethod · 0.45

Tested by

no test coverage detected