Skip to content

Commit da23636

Browse files
committed
Support for more console.log with variable number of args.
Signed-off-by: Adam Treat <[email protected]>
1 parent c7d7345 commit da23636

File tree

1 file changed

+71
-2
lines changed

1 file changed

+71
-2
lines changed

gpt4all-chat/src/codeinterpreter.h

+71-2
Original file line numberDiff line numberDiff line change
@@ -14,12 +14,79 @@ class JavaScriptConsoleCapture : public QObject
1414
Q_OBJECT
1515
public:
1616
QString output;
17-
Q_INVOKABLE void log(const QString &message)
17+
Q_INVOKABLE void log(const QJSValue &a)
18+
{
19+
logInternal(a, true);
20+
}
21+
Q_INVOKABLE void log(const QJSValue &a, const QJSValue &b)
22+
{
23+
logInternal(a);
24+
logInternal(b, true);
25+
}
26+
Q_INVOKABLE void log(const QJSValue &a, const QJSValue &b, const QJSValue &c)
27+
{
28+
logInternal(a);
29+
logInternal(b);
30+
logInternal(c, true);
31+
}
32+
Q_INVOKABLE void log(const QJSValue &a, const QJSValue &b, const QJSValue &c, const QJSValue &d)
33+
{
34+
logInternal(a);
35+
logInternal(b);
36+
logInternal(c);
37+
logInternal(d, true);
38+
}
39+
Q_INVOKABLE void log(const QJSValue &a, const QJSValue &b, const QJSValue &c, const QJSValue &d,
40+
const QJSValue &e)
41+
{
42+
logInternal(a);
43+
logInternal(b);
44+
logInternal(c);
45+
logInternal(d);
46+
logInternal(e, true);
47+
}
48+
Q_INVOKABLE void log(const QJSValue &a, const QJSValue &b, const QJSValue &c, const QJSValue &d,
49+
const QJSValue &e, const QJSValue &f)
50+
{
51+
logInternal(a);
52+
logInternal(b);
53+
logInternal(c);
54+
logInternal(d);
55+
logInternal(e);
56+
logInternal(f, true);
57+
}
58+
Q_INVOKABLE void log(const QJSValue &a, const QJSValue &b, const QJSValue &c, const QJSValue &d,
59+
const QJSValue &e, const QJSValue &f, const QJSValue &g)
60+
{
61+
logInternal(a);
62+
logInternal(b);
63+
logInternal(c);
64+
logInternal(d);
65+
logInternal(e);
66+
logInternal(f);
67+
logInternal(g, true);
68+
}
69+
Q_INVOKABLE void log(const QJSValue &a, const QJSValue &b, const QJSValue &c, const QJSValue &d,
70+
const QJSValue &e, const QJSValue &f, const QJSValue &g, const QJSValue &h)
71+
{
72+
logInternal(a);
73+
logInternal(b);
74+
logInternal(c);
75+
logInternal(d);
76+
logInternal(e);
77+
logInternal(f);
78+
logInternal(g);
79+
logInternal(h, true);
80+
}
81+
82+
private:
83+
void logInternal(const QJSValue &value, bool newLine = false)
1884
{
1985
const int maxLength = 1024;
2086
if (output.length() >= maxLength)
2187
return;
2288

89+
const QString message = value.toString();
2390
if (output.length() + message.length() + 1 > maxLength) {
2491
static const QString trunc = "\noutput truncated at " + QString::number(maxLength) + " characters...";
2592
int remainingLength = maxLength - output.length();
@@ -28,7 +95,9 @@ class JavaScriptConsoleCapture : public QObject
2895
output.append(trunc);
2996
Q_ASSERT(output.length() > maxLength);
3097
} else {
31-
output.append(message + "\n");
98+
if (!output.isEmpty() && output.back() != '\n') output.append(' ');
99+
output.append(message);
100+
if (newLine) output.append('\n');
32101
}
33102
}
34103
};

0 commit comments

Comments
 (0)