mirror of
https://github.com/RPCS3/rpcs3.git
synced 2025-07-12 17:58:37 +12:00
Improve TTY output
Use atomic variable to sync TTY size Implement console_putc (liblv2) Write plaintext instead of HTML Slightly improve performance Fix random line breaks in TTY
This commit is contained in:
parent
445b7c0758
commit
f056b2f4ab
6 changed files with 37 additions and 58 deletions
|
@ -9,6 +9,8 @@
|
|||
#include <QScrollBar>
|
||||
#include <QTabBar>
|
||||
|
||||
extern atomic_t<s64> g_tty_size;
|
||||
|
||||
constexpr auto qstr = QString::fromStdString;
|
||||
|
||||
struct gui_listener : logs::listener
|
||||
|
@ -193,7 +195,7 @@ void log_frame::CreateAndConnectActions()
|
|||
auto l_initAct = [this](QAction* act, logs::level logLevel)
|
||||
{
|
||||
act->setCheckable(true);
|
||||
|
||||
|
||||
// This sets the log level properly when the action is triggered.
|
||||
connect(act, &QAction::triggered, [this, logLevel]()
|
||||
{
|
||||
|
@ -302,47 +304,30 @@ void log_frame::RepaintTextColors()
|
|||
|
||||
void log_frame::UpdateUI()
|
||||
{
|
||||
std::vector<char> buf(4096);
|
||||
|
||||
// Get UTF-8 string from file
|
||||
auto get_utf8 = [&](const fs::file& file, u64 size) -> QString
|
||||
{
|
||||
size = file.read(buf.data(), size);
|
||||
|
||||
for (u64 i = 0; i < size; i++)
|
||||
{
|
||||
// Get UTF-8 sequence length (no real validation performed)
|
||||
const u64 tail =
|
||||
(buf[i] & 0xF0) == 0xF0 ? 3 :
|
||||
(buf[i] & 0xE0) == 0xE0 ? 2 :
|
||||
(buf[i] & 0xC0) == 0xC0 ? 1 : 0;
|
||||
|
||||
if (i + tail >= size)
|
||||
{ // Copying is expensive-- O(i)-- but I suspect this corruption will be exceptionally unlikely.
|
||||
file.seek(i - size, fs::seek_cur);
|
||||
std::vector<char> sub(&buf[0], &buf[i]);
|
||||
return QString(sub.data());
|
||||
}
|
||||
}
|
||||
return QString(buf.data());
|
||||
};
|
||||
|
||||
const auto start = steady_clock::now();
|
||||
|
||||
// Check TTY logs
|
||||
|
||||
while (const u64 size = std::min<u64>(buf.size(), m_tty_file.size() - m_tty_file.pos()))
|
||||
while (const u64 size = std::max<s64>(0, g_tty_size.load() - m_tty_file.pos()))
|
||||
{
|
||||
QString text = get_utf8(m_tty_file, size);
|
||||
std::string buf;
|
||||
buf.resize(size);
|
||||
buf.resize(m_tty_file.read(&buf.front(), buf.size()));
|
||||
|
||||
// Hackily used the state of the check.. be better if I actually stored this value.
|
||||
if (m_TTYAct->isChecked())
|
||||
if (buf.find_first_of('\0') != -1)
|
||||
{
|
||||
text.chop(1); // remove newline since Qt automatically adds a newline.
|
||||
m_tty->append(text);
|
||||
m_tty_file.seek(s64{0} - buf.size(), fs::seek_mode::seek_cur);
|
||||
break;
|
||||
}
|
||||
|
||||
if (buf.size() && m_TTYAct->isChecked())
|
||||
{
|
||||
QTextCursor text_cursor{m_tty->document()};
|
||||
text_cursor.movePosition(QTextCursor::End);
|
||||
text_cursor.insertText(qstr(buf));
|
||||
}
|
||||
|
||||
// Limit processing time
|
||||
if (steady_clock::now() >= start + 4ms || text.isEmpty()) break;
|
||||
if (steady_clock::now() >= start + 4ms || buf.empty()) break;
|
||||
}
|
||||
|
||||
// Check main logs
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue