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 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113
|
/*
* Copyright (c) 2007, 2014, Oracle and/or its affiliates. All rights reserved.
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License as
* published by the Free Software Foundation; version 2 of the
* License.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
* 02110-1301 USA
*/
#pragma once
#include "grtpp.h"
#include "grtpp_shell.h"
#include "grt_dispatcher.h"
#include "wbpublic_public_interface.h"
#define ShellBE_VERSION 4
namespace bec {
class GRTManager;
class WBPUBLICBACKEND_PUBLIC_FUNC ShellBE
{
public:
ShellBE(GRTManager *grtm, const GRTDispatcher::Ref dispatcher);
~ShellBE();
bool setup(const std::string &lang);
void set_save_directory(const std::string &path);
void start();
void process_line_async(const std::string &line);
void run_script_file(const std::string &path);
bool run_script(const std::string &script, const std::string &language);
bool previous_history_line(const std::string ¤t_line, std::string &line);
bool next_history_line(std::string &line);
void reset_history_position();
std::vector<std::string> get_grt_tree_bookmarks();
void add_grt_tree_bookmark(const std::string &path);
void delete_grt_tree_bookmark(const std::string &path);
void write_line(const std::string &line);
void write(const std::string &text);
void writef(const char *fmt, ...);
void set_output_handler(const boost::function<void (const std::string&)> &slot);
void set_ready_handler(const boost::function<void (const std::string&)> &slot);
void flush_shell_output();
void set_saves_history(int line_count);
std::vector<std::string> complete_line(const std::string &line, std::string &nprefix);
grt::ValueRef get_shell_variable(const std::string &varname);
void clear_history();
void save_history_line(const std::string &line);
std::string get_snippet_data();
void set_snippet_data(const std::string &data);
void store_state();
void restore_state();
void handle_msg(const grt::Message &msgs);
protected:
GRTManager *_grtm;
grt::GRT *_grt;
grt::Shell *_shell;
GRTDispatcher::Ref _dispatcher;
std::vector<std::string> _grt_tree_bookmarks;
std::string _savedata_dir;
std::string _current_statement;
std::list<std::string> _history; // most recent first
std::list<std::string>::iterator _history_ptr;
boost::function<void (const std::string&)> _ready_slot;
boost::function<void (const std::string&)> _output_slot;
base::Mutex _text_queue_mutex;
std::list<std::string> _text_queue;
int _save_history_size;
int _skip_history;
private:
void shell_finished_cb(grt::ShellCommand result, const std::string &prompt, const std::string &line);
};
};
|