1/*[clinic input]
2preserve
3[clinic start generated code]*/
4
5PyDoc_STRVAR(readline_parse_and_bind__doc__,
6"parse_and_bind($module, string, /)\n"
7"--\n"
8"\n"
9"Execute the init line provided in the string argument.");
10
11#define READLINE_PARSE_AND_BIND_METHODDEF \
12 {"parse_and_bind", (PyCFunction)readline_parse_and_bind, METH_O, readline_parse_and_bind__doc__},
13
14PyDoc_STRVAR(readline_read_init_file__doc__,
15"read_init_file($module, filename=None, /)\n"
16"--\n"
17"\n"
18"Execute a readline initialization file.\n"
19"\n"
20"The default filename is the last filename used.");
21
22#define READLINE_READ_INIT_FILE_METHODDEF \
23 {"read_init_file", (PyCFunction)(void(*)(void))readline_read_init_file, METH_FASTCALL, readline_read_init_file__doc__},
24
25static PyObject *
26readline_read_init_file_impl(PyObject *module, PyObject *filename_obj);
27
28static PyObject *
29readline_read_init_file(PyObject *module, PyObject *const *args, Py_ssize_t nargs)
30{
31 PyObject *return_value = NULL;
32 PyObject *filename_obj = Py_None;
33
34 if (!_PyArg_CheckPositional("read_init_file", nargs, 0, 1)) {
35 goto exit;
36 }
37 if (nargs < 1) {
38 goto skip_optional;
39 }
40 filename_obj = args[0];
41skip_optional:
42 return_value = readline_read_init_file_impl(module, filename_obj);
43
44exit:
45 return return_value;
46}
47
48PyDoc_STRVAR(readline_read_history_file__doc__,
49"read_history_file($module, filename=None, /)\n"
50"--\n"
51"\n"
52"Load a readline history file.\n"
53"\n"
54"The default filename is ~/.history.");
55
56#define READLINE_READ_HISTORY_FILE_METHODDEF \
57 {"read_history_file", (PyCFunction)(void(*)(void))readline_read_history_file, METH_FASTCALL, readline_read_history_file__doc__},
58
59static PyObject *
60readline_read_history_file_impl(PyObject *module, PyObject *filename_obj);
61
62static PyObject *
63readline_read_history_file(PyObject *module, PyObject *const *args, Py_ssize_t nargs)
64{
65 PyObject *return_value = NULL;
66 PyObject *filename_obj = Py_None;
67
68 if (!_PyArg_CheckPositional("read_history_file", nargs, 0, 1)) {
69 goto exit;
70 }
71 if (nargs < 1) {
72 goto skip_optional;
73 }
74 filename_obj = args[0];
75skip_optional:
76 return_value = readline_read_history_file_impl(module, filename_obj);
77
78exit:
79 return return_value;
80}
81
82PyDoc_STRVAR(readline_write_history_file__doc__,
83"write_history_file($module, filename=None, /)\n"
84"--\n"
85"\n"
86"Save a readline history file.\n"
87"\n"
88"The default filename is ~/.history.");
89
90#define READLINE_WRITE_HISTORY_FILE_METHODDEF \
91 {"write_history_file", (PyCFunction)(void(*)(void))readline_write_history_file, METH_FASTCALL, readline_write_history_file__doc__},
92
93static PyObject *
94readline_write_history_file_impl(PyObject *module, PyObject *filename_obj);
95
96static PyObject *
97readline_write_history_file(PyObject *module, PyObject *const *args, Py_ssize_t nargs)
98{
99 PyObject *return_value = NULL;
100 PyObject *filename_obj = Py_None;
101
102 if (!_PyArg_CheckPositional("write_history_file", nargs, 0, 1)) {
103 goto exit;
104 }
105 if (nargs < 1) {
106 goto skip_optional;
107 }
108 filename_obj = args[0];
109skip_optional:
110 return_value = readline_write_history_file_impl(module, filename_obj);
111
112exit:
113 return return_value;
114}
115
116#if defined(HAVE_RL_APPEND_HISTORY)
117
118PyDoc_STRVAR(readline_append_history_file__doc__,
119"append_history_file($module, nelements, filename=None, /)\n"
120"--\n"
121"\n"
122"Append the last nelements items of the history list to file.\n"
123"\n"
124"The default filename is ~/.history.");
125
126#define READLINE_APPEND_HISTORY_FILE_METHODDEF \
127 {"append_history_file", (PyCFunction)(void(*)(void))readline_append_history_file, METH_FASTCALL, readline_append_history_file__doc__},
128
129static PyObject *
130readline_append_history_file_impl(PyObject *module, int nelements,
131 PyObject *filename_obj);
132
133static PyObject *
134readline_append_history_file(PyObject *module, PyObject *const *args, Py_ssize_t nargs)
135{
136 PyObject *return_value = NULL;
137 int nelements;
138 PyObject *filename_obj = Py_None;
139
140 if (!_PyArg_CheckPositional("append_history_file", nargs, 1, 2)) {
141 goto exit;
142 }
143 nelements = _PyLong_AsInt(args[0]);
144 if (nelements == -1 && PyErr_Occurred()) {
145 goto exit;
146 }
147 if (nargs < 2) {
148 goto skip_optional;
149 }
150 filename_obj = args[1];
151skip_optional:
152 return_value = readline_append_history_file_impl(module, nelements, filename_obj);
153
154exit:
155 return return_value;
156}
157
158#endif /* defined(HAVE_RL_APPEND_HISTORY) */
159
160PyDoc_STRVAR(readline_set_history_length__doc__,
161"set_history_length($module, length, /)\n"
162"--\n"
163"\n"
164"Set the maximal number of lines which will be written to the history file.\n"
165"\n"
166"A negative length is used to inhibit history truncation.");
167
168#define READLINE_SET_HISTORY_LENGTH_METHODDEF \
169 {"set_history_length", (PyCFunction)readline_set_history_length, METH_O, readline_set_history_length__doc__},
170
171static PyObject *
172readline_set_history_length_impl(PyObject *module, int length);
173
174static PyObject *
175readline_set_history_length(PyObject *module, PyObject *arg)
176{
177 PyObject *return_value = NULL;
178 int length;
179
180 length = _PyLong_AsInt(arg);
181 if (length == -1 && PyErr_Occurred()) {
182 goto exit;
183 }
184 return_value = readline_set_history_length_impl(module, length);
185
186exit:
187 return return_value;
188}
189
190PyDoc_STRVAR(readline_get_history_length__doc__,
191"get_history_length($module, /)\n"
192"--\n"
193"\n"
194"Return the maximum number of lines that will be written to the history file.");
195
196#define READLINE_GET_HISTORY_LENGTH_METHODDEF \
197 {"get_history_length", (PyCFunction)readline_get_history_length, METH_NOARGS, readline_get_history_length__doc__},
198
199static PyObject *
200readline_get_history_length_impl(PyObject *module);
201
202static PyObject *
203readline_get_history_length(PyObject *module, PyObject *Py_UNUSED(ignored))
204{
205 return readline_get_history_length_impl(module);
206}
207
208PyDoc_STRVAR(readline_set_completion_display_matches_hook__doc__,
209"set_completion_display_matches_hook($module, function=None, /)\n"
210"--\n"
211"\n"
212"Set or remove the completion display function.\n"
213"\n"
214"The function is called as\n"
215" function(substitution, [matches], longest_match_length)\n"
216"once each time matches need to be displayed.");
217
218#define READLINE_SET_COMPLETION_DISPLAY_MATCHES_HOOK_METHODDEF \
219 {"set_completion_display_matches_hook", (PyCFunction)(void(*)(void))readline_set_completion_display_matches_hook, METH_FASTCALL, readline_set_completion_display_matches_hook__doc__},
220
221static PyObject *
222readline_set_completion_display_matches_hook_impl(PyObject *module,
223 PyObject *function);
224
225static PyObject *
226readline_set_completion_display_matches_hook(PyObject *module, PyObject *const *args, Py_ssize_t nargs)
227{
228 PyObject *return_value = NULL;
229 PyObject *function = Py_None;
230
231 if (!_PyArg_CheckPositional("set_completion_display_matches_hook", nargs, 0, 1)) {
232 goto exit;
233 }
234 if (nargs < 1) {
235 goto skip_optional;
236 }
237 function = args[0];
238skip_optional:
239 return_value = readline_set_completion_display_matches_hook_impl(module, function);
240
241exit:
242 return return_value;
243}
244
245PyDoc_STRVAR(readline_set_startup_hook__doc__,
246"set_startup_hook($module, function=None, /)\n"
247"--\n"
248"\n"
249"Set or remove the function invoked by the rl_startup_hook callback.\n"
250"\n"
251"The function is called with no arguments just\n"
252"before readline prints the first prompt.");
253
254#define READLINE_SET_STARTUP_HOOK_METHODDEF \
255 {"set_startup_hook", (PyCFunction)(void(*)(void))readline_set_startup_hook, METH_FASTCALL, readline_set_startup_hook__doc__},
256
257static PyObject *
258readline_set_startup_hook_impl(PyObject *module, PyObject *function);
259
260static PyObject *
261readline_set_startup_hook(PyObject *module, PyObject *const *args, Py_ssize_t nargs)
262{
263 PyObject *return_value = NULL;
264 PyObject *function = Py_None;
265
266 if (!_PyArg_CheckPositional("set_startup_hook", nargs, 0, 1)) {
267 goto exit;
268 }
269 if (nargs < 1) {
270 goto skip_optional;
271 }
272 function = args[0];
273skip_optional:
274 return_value = readline_set_startup_hook_impl(module, function);
275
276exit:
277 return return_value;
278}
279
280#if defined(HAVE_RL_PRE_INPUT_HOOK)
281
282PyDoc_STRVAR(readline_set_pre_input_hook__doc__,
283"set_pre_input_hook($module, function=None, /)\n"
284"--\n"
285"\n"
286"Set or remove the function invoked by the rl_pre_input_hook callback.\n"
287"\n"
288"The function is called with no arguments after the first prompt\n"
289"has been printed and just before readline starts reading input\n"
290"characters.");
291
292#define READLINE_SET_PRE_INPUT_HOOK_METHODDEF \
293 {"set_pre_input_hook", (PyCFunction)(void(*)(void))readline_set_pre_input_hook, METH_FASTCALL, readline_set_pre_input_hook__doc__},
294
295static PyObject *
296readline_set_pre_input_hook_impl(PyObject *module, PyObject *function);
297
298static PyObject *
299readline_set_pre_input_hook(PyObject *module, PyObject *const *args, Py_ssize_t nargs)
300{
301 PyObject *return_value = NULL;
302 PyObject *function = Py_None;
303
304 if (!_PyArg_CheckPositional("set_pre_input_hook", nargs, 0, 1)) {
305 goto exit;
306 }
307 if (nargs < 1) {
308 goto skip_optional;
309 }
310 function = args[0];
311skip_optional:
312 return_value = readline_set_pre_input_hook_impl(module, function);
313
314exit:
315 return return_value;
316}
317
318#endif /* defined(HAVE_RL_PRE_INPUT_HOOK) */
319
320PyDoc_STRVAR(readline_get_completion_type__doc__,
321"get_completion_type($module, /)\n"
322"--\n"
323"\n"
324"Get the type of completion being attempted.");
325
326#define READLINE_GET_COMPLETION_TYPE_METHODDEF \
327 {"get_completion_type", (PyCFunction)readline_get_completion_type, METH_NOARGS, readline_get_completion_type__doc__},
328
329static PyObject *
330readline_get_completion_type_impl(PyObject *module);
331
332static PyObject *
333readline_get_completion_type(PyObject *module, PyObject *Py_UNUSED(ignored))
334{
335 return readline_get_completion_type_impl(module);
336}
337
338PyDoc_STRVAR(readline_get_begidx__doc__,
339"get_begidx($module, /)\n"
340"--\n"
341"\n"
342"Get the beginning index of the completion scope.");
343
344#define READLINE_GET_BEGIDX_METHODDEF \
345 {"get_begidx", (PyCFunction)readline_get_begidx, METH_NOARGS, readline_get_begidx__doc__},
346
347static PyObject *
348readline_get_begidx_impl(PyObject *module);
349
350static PyObject *
351readline_get_begidx(PyObject *module, PyObject *Py_UNUSED(ignored))
352{
353 return readline_get_begidx_impl(module);
354}
355
356PyDoc_STRVAR(readline_get_endidx__doc__,
357"get_endidx($module, /)\n"
358"--\n"
359"\n"
360"Get the ending index of the completion scope.");
361
362#define READLINE_GET_ENDIDX_METHODDEF \
363 {"get_endidx", (PyCFunction)readline_get_endidx, METH_NOARGS, readline_get_endidx__doc__},
364
365static PyObject *
366readline_get_endidx_impl(PyObject *module);
367
368static PyObject *
369readline_get_endidx(PyObject *module, PyObject *Py_UNUSED(ignored))
370{
371 return readline_get_endidx_impl(module);
372}
373
374PyDoc_STRVAR(readline_set_completer_delims__doc__,
375"set_completer_delims($module, string, /)\n"
376"--\n"
377"\n"
378"Set the word delimiters for completion.");
379
380#define READLINE_SET_COMPLETER_DELIMS_METHODDEF \
381 {"set_completer_delims", (PyCFunction)readline_set_completer_delims, METH_O, readline_set_completer_delims__doc__},
382
383PyDoc_STRVAR(readline_remove_history_item__doc__,
384"remove_history_item($module, pos, /)\n"
385"--\n"
386"\n"
387"Remove history item given by its zero-based position.");
388
389#define READLINE_REMOVE_HISTORY_ITEM_METHODDEF \
390 {"remove_history_item", (PyCFunction)readline_remove_history_item, METH_O, readline_remove_history_item__doc__},
391
392static PyObject *
393readline_remove_history_item_impl(PyObject *module, int entry_number);
394
395static PyObject *
396readline_remove_history_item(PyObject *module, PyObject *arg)
397{
398 PyObject *return_value = NULL;
399 int entry_number;
400
401 entry_number = _PyLong_AsInt(arg);
402 if (entry_number == -1 && PyErr_Occurred()) {
403 goto exit;
404 }
405 return_value = readline_remove_history_item_impl(module, entry_number);
406
407exit:
408 return return_value;
409}
410
411PyDoc_STRVAR(readline_replace_history_item__doc__,
412"replace_history_item($module, pos, line, /)\n"
413"--\n"
414"\n"
415"Replaces history item given by its position with contents of line.\n"
416"\n"
417"pos is zero-based.");
418
419#define READLINE_REPLACE_HISTORY_ITEM_METHODDEF \
420 {"replace_history_item", (PyCFunction)(void(*)(void))readline_replace_history_item, METH_FASTCALL, readline_replace_history_item__doc__},
421
422static PyObject *
423readline_replace_history_item_impl(PyObject *module, int entry_number,
424 PyObject *line);
425
426static PyObject *
427readline_replace_history_item(PyObject *module, PyObject *const *args, Py_ssize_t nargs)
428{
429 PyObject *return_value = NULL;
430 int entry_number;
431 PyObject *line;
432
433 if (!_PyArg_CheckPositional("replace_history_item", nargs, 2, 2)) {
434 goto exit;
435 }
436 entry_number = _PyLong_AsInt(args[0]);
437 if (entry_number == -1 && PyErr_Occurred()) {
438 goto exit;
439 }
440 if (!PyUnicode_Check(args[1])) {
441 _PyArg_BadArgument("replace_history_item", "argument 2", "str", args[1]);
442 goto exit;
443 }
444 if (PyUnicode_READY(args[1]) == -1) {
445 goto exit;
446 }
447 line = args[1];
448 return_value = readline_replace_history_item_impl(module, entry_number, line);
449
450exit:
451 return return_value;
452}
453
454PyDoc_STRVAR(readline_add_history__doc__,
455"add_history($module, string, /)\n"
456"--\n"
457"\n"
458"Add an item to the history buffer.");
459
460#define READLINE_ADD_HISTORY_METHODDEF \
461 {"add_history", (PyCFunction)readline_add_history, METH_O, readline_add_history__doc__},
462
463PyDoc_STRVAR(readline_set_auto_history__doc__,
464"set_auto_history($module, enabled, /)\n"
465"--\n"
466"\n"
467"Enables or disables automatic history.");
468
469#define READLINE_SET_AUTO_HISTORY_METHODDEF \
470 {"set_auto_history", (PyCFunction)readline_set_auto_history, METH_O, readline_set_auto_history__doc__},
471
472static PyObject *
473readline_set_auto_history_impl(PyObject *module,
474 int _should_auto_add_history);
475
476static PyObject *
477readline_set_auto_history(PyObject *module, PyObject *arg)
478{
479 PyObject *return_value = NULL;
480 int _should_auto_add_history;
481
482 _should_auto_add_history = PyObject_IsTrue(arg);
483 if (_should_auto_add_history < 0) {
484 goto exit;
485 }
486 return_value = readline_set_auto_history_impl(module, _should_auto_add_history);
487
488exit:
489 return return_value;
490}
491
492PyDoc_STRVAR(readline_get_completer_delims__doc__,
493"get_completer_delims($module, /)\n"
494"--\n"
495"\n"
496"Get the word delimiters for completion.");
497
498#define READLINE_GET_COMPLETER_DELIMS_METHODDEF \
499 {"get_completer_delims", (PyCFunction)readline_get_completer_delims, METH_NOARGS, readline_get_completer_delims__doc__},
500
501static PyObject *
502readline_get_completer_delims_impl(PyObject *module);
503
504static PyObject *
505readline_get_completer_delims(PyObject *module, PyObject *Py_UNUSED(ignored))
506{
507 return readline_get_completer_delims_impl(module);
508}
509
510PyDoc_STRVAR(readline_set_completer__doc__,
511"set_completer($module, function=None, /)\n"
512"--\n"
513"\n"
514"Set or remove the completer function.\n"
515"\n"
516"The function is called as function(text, state),\n"
517"for state in 0, 1, 2, ..., until it returns a non-string.\n"
518"It should return the next possible completion starting with \'text\'.");
519
520#define READLINE_SET_COMPLETER_METHODDEF \
521 {"set_completer", (PyCFunction)(void(*)(void))readline_set_completer, METH_FASTCALL, readline_set_completer__doc__},
522
523static PyObject *
524readline_set_completer_impl(PyObject *module, PyObject *function);
525
526static PyObject *
527readline_set_completer(PyObject *module, PyObject *const *args, Py_ssize_t nargs)
528{
529 PyObject *return_value = NULL;
530 PyObject *function = Py_None;
531
532 if (!_PyArg_CheckPositional("set_completer", nargs, 0, 1)) {
533 goto exit;
534 }
535 if (nargs < 1) {
536 goto skip_optional;
537 }
538 function = args[0];
539skip_optional:
540 return_value = readline_set_completer_impl(module, function);
541
542exit:
543 return return_value;
544}
545
546PyDoc_STRVAR(readline_get_completer__doc__,
547"get_completer($module, /)\n"
548"--\n"
549"\n"
550"Get the current completer function.");
551
552#define READLINE_GET_COMPLETER_METHODDEF \
553 {"get_completer", (PyCFunction)readline_get_completer, METH_NOARGS, readline_get_completer__doc__},
554
555static PyObject *
556readline_get_completer_impl(PyObject *module);
557
558static PyObject *
559readline_get_completer(PyObject *module, PyObject *Py_UNUSED(ignored))
560{
561 return readline_get_completer_impl(module);
562}
563
564PyDoc_STRVAR(readline_get_history_item__doc__,
565"get_history_item($module, index, /)\n"
566"--\n"
567"\n"
568"Return the current contents of history item at one-based index.");
569
570#define READLINE_GET_HISTORY_ITEM_METHODDEF \
571 {"get_history_item", (PyCFunction)readline_get_history_item, METH_O, readline_get_history_item__doc__},
572
573static PyObject *
574readline_get_history_item_impl(PyObject *module, int idx);
575
576static PyObject *
577readline_get_history_item(PyObject *module, PyObject *arg)
578{
579 PyObject *return_value = NULL;
580 int idx;
581
582 idx = _PyLong_AsInt(arg);
583 if (idx == -1 && PyErr_Occurred()) {
584 goto exit;
585 }
586 return_value = readline_get_history_item_impl(module, idx);
587
588exit:
589 return return_value;
590}
591
592PyDoc_STRVAR(readline_get_current_history_length__doc__,
593"get_current_history_length($module, /)\n"
594"--\n"
595"\n"
596"Return the current (not the maximum) length of history.");
597
598#define READLINE_GET_CURRENT_HISTORY_LENGTH_METHODDEF \
599 {"get_current_history_length", (PyCFunction)readline_get_current_history_length, METH_NOARGS, readline_get_current_history_length__doc__},
600
601static PyObject *
602readline_get_current_history_length_impl(PyObject *module);
603
604static PyObject *
605readline_get_current_history_length(PyObject *module, PyObject *Py_UNUSED(ignored))
606{
607 return readline_get_current_history_length_impl(module);
608}
609
610PyDoc_STRVAR(readline_get_line_buffer__doc__,
611"get_line_buffer($module, /)\n"
612"--\n"
613"\n"
614"Return the current contents of the line buffer.");
615
616#define READLINE_GET_LINE_BUFFER_METHODDEF \
617 {"get_line_buffer", (PyCFunction)readline_get_line_buffer, METH_NOARGS, readline_get_line_buffer__doc__},
618
619static PyObject *
620readline_get_line_buffer_impl(PyObject *module);
621
622static PyObject *
623readline_get_line_buffer(PyObject *module, PyObject *Py_UNUSED(ignored))
624{
625 return readline_get_line_buffer_impl(module);
626}
627
628#if defined(HAVE_RL_COMPLETION_APPEND_CHARACTER)
629
630PyDoc_STRVAR(readline_clear_history__doc__,
631"clear_history($module, /)\n"
632"--\n"
633"\n"
634"Clear the current readline history.");
635
636#define READLINE_CLEAR_HISTORY_METHODDEF \
637 {"clear_history", (PyCFunction)readline_clear_history, METH_NOARGS, readline_clear_history__doc__},
638
639static PyObject *
640readline_clear_history_impl(PyObject *module);
641
642static PyObject *
643readline_clear_history(PyObject *module, PyObject *Py_UNUSED(ignored))
644{
645 return readline_clear_history_impl(module);
646}
647
648#endif /* defined(HAVE_RL_COMPLETION_APPEND_CHARACTER) */
649
650PyDoc_STRVAR(readline_insert_text__doc__,
651"insert_text($module, string, /)\n"
652"--\n"
653"\n"
654"Insert text into the line buffer at the cursor position.");
655
656#define READLINE_INSERT_TEXT_METHODDEF \
657 {"insert_text", (PyCFunction)readline_insert_text, METH_O, readline_insert_text__doc__},
658
659PyDoc_STRVAR(readline_redisplay__doc__,
660"redisplay($module, /)\n"
661"--\n"
662"\n"
663"Change what\'s displayed on the screen to reflect contents of the line buffer.");
664
665#define READLINE_REDISPLAY_METHODDEF \
666 {"redisplay", (PyCFunction)readline_redisplay, METH_NOARGS, readline_redisplay__doc__},
667
668static PyObject *
669readline_redisplay_impl(PyObject *module);
670
671static PyObject *
672readline_redisplay(PyObject *module, PyObject *Py_UNUSED(ignored))
673{
674 return readline_redisplay_impl(module);
675}
676
677#ifndef READLINE_APPEND_HISTORY_FILE_METHODDEF
678 #define READLINE_APPEND_HISTORY_FILE_METHODDEF
679#endif /* !defined(READLINE_APPEND_HISTORY_FILE_METHODDEF) */
680
681#ifndef READLINE_SET_PRE_INPUT_HOOK_METHODDEF
682 #define READLINE_SET_PRE_INPUT_HOOK_METHODDEF
683#endif /* !defined(READLINE_SET_PRE_INPUT_HOOK_METHODDEF) */
684
685#ifndef READLINE_CLEAR_HISTORY_METHODDEF
686 #define READLINE_CLEAR_HISTORY_METHODDEF
687#endif /* !defined(READLINE_CLEAR_HISTORY_METHODDEF) */
688/*[clinic end generated code: output=f7d390113b27989f input=a9049054013a1b77]*/
689