elna/include/elna/shell/interactive.hpp

90 lines
1.8 KiB
C++

#pragma once
#include <boost/core/noncopyable.hpp>
#include <stdexcept>
#include <string>
#include <optional>
#include "elna/shell/state.hpp"
#include "elna/shell/history.hpp"
#define BOOST_PROCESS_USE_STD_FS
namespace elna
{
/**
* Runtime exception for non recoverable errors.
*/
struct interactive_exception : public std::runtime_error
{
/**
* Constructor.
*/
interactive_exception();
};
/**
* Main loop.
*/
void loop();
/**
* Reads the next line.
* Returns no value upon receiving end of file.
*
* \param history Shell history.
* \return The read line.
*/
std::optional<editor_state> read_line(editor_history& history);
/**
* Runs a built-in or a command.
*
* \param line The command and arguments.
* \return Whether the input shoud continued (no exit requested).
*/
bool execute(const std::string& line);
/**
* Runs the binary specified in its argument.
*
* \param program Program name in PATH.
*/
void launch(const std::string& program);
/**
* Enables the raw mode.
*
* \return Whether the operation was successful.
*/
bool enable_raw_mode();
/**
* Disables the raw mode.
*/
void disable_raw_mode();
/**
* Reads a key.
*
* \return Read character.
*/
key read_key();
/**
* Calls autocompletion.
*
* \param User input.
* \param Cursor position in the user input.
* \return Selected item.
*/
std::string complete(const std::string& input, const std::size_t position);
/**
* Prints the message from the exception.
*
* \param exception The exception to print.
*/
void print_exception(const std::exception& exception);
}