mirror of
https://github.com/FairRootGroup/FairMQ.git
synced 2025-10-13 16:46:47 +00:00
feat: add tool for noncanonical input
This commit is contained in:
parent
d7fb01908c
commit
5fe2f53c7b
|
@ -31,6 +31,7 @@ if(BUILD_FAIRMQ OR BUILD_SDK)
|
|||
set(TOOLS_PUBLIC_HEADER_FILES
|
||||
tools/CppSTL.h
|
||||
tools/InstanceLimit.h
|
||||
tools/IO.h
|
||||
tools/Network.h
|
||||
tools/Process.h
|
||||
tools/RateLimit.h
|
||||
|
|
|
@ -8,6 +8,8 @@
|
|||
|
||||
#include "Control.h"
|
||||
|
||||
#include <fairmq/tools/IO.h>
|
||||
|
||||
#include <atomic>
|
||||
#include <chrono>
|
||||
#include <csignal> // catching system signals
|
||||
|
@ -17,7 +19,6 @@
|
|||
#include <thread>
|
||||
|
||||
#include <poll.h> // for the interactive mode
|
||||
#include <termios.h> // for the interactive mode
|
||||
|
||||
using namespace std;
|
||||
|
||||
|
@ -119,32 +120,6 @@ auto ControlPluginProgramOptions() -> Plugin::ProgOptions
|
|||
return pluginOptions;
|
||||
}
|
||||
|
||||
struct TerminalConfig
|
||||
{
|
||||
TerminalConfig()
|
||||
{
|
||||
termios t;
|
||||
tcgetattr(STDIN_FILENO, &t); // get the current terminal I/O structure
|
||||
t.c_lflag &= ~ICANON; // disable canonical input
|
||||
t.c_lflag &= ~ECHO; // do not echo input chars
|
||||
tcsetattr(STDIN_FILENO, TCSANOW, &t); // apply the new settings
|
||||
}
|
||||
|
||||
TerminalConfig(const TerminalConfig&) = delete;
|
||||
TerminalConfig(TerminalConfig&&) = delete;
|
||||
TerminalConfig& operator=(const TerminalConfig&) = delete;
|
||||
TerminalConfig& operator=(TerminalConfig&&) = delete;
|
||||
|
||||
~TerminalConfig()
|
||||
{
|
||||
termios t;
|
||||
tcgetattr(STDIN_FILENO, &t); // get the current terminal I/O structure
|
||||
t.c_lflag |= ICANON; // re-enable canonical input
|
||||
t.c_lflag |= ECHO; // echo input chars
|
||||
tcsetattr(STDIN_FILENO, TCSANOW, &t); // apply the new settings
|
||||
}
|
||||
};
|
||||
|
||||
auto Control::InteractiveMode() -> void
|
||||
try {
|
||||
RunStartupSequence();
|
||||
|
@ -155,7 +130,7 @@ try {
|
|||
cinfd[0].events = POLLIN;
|
||||
cinfd[0].revents = 0;
|
||||
|
||||
TerminalConfig tconfig;
|
||||
tools::NonCanonicalInput nci;
|
||||
|
||||
bool color = GetProperty<bool>("color");
|
||||
|
||||
|
|
|
@ -9,6 +9,7 @@
|
|||
#include "Monitor.h"
|
||||
#include "Common.h"
|
||||
|
||||
#include <fairmq/tools/IO.h>
|
||||
#include <fairmq/tools/Strings.h>
|
||||
|
||||
#include <boost/interprocess/managed_shared_memory.hpp>
|
||||
|
@ -26,7 +27,6 @@
|
|||
#include <iomanip>
|
||||
#include <sstream>
|
||||
|
||||
#include <termios.h>
|
||||
#include <poll.h>
|
||||
|
||||
#if FAIRMQ_HAS_STD_FILESYSTEM
|
||||
|
@ -49,32 +49,6 @@ namespace
|
|||
namespace fair::mq::shmem
|
||||
{
|
||||
|
||||
struct TerminalConfig
|
||||
{
|
||||
TerminalConfig()
|
||||
{
|
||||
termios t;
|
||||
tcgetattr(STDIN_FILENO, &t); // get the current terminal I/O structure
|
||||
t.c_lflag &= ~ICANON; // disable canonical input
|
||||
t.c_lflag &= ~ECHO; // do not echo input chars
|
||||
tcsetattr(STDIN_FILENO, TCSANOW, &t); // apply the new settings
|
||||
}
|
||||
|
||||
TerminalConfig(const TerminalConfig&) = delete;
|
||||
TerminalConfig(TerminalConfig&&) = delete;
|
||||
TerminalConfig& operator=(const TerminalConfig&) = delete;
|
||||
TerminalConfig& operator=(TerminalConfig&&) = delete;
|
||||
|
||||
~TerminalConfig()
|
||||
{
|
||||
termios t;
|
||||
tcgetattr(STDIN_FILENO, &t); // get the current terminal I/O structure
|
||||
t.c_lflag |= ICANON; // re-enable canonical input
|
||||
t.c_lflag |= ECHO; // echo input chars
|
||||
tcsetattr(STDIN_FILENO, TCSANOW, &t); // apply the new settings
|
||||
}
|
||||
};
|
||||
|
||||
void signalHandler(int signal)
|
||||
{
|
||||
gSignalStatus = signal;
|
||||
|
@ -339,7 +313,7 @@ void Monitor::Interactive()
|
|||
cinfd[0].fd = fileno(stdin);
|
||||
cinfd[0].events = POLLIN;
|
||||
|
||||
TerminalConfig tcfg;
|
||||
tools::NonCanonicalInput nci;
|
||||
|
||||
LOG(info) << "\n";
|
||||
PrintHelp();
|
||||
|
|
49
fairmq/tools/IO.h
Normal file
49
fairmq/tools/IO.h
Normal file
|
@ -0,0 +1,49 @@
|
|||
/********************************************************************************
|
||||
* Copyright (C) 2021 GSI Helmholtzzentrum fuer Schwerionenforschung GmbH *
|
||||
* *
|
||||
* This software is distributed under the terms of the *
|
||||
* GNU Lesser General Public Licence (LGPL) version 3, *
|
||||
* copied verbatim in the file "LICENSE" *
|
||||
********************************************************************************/
|
||||
|
||||
#ifndef FAIR_MQ_TOOLS_IO_H
|
||||
#define FAIR_MQ_TOOLS_IO_H
|
||||
|
||||
#include <termios.h>
|
||||
#include <unistd.h>
|
||||
|
||||
namespace fair::mq::tools
|
||||
{
|
||||
|
||||
/// Enables noncanonical mode for the input terminal for the lifetime of this object.
|
||||
/// (input becomes available to the application without user having to type a line-delimiter)
|
||||
/// Read `man termios` for more details
|
||||
struct NonCanonicalInput
|
||||
{
|
||||
NonCanonicalInput()
|
||||
{
|
||||
termios t;
|
||||
tcgetattr(STDIN_FILENO, &t); // get the current terminal I/O structure
|
||||
t.c_lflag &= ~ICANON; // disable canonical input
|
||||
t.c_lflag &= ~ECHO; // do not echo input chars
|
||||
tcsetattr(STDIN_FILENO, TCSANOW, &t); // apply the new settings
|
||||
}
|
||||
|
||||
NonCanonicalInput(const NonCanonicalInput&) = delete;
|
||||
NonCanonicalInput(NonCanonicalInput&&) = delete;
|
||||
NonCanonicalInput& operator=(const NonCanonicalInput&) = delete;
|
||||
NonCanonicalInput& operator=(NonCanonicalInput&&) = delete;
|
||||
|
||||
~NonCanonicalInput()
|
||||
{
|
||||
termios t;
|
||||
tcgetattr(STDIN_FILENO, &t); // get the current terminal I/O structure
|
||||
t.c_lflag |= ICANON; // re-enable canonical input
|
||||
t.c_lflag |= ECHO; // echo input chars
|
||||
tcsetattr(STDIN_FILENO, TCSANOW, &t); // apply the new settings
|
||||
}
|
||||
};
|
||||
|
||||
} // namespace fair::mq::tools
|
||||
|
||||
#endif /* FAIR_MQ_TOOLS_IO_H */
|
Loading…
Reference in New Issue
Block a user