Skip to content

Commit

Permalink
Merge pull request #391 from JohanMabille/update_doc
Browse files Browse the repository at this point in the history
Updated documentation after parent header PR
  • Loading branch information
JohanMabille committed Mar 20, 2024
2 parents e6d62ff + 8174fc6 commit ff27c17
Show file tree
Hide file tree
Showing 5 changed files with 34 additions and 23 deletions.
7 changes: 4 additions & 3 deletions docs/source/example/src/custom_interpreter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,8 @@ namespace nl = nlohmann;
namespace custom
{

nl::json custom_interpreter::execute_request_impl(int execution_counter, // Typically the cell number
nl::json custom_interpreter::execute_request_impl(xrequest_context request_context, // data required by other functions
int execution_counter, // Typically the cell number
const std::string& /*code*/, // Code to execute
bool /*silent*/,
bool /*store_history*/,
Expand All @@ -37,12 +38,12 @@ namespace custom
// Replace "Hello World !!" by what you want to be displayed under the execution cell
nl::json pub_data;
pub_data["text/plain"] = "Hello World !!";
publish_execution_result(execution_counter, std::move(pub_data), nl::json::object());
publish_execution_result(request_context, execution_counter, std::move(pub_data), nl::json::object());

// You can also use this method for publishing errors to the client, if the code
// failed to execute
// publish_execution_error(error_name, error_value, error_traceback);
publish_execution_error("TypeError", "123", {"!@#$", "*(*"});
publish_execution_error(request_context, "TypeError", "123", {"!@#$", "*(*"});

return xeus::create_successful_reply();
}
Expand Down
3 changes: 2 additions & 1 deletion docs/source/example/src/custom_interpreter.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,8 @@ namespace custom

void configure_impl() override;

nl::json execute_request_impl(int execution_counter,
nl::json execute_request_impl(xrequest_context request_context,
int execution_counter,
const std::string& code,
bool silent,
bool store_history,
Expand Down
9 changes: 5 additions & 4 deletions docs/source/kernel_implementation.rst
Original file line number Diff line number Diff line change
Expand Up @@ -64,15 +64,16 @@ Input request
~~~~~~~~~~~~~

For input request support, you would need to monkey-patch the language functions that prompt for a user input (``input``
and ``raw_input`` in Python, ``io.read`` in Lua etc) and call ``xeus::blocking_input_request`` instead. The second parameter
should be set to False if what the user is typing should not be visible on the screen.
and ``raw_input`` in Python, ``io.read`` in Lua etc) and call ``xeus::blocking_input_request`` instead. The first parameter
should be forwarded from the execution_request implementation. The third parameter should be set to False if what the user
is typing should not be visible on the screen.

.. code::
#include "xeus/xinput.hpp"
xeus::blocking_input_request("User name:", true);
xeus::blocking_input_request("Password:", false);
xeus::blocking_input_request(request_context, "User name:", true);
xeus::blocking_input_request(request_context, "Password:", false);
Configuration
~~~~~~~~~~~~~
Expand Down
10 changes: 8 additions & 2 deletions include/xeus/xinput.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,17 @@

#include <string>

#include "xeus.hpp"
#include "xeus/xeus.hpp"
#include "xeus/xrequest_context.hpp"

namespace xeus
{
XEUS_API std::string blocking_input_request(const std::string& prompt, bool password);
XEUS_API
std::string blocking_input_request(
xrequest_context context,
const std::string& prompt,
bool password
);
}

#endif
28 changes: 15 additions & 13 deletions include/xeus/xrequest_context.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,21 +20,23 @@ namespace nl = nlohmann;

namespace xeus
{

class XEUS_API xrequest_context{
public:
using guid_list = xmessage::guid_list;
xrequest_context(nl::json header, channel origin, guid_list id);
const nl::json& header() const;
channel origin() const;
const guid_list& id() const;

private:
class XEUS_API xrequest_context
{
public:

using guid_list = xmessage::guid_list;

nl::json m_header;
channel m_origin;
guid_list m_id;
xrequest_context(nl::json header, channel origin, guid_list id);

const nl::json& header() const;
channel origin() const;
const guid_list& id() const;

private:

nl::json m_header;
channel m_origin;
guid_list m_id;
};
}

Expand Down

0 comments on commit ff27c17

Please sign in to comment.