1 module editline;
2 /*	$NetBSD: readline.h,v 1.42 2017/09/01 10:19:10 christos Exp $	*/
3 
4 /*-
5  * Copyright (c) 1997 The NetBSD Foundation, Inc.
6  * All rights reserved.
7  *
8  * This code is derived from software contributed to The NetBSD Foundation
9  * by Jaromir Dolecek.
10  *
11  * Redistribution and use in source and binary forms, with or without
12  * modification, are permitted provided that the following conditions
13  * are met:
14  * 1. Redistributions of source code must retain the above copyright
15  *    notice, this list of conditions and the following disclaimer.
16  * 2. Redistributions in binary form must reproduce the above copyright
17  *    notice, this list of conditions and the following disclaimer in the
18  *    documentation and/or other materials provided with the distribution.
19  *
20  * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
21  * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
22  * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
23  * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
24  * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
25  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
26  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
27  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
28  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
29  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
30  * POSSIBILITY OF SUCH DAMAGE.
31  */
32 
33 import core.stdc.stdio;
34 
35 extern (C):
36 
37 /* list of readline stuff supported by editline library's readline wrapper */
38 
39 /* typedefs */
40 alias Function = int function (const(char)*, int);
41 alias VFunction = void function ();
42 alias rl_vcpfunc_t = void function (char*);
43 alias rl_completion_func_t = char** function (const(char)*, int, int);
44 alias rl_compentry_func_t = char* function (const(char)*, int);
45 alias rl_command_func_t = int function (int, int);
46 
47 /* only supports length */
48 struct HISTORY_STATE
49 {
50     int length;
51 }
52 
53 alias histdata_t = void*;
54 
55 struct _hist_entry
56 {
57     const(char)* line;
58     histdata_t data;
59 }
60 
61 alias HIST_ENTRY = _hist_entry;
62 
63 struct _keymap_entry
64 {
65     char type;
66 
67     int function () function_;
68 }
69 
70 enum ISFUNC = 0;
71 enum ISKMAP = 1;
72 enum ISMACR = 2;
73 alias KEYMAP_ENTRY = _keymap_entry;
74 
75 enum KEYMAP_SIZE = 256;
76 
77 alias KEYMAP_ENTRY_ARRAY = _keymap_entry[KEYMAP_SIZE];
78 alias Keymap = _keymap_entry*;
79 
80 enum control_character_threshold = 0x20;
81 enum control_character_bit = 0x40;
82 
83 auto CTRL(T)(T c) {return (c) & 31; }
84 
85 extern (D) auto UNCTRL(T)(auto ref T c)
86 {
87     return (c - 'a' + 'A') | control_character_bit;
88 }
89 
90 enum RUBOUT = 0x7f;
91 enum ABORT_CHAR = CTRL('G');
92 enum RL_READLINE_VERSION = 0x0402;
93 enum RL_PROMPT_START_IGNORE = '\1';
94 enum RL_PROMPT_END_IGNORE = '\2';
95 
96 /* global variables used by readline enabled applications */
97 
98 extern __gshared const(char)* rl_library_version;
99 extern __gshared int rl_readline_version;
100 extern __gshared char* rl_readline_name;
101 extern __gshared FILE* rl_instream;
102 extern __gshared FILE* rl_outstream;
103 extern __gshared char* rl_line_buffer;
104 extern __gshared int rl_point;
105 extern __gshared int rl_end;
106 extern __gshared int history_base;
107 extern __gshared int history_length;
108 extern __gshared int max_input_history;
109 extern __gshared char* rl_basic_word_break_characters;
110 extern __gshared char* rl_completer_word_break_characters;
111 extern __gshared char* rl_completer_quote_characters;
112 extern __gshared char* function () rl_completion_entry_function;
113 extern __gshared char* function () rl_completion_word_break_hook;
114 extern __gshared char** function () rl_attempted_completion_function;
115 extern __gshared int rl_attempted_completion_over;
116 extern __gshared int rl_completion_type;
117 extern __gshared int rl_completion_query_items;
118 extern __gshared char* rl_special_prefixes;
119 extern __gshared int rl_completion_append_character;
120 extern __gshared int rl_inhibit_completion;
121 extern __gshared int function () rl_pre_input_hook;
122 extern __gshared int function () rl_startup_hook;
123 extern __gshared char* rl_terminal_name;
124 extern __gshared int rl_already_prompted;
125 extern __gshared char* rl_prompt;
126 extern __gshared int rl_done;
127 /*
128  * The following is not implemented
129  */
130 extern __gshared int rl_catch_signals;
131 extern __gshared int rl_catch_sigwinch;
132 extern __gshared KEYMAP_ENTRY_ARRAY emacs_standard_keymap;
133 extern __gshared KEYMAP_ENTRY_ARRAY emacs_meta_keymap;
134 extern __gshared KEYMAP_ENTRY_ARRAY emacs_ctlx_keymap;
135 extern __gshared int rl_filename_completion_desired;
136 extern __gshared int rl_ignore_completion_duplicates;
137 extern __gshared int function (FILE*) rl_getc_function;
138 extern __gshared void function () rl_redisplay_function;
139 extern __gshared void function () rl_completion_display_matches_hook;
140 extern __gshared void function () rl_prep_term_function;
141 extern __gshared void function () rl_deprep_term_function;
142 extern __gshared int readline_echoing_p;
143 extern __gshared int _rl_print_completions_horizontally;
144 
145 /* supported functions */
146 char* readline (const(char)*);
147 int rl_initialize ();
148 
149 void using_history ();
150 int add_history (const(char)*);
151 void clear_history ();
152 int append_history (int, const(char)*);
153 void stifle_history (int);
154 int unstifle_history ();
155 int history_is_stifled ();
156 int where_history ();
157 HIST_ENTRY* current_history ();
158 HIST_ENTRY* history_get (int);
159 HIST_ENTRY* remove_history (int);
160 HIST_ENTRY* replace_history_entry (int, const(char)*, histdata_t);
161 int history_total_bytes ();
162 int history_set_pos (int);
163 HIST_ENTRY* previous_history ();
164 HIST_ENTRY* next_history ();
165 HIST_ENTRY** history_list ();
166 int history_search (const(char)*, int);
167 int history_search_prefix (const(char)*, int);
168 int history_search_pos (const(char)*, int, int);
169 int read_history (const(char)*);
170 int write_history (const(char)*);
171 int history_truncate_file (const(char)*, int);
172 int history_expand (char*, char**);
173 char** history_tokenize (const(char)*);
174 const(char)* get_history_event (const(char)*, int*, int);
175 char* history_arg_extract (int, int, const(char)*);
176 
177 char* tilde_expand (char*);
178 char* filename_completion_function (const(char)*, int);
179 char* username_completion_function (const(char)*, int);
180 int rl_complete (int, int);
181 int rl_read_key ();
182 char** completion_matches (const(char)*, char* function ());
183 void rl_display_match_list (char**, int, int);
184 
185 int rl_insert (int, int);
186 int rl_insert_text (const(char)*);
187 void rl_reset_terminal (const(char)*);
188 void rl_resize_terminal ();
189 int rl_bind_key (int, int function ());
190 int rl_newline (int, int);
191 void rl_callback_read_char ();
192 void rl_callback_handler_install (const(char)*, void function ());
193 void rl_callback_handler_remove ();
194 void rl_redisplay ();
195 int rl_get_previous_history (int, int);
196 void rl_prep_terminal (int);
197 void rl_deprep_terminal ();
198 int rl_read_init_file (const(char)*);
199 int rl_parse_and_bind (const(char)*);
200 int rl_variable_bind (const(char)*, const(char)*);
201 void rl_stuff_char (int);
202 int rl_add_defun (const(char)*, int function (), int);
203 HISTORY_STATE* history_get_history_state ();
204 void rl_get_screen_size (int*, int*);
205 void rl_set_screen_size (int, int);
206 char* rl_filename_completion_function (const(char)*, int);
207 int _rl_abort_internal ();
208 int _rl_qsort_string_compare (char**, char**);
209 char** rl_completion_matches (const(char)*, char* function ());
210 void rl_forced_update_display ();
211 int rl_set_prompt (const(char)*);
212 int rl_on_new_line ();
213 
214 /*
215  * The following are not implemented
216  */
217 int rl_kill_text (int, int);
218 Keymap rl_get_keymap ();
219 void rl_set_keymap (Keymap);
220 Keymap rl_make_bare_keymap ();
221 int rl_generic_bind (int, const(char)*, const(char)*, Keymap);
222 int rl_bind_key_in_map (int, int function (), Keymap);
223 void rl_cleanup_after_signal ();
224 void rl_free_line_state ();
225 int rl_set_keyboard_input_timeout (int);
226 
227 /* _READLINE_H_ */