-
Notifications
You must be signed in to change notification settings - Fork 1
/
Shell.h
84 lines (64 loc) · 1.9 KB
/
Shell.h
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
// Copyright 2012 naoya_t. All Rights Reserved.
// Use of this source code is governed by a LGPL-style
// license that can be found in the COPYING file.
#ifndef SHELL_H_
#define SHELL_H_
#include <re2/re2.h>
#include <map>
#include <set>
#include <string>
#include <utility>
#include <vector>
#include "pdic/lookup_result.h"
class Dict;
class ShellParams {
public:
ShellParams();
int set_render_count_limit(int limit);
int set_lookup_mode(const char *mode_str);
const char *get_lookup_mode();
public:
bool separator_mode;
bool verbose_mode;
bool direct_dump_mode;
bool full_search_mode;
bool ansi_coloring_mode;
bool more_newline_mode;
int render_count_limit;
bool stop_on_limit_mode;
int default_lookup_flags;
int debug_flags;
bool drop_hiragana_times_mode;
};
class Shell {
public:
Shell();
~Shell();
void load_rc(const char *rcpath = NULL);
int do_load(const std::string& filename);
bool do_command(char *cmdstr);
void render_current_result();
int run(char *word_to_lookup = NULL);
int execute(char *line);
ShellParams params;
std::vector<std::string> loadpaths;
std::vector<Dict*> dicts;
std::map<std::string, std::vector<std::string> > aliases; // name -> name
std::map<std::string, int> nametable; // name -> dict_id
std::string current_dict_name;
std::vector<int> current_dict_ids;
lookup_result_vec current_result_vec;
RE2* current_pattern;
std::pair<std::string, std::string> current_query;
std::vector<std::string> query_history;
private:
void do_alias(const std::string& alias,
const std::string& valid_name);
void do_alias(const std::string& alias,
const std::vector<std::string>& valid_names);
std::vector<int> resolve_aliases(const std::string& name);
bool do_use(std::string name);
void render_current_result(const std::set<int>& range);
void render_status();
};
#endif // SHELL_H_