forked from jupyter-xeus/xeus-cling
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathxinput.cpp
43 lines (36 loc) · 1.51 KB
/
xinput.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
/***********************************************************************************
* Copyright (c) 2016, Johan Mabille, Loic Gouarin, Sylvain Corlay, Wolf Vollprecht *
* Copyright (c) 2016, QuantStack *
* *
* Distributed under the terms of the BSD 3-Clause License. *
* *
* The full license is in the file LICENSE, distributed with this software. *
************************************************************************************/
#include <iostream>
#include <stdexcept>
#include <string>
#include "xinput.hpp"
#include "xeus/xinterpreter.hpp"
#include "xeus/xinput.hpp"
namespace xcpp
{
void notimplemented(const std::string&)
{
throw std::runtime_error("This frontend does not support input requests");
}
/***************************************
* Implementation of input_redirection *
***************************************/
input_redirection::input_redirection(bool allow_stdin)
: p_cin_strbuf(std::cin.rdbuf()),
m_cin_buffer(allow_stdin ? xinput_buffer([](std::string& value) {
value = xeus::blocking_input_request("", false);
}) : xinput_buffer(notimplemented))
{
std::cin.rdbuf(&m_cin_buffer);
}
input_redirection::~input_redirection()
{
std::cin.rdbuf(p_cin_strbuf);
}
}