aboutsummaryrefslogtreecommitdiffstats
path: root/libdevcore
diff options
context:
space:
mode:
authorDaniel Kirchner <daniel@ekpyron.org>2018-03-15 02:15:48 +0800
committerDaniel Kirchner <daniel@ekpyron.org>2018-03-15 23:23:49 +0800
commit7fa892eca93cc1b3fd75eb9341c11f0a471970d9 (patch)
tree1d4c5484c8ae42539f79d2c4e70afddf757f0527 /libdevcore
parent269241e9105a3b3014002bf711ade985d87febe4 (diff)
downloaddexon-solidity-7fa892eca93cc1b3fd75eb9341c11f0a471970d9.tar
dexon-solidity-7fa892eca93cc1b3fd75eb9341c11f0a471970d9.tar.gz
dexon-solidity-7fa892eca93cc1b3fd75eb9341c11f0a471970d9.tar.bz2
dexon-solidity-7fa892eca93cc1b3fd75eb9341c11f0a471970d9.tar.lz
dexon-solidity-7fa892eca93cc1b3fd75eb9341c11f0a471970d9.tar.xz
dexon-solidity-7fa892eca93cc1b3fd75eb9341c11f0a471970d9.tar.zst
dexon-solidity-7fa892eca93cc1b3fd75eb9341c11f0a471970d9.zip
Add interactive test tool isoltest.
Diffstat (limited to 'libdevcore')
-rw-r--r--libdevcore/CommonIO.cpp49
-rw-r--r--libdevcore/CommonIO.h3
2 files changed, 52 insertions, 0 deletions
diff --git a/libdevcore/CommonIO.cpp b/libdevcore/CommonIO.cpp
index 8c7e08f6..6526baf9 100644
--- a/libdevcore/CommonIO.cpp
+++ b/libdevcore/CommonIO.cpp
@@ -27,6 +27,7 @@
#if defined(_WIN32)
#include <windows.h>
#else
+#include <unistd.h>
#include <termios.h>
#endif
#include <boost/filesystem.hpp>
@@ -118,3 +119,51 @@ void dev::writeFile(std::string const& _file, bytesConstRef _data, bool _writeDe
}
}
}
+
+#if defined(_WIN32)
+class DisableConsoleBuffering
+{
+public:
+ DisableConsoleBuffering()
+ {
+ m_stdin = GetStdHandle(STD_INPUT_HANDLE);
+ GetConsoleMode(m_stdin, &m_oldMode);
+ SetConsoleMode(m_stdin, m_oldMode & (~(ENABLE_ECHO_INPUT | ENABLE_LINE_INPUT)));
+ }
+ ~DisableConsoleBuffering()
+ {
+ SetConsoleMode(m_stdin, m_oldMode);
+ }
+private:
+ HANDLE m_stdin;
+ DWORD m_oldMode;
+};
+#else
+class DisableConsoleBuffering
+{
+public:
+ DisableConsoleBuffering()
+ {
+ tcgetattr(0, &m_termios);
+ m_termios.c_lflag &= ~ICANON;
+ m_termios.c_lflag &= ~ECHO;
+ m_termios.c_cc[VMIN] = 1;
+ m_termios.c_cc[VTIME] = 0;
+ tcsetattr(0, TCSANOW, &m_termios);
+ }
+ ~DisableConsoleBuffering()
+ {
+ m_termios.c_lflag |= ICANON;
+ m_termios.c_lflag |= ECHO;
+ tcsetattr(0, TCSADRAIN, &m_termios);
+ }
+private:
+ struct termios m_termios;
+};
+#endif
+
+int dev::readStandardInputChar()
+{
+ DisableConsoleBuffering disableConsoleBuffering;
+ return cin.get();
+}
diff --git a/libdevcore/CommonIO.h b/libdevcore/CommonIO.h
index 33769ec3..3ecdb4c3 100644
--- a/libdevcore/CommonIO.h
+++ b/libdevcore/CommonIO.h
@@ -37,6 +37,9 @@ std::string readFileAsString(std::string const& _file);
/// Retrieve and returns the contents of standard input (until EOF).
std::string readStandardInput();
+/// Retrieve and returns a character from standard input (without waiting for EOL).
+int readStandardInputChar();
+
/// Write the given binary data into the given file, replacing the file if it pre-exists.
/// Throws exception on error.
/// @param _writeDeleteRename useful not to lose any data: If set, first writes to another file in