mirror of https://github.com/vitalif/phantomjs
Synchronize std{in,out,err} encoding with `Terminal`
See #11234 https://github.com/ariya/phantomjs/pull/11234 Spin off from #11168 https://github.com/ariya/phantomjs/pull/111681.x
parent
b159144a48
commit
39bec1ce17
|
@ -46,11 +46,11 @@ public:
|
||||||
QString getName() const;
|
QString getName() const;
|
||||||
void setEncoding(const QString &encoding);
|
void setEncoding(const QString &encoding);
|
||||||
|
|
||||||
|
QTextCodec *getCodec() const;
|
||||||
|
|
||||||
static const Encoding UTF8;
|
static const Encoding UTF8;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
QTextCodec *getCodec() const;
|
|
||||||
|
|
||||||
QTextCodec *m_codec;
|
QTextCodec *m_codec;
|
||||||
static const QByteArray DEFAULT_CODEC_NAME;
|
static const QByteArray DEFAULT_CODEC_NAME;
|
||||||
};
|
};
|
||||||
|
|
|
@ -37,6 +37,7 @@
|
||||||
#include <QTextCodec>
|
#include <QTextCodec>
|
||||||
|
|
||||||
#include "../env.h"
|
#include "../env.h"
|
||||||
|
#include "terminal.h"
|
||||||
|
|
||||||
System::System(QObject *parent) :
|
System::System(QObject *parent) :
|
||||||
QObject(parent)
|
QObject(parent)
|
||||||
|
@ -124,6 +125,8 @@ System::System(QObject *parent) :
|
||||||
m_os.insert("name", "unknown");
|
m_os.insert("name", "unknown");
|
||||||
m_os.insert("version", "unknown");
|
m_os.insert("version", "unknown");
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
connect(Terminal::instance(), SIGNAL(encodingChanged(QString)), this, SLOT(_onTerminalEncodingChanged(QString)));
|
||||||
}
|
}
|
||||||
|
|
||||||
System::~System()
|
System::~System()
|
||||||
|
@ -203,10 +206,29 @@ QObject *System::_stdin() {
|
||||||
return m_stdin;
|
return m_stdin;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// private slots:
|
||||||
|
|
||||||
|
void System::_onTerminalEncodingChanged(const QString &encoding)
|
||||||
|
{
|
||||||
|
if ((File *)NULL != m_stdin) {
|
||||||
|
m_stdin->setEncoding(encoding);
|
||||||
|
}
|
||||||
|
|
||||||
|
if ((File *)NULL != m_stdout) {
|
||||||
|
m_stdout->setEncoding(encoding);
|
||||||
|
}
|
||||||
|
|
||||||
|
if ((File *)NULL != m_stderr) {
|
||||||
|
m_stderr->setEncoding(encoding);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// private:
|
// private:
|
||||||
|
|
||||||
File *System::createFileInstance(QFile *f)
|
File *System::createFileInstance(QFile *f)
|
||||||
{
|
{
|
||||||
QTextCodec *codec = QTextCodec::codecForName("UTF-8");
|
// Get the Encoding used by the Terminal at this point in time
|
||||||
|
Encoding e(Terminal::instance()->getEncoding());
|
||||||
|
QTextCodec *codec = e.getCodec();
|
||||||
return new File(f, codec, this);
|
return new File(f, codec, this);
|
||||||
}
|
}
|
||||||
|
|
|
@ -76,6 +76,9 @@ public:
|
||||||
// system.stdin
|
// system.stdin
|
||||||
QObject *_stdin();
|
QObject *_stdin();
|
||||||
|
|
||||||
|
private slots:
|
||||||
|
void _onTerminalEncodingChanged(const QString &encoding);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
File *createFileInstance(QFile *f);
|
File *createFileInstance(QFile *f);
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue