|
| 1 | +/** |
| 2 | + * |
| 3 | + * @file ReplyCellRunner.hpp |
| 4 | + * @author Gaspard Kirira |
| 5 | + * |
| 6 | + * @brief Reply cell execution helper for Vix Note. |
| 7 | + * |
| 8 | + * Copyright 2026, Gaspard Kirira. |
| 9 | + * All rights reserved. |
| 10 | + * https://github.com/vixcpp/note |
| 11 | + * |
| 12 | + * Use of this source code is governed by a MIT license |
| 13 | + * that can be found in the LICENSE file. |
| 14 | + * |
| 15 | + * Vix Note |
| 16 | + * |
| 17 | + */ |
| 18 | + |
| 19 | +#ifndef VIX_NOTE_RUNTIME_REPLY_CELL_RUNNER_HPP |
| 20 | +#define VIX_NOTE_RUNTIME_REPLY_CELL_RUNNER_HPP |
| 21 | + |
| 22 | +#include <vix/note/core/NoteCell.hpp> |
| 23 | +#include <vix/note/core/NoteResult.hpp> |
| 24 | + |
| 25 | +#include <vix/reply/core/ReplyRuntime.hpp> |
| 26 | + |
| 27 | +#include <string> |
| 28 | +#include <utility> |
| 29 | +#include <vector> |
| 30 | + |
| 31 | +namespace vix::note |
| 32 | +{ |
| 33 | + /** |
| 34 | + * @brief Options used when running a Reply note cell. |
| 35 | + * |
| 36 | + * ReplyCellRunner executes small Reply cells through the embeddable |
| 37 | + * Vix Reply runtime. It does not start the interactive terminal REPL. |
| 38 | + */ |
| 39 | + struct ReplyCellRunnerOptions |
| 40 | + { |
| 41 | + /** |
| 42 | + * @brief Runtime options passed to the embedded Reply runtime. |
| 43 | + */ |
| 44 | + vix::reply::ReplyRuntimeOptions runtimeOptions; |
| 45 | + |
| 46 | + /** |
| 47 | + * @brief Arguments exposed through Vix.args(). |
| 48 | + */ |
| 49 | + std::vector<std::string> args; |
| 50 | + |
| 51 | + /** |
| 52 | + * @brief Enables debug metadata outputs. |
| 53 | + */ |
| 54 | + bool debugMode = false; |
| 55 | + }; |
| 56 | + |
| 57 | + /** |
| 58 | + * @brief Executes Reply cells through the embedded Reply runtime. |
| 59 | + */ |
| 60 | + class ReplyCellRunner |
| 61 | + { |
| 62 | + public: |
| 63 | + /** |
| 64 | + * @brief Creates a runner with default options. |
| 65 | + */ |
| 66 | + ReplyCellRunner(); |
| 67 | + |
| 68 | + /** |
| 69 | + * @brief Creates a runner with custom options. |
| 70 | + * |
| 71 | + * @param options Runner options. |
| 72 | + */ |
| 73 | + explicit ReplyCellRunner(ReplyCellRunnerOptions options); |
| 74 | + |
| 75 | + /** |
| 76 | + * @brief Returns the current runner options. |
| 77 | + * |
| 78 | + * @return Runner options. |
| 79 | + */ |
| 80 | + const ReplyCellRunnerOptions &options() const noexcept; |
| 81 | + |
| 82 | + /** |
| 83 | + * @brief Replaces the current runner options. |
| 84 | + * |
| 85 | + * @param options New runner options. |
| 86 | + */ |
| 87 | + void set_options(ReplyCellRunnerOptions options); |
| 88 | + |
| 89 | + /** |
| 90 | + * @brief Runs raw Reply source code. |
| 91 | + * |
| 92 | + * @param source Reply source code. |
| 93 | + * @return Execution result. |
| 94 | + */ |
| 95 | + NoteResult run_source(const std::string &source); |
| 96 | + |
| 97 | + /** |
| 98 | + * @brief Runs a Reply note cell. |
| 99 | + * |
| 100 | + * @param cell Cell to execute. |
| 101 | + * @return Execution result. |
| 102 | + */ |
| 103 | + NoteResult run_cell(const NoteCell &cell); |
| 104 | + |
| 105 | + /** |
| 106 | + * @brief Clears the embedded Reply runtime state. |
| 107 | + */ |
| 108 | + void clear(); |
| 109 | + |
| 110 | + private: |
| 111 | + /** |
| 112 | + * @brief Rebuilds the embedded runtime from current options. |
| 113 | + */ |
| 114 | + void reset_runtime(); |
| 115 | + |
| 116 | + /** |
| 117 | + * @brief Runner options. |
| 118 | + */ |
| 119 | + ReplyCellRunnerOptions options_; |
| 120 | + |
| 121 | + /** |
| 122 | + * @brief Embedded Reply runtime. |
| 123 | + */ |
| 124 | + vix::reply::ReplyRuntime runtime_; |
| 125 | + }; |
| 126 | + |
| 127 | + /** |
| 128 | + * @brief Runs raw Reply source code using default runner options. |
| 129 | + * |
| 130 | + * @param source Reply source code. |
| 131 | + * @return Execution result. |
| 132 | + */ |
| 133 | + NoteResult run_reply_source(const std::string &source); |
| 134 | + |
| 135 | + /** |
| 136 | + * @brief Runs a Reply cell using default runner options. |
| 137 | + * |
| 138 | + * @param cell Cell to execute. |
| 139 | + * @return Execution result. |
| 140 | + */ |
| 141 | + NoteResult run_reply_cell(const NoteCell &cell); |
| 142 | +} |
| 143 | + |
| 144 | +#endif // VIX_NOTE_RUNTIME_REPLY_CELL_RUNNER_HPP |
0 commit comments