Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
Roblox
GitHub Repository: Roblox/luau
Path: blob/master/extern/isocline/include/isocline.h
2727 views
1
/* ----------------------------------------------------------------------------
2
Copyright (c) 2021, Daan Leijen
3
This is free software; you can redistribute it and/or modify it
4
under the terms of the MIT License. A copy of the license can be
5
found in the "LICENSE" file at the root of this distribution.
6
-----------------------------------------------------------------------------*/
7
#pragma once
8
#ifndef IC_ISOCLINE_H
9
#define IC_ISOCLINE_H
10
11
#ifdef __cplusplus
12
extern "C" {
13
#endif
14
15
#include <stddef.h> // size_t
16
#include <stdbool.h> // bool
17
#include <stdint.h> // uint32_t
18
#include <stdarg.h> // term_vprintf
19
20
21
/*! \mainpage
22
Isocline C API reference.
23
24
Isocline is a pure C library that can be used as an alternative to the GNU readline library.
25
26
See the [Github repository](https://github.com/daanx/isocline#readme)
27
for general information and building the library.
28
29
Contents:
30
- \ref readline
31
- \ref bbcode
32
- \ref history
33
- \ref completion
34
- \ref highlight
35
- \ref options
36
- \ref helper
37
- \ref completex
38
- \ref term
39
- \ref async
40
- \ref alloc
41
*/
42
43
/// \defgroup readline Readline
44
/// The basic readline interface.
45
/// \{
46
47
/// Isocline version: 102 = 1.0.2.
48
#define IC_VERSION (104)
49
50
51
/// Read input from the user using rich editing abilities.
52
/// @param prompt_text The prompt text, can be NULL for the default ("").
53
/// The displayed prompt becomes `prompt_text` followed by the `prompt_marker` ("> ").
54
/// @returns the heap allocated input on succes, which should be `free`d by the caller.
55
/// Returns NULL on error, or if the user typed ctrl+d or ctrl+c.
56
///
57
/// If the standard input (`stdin`) has no editing capability
58
/// (like a dumb terminal (e.g. `TERM`=`dumb`), running in a debuggen, a pipe or redirected file, etc.)
59
/// the input is read directly from the input stream up to the
60
/// next line without editing capability.
61
/// See also \a ic_set_prompt_marker(), \a ic_style_def()
62
///
63
/// @see ic_set_prompt_marker(), ic_style_def()
64
char* ic_readline(const char* prompt_text);
65
66
/// \}
67
68
69
//--------------------------------------------------------------
70
/// \defgroup bbcode Formatted Text
71
/// Formatted text using [bbcode markup](https://github.com/daanx/isocline#bbcode-format).
72
/// \{
73
74
/// Print to the terminal while respection bbcode markup.
75
/// Any unclosed tags are closed automatically at the end of the print.
76
/// For example:
77
/// ```
78
/// ic_print("[b]bold, [i]bold and italic[/i], [red]red and bold[/][/b] default.");
79
/// ic_print("[b]bold[/], [i b]bold and italic[/], [yellow on blue]yellow on blue background");
80
/// ic_style_add("em","i color=#888800");
81
/// ic_print("[em]emphasis");
82
/// ```
83
/// Properties that can be assigned are:
84
/// * `color=` _clr_, `bgcolor=` _clr_: where _clr_ is either a hex value `#`RRGGBB or `#`RGB, a
85
/// standard HTML color name, or an ANSI palette name, like `ansi-maroon`, `ansi-default`, etc.
86
/// * `bold`,`italic`,`reverse`,`underline`: can be `on` or `off`.
87
/// * everything else is a style; all HTML and ANSI color names are also a style (so we can just use `red`
88
/// instead of `color=red`, or `on red` instead of `bgcolor=red`), and there are
89
/// the `b`, `i`, `u`, and `r` styles for bold, italic, underline, and reverse.
90
///
91
/// See [here](https://github.com/daanx/isocline#bbcode-format) for a description of the full bbcode format.
92
void ic_print( const char* s );
93
94
/// Print with bbcode markup ending with a newline.
95
/// @see ic_print()
96
void ic_println( const char* s );
97
98
/// Print formatted with bbcode markup.
99
/// @see ic_print()
100
void ic_printf(const char* fmt, ...);
101
102
/// Print formatted with bbcode markup.
103
/// @see ic_print
104
void ic_vprintf(const char* fmt, va_list args);
105
106
/// Define or redefine a style.
107
/// @param style_name The name of the style.
108
/// @param fmt The `fmt` string is the content of a tag and can contain
109
/// other styles. This is very useful to theme the output of a program
110
/// by assigning standard styles like `em` or `warning` etc.
111
void ic_style_def( const char* style_name, const char* fmt );
112
113
/// Start a global style that is only reset when calling a matching ic_style_close().
114
void ic_style_open( const char* fmt );
115
116
/// End a global style.
117
void ic_style_close(void);
118
119
/// \}
120
121
122
//--------------------------------------------------------------
123
// History
124
//--------------------------------------------------------------
125
/// \defgroup history History
126
/// Readline input history.
127
/// \{
128
129
/// Enable history.
130
/// Use a \a NULL filename to not persist the history. Use -1 for max_entries to get the default (200).
131
void ic_set_history(const char* fname, long max_entries );
132
133
/// Remove the last entry in the history.
134
/// The last returned input from ic_readline() is automatically added to the history; this function removes it.
135
void ic_history_remove_last(void);
136
137
/// Clear the history.
138
void ic_history_clear(void);
139
140
/// Add an entry to the history
141
void ic_history_add( const char* entry );
142
143
/// \}
144
145
//--------------------------------------------------------------
146
// Basic Completion
147
//--------------------------------------------------------------
148
149
/// \defgroup completion Completion
150
/// Basic word completion.
151
/// \{
152
153
/// A completion environment
154
struct ic_completion_env_s;
155
156
/// A completion environment
157
typedef struct ic_completion_env_s ic_completion_env_t;
158
159
/// A completion callback that is called by isocline when tab is pressed.
160
/// It is passed a completion environment (containing the current input and the current cursor position),
161
/// the current input up-to the cursor (`prefix`)
162
/// and the user given argument when the callback was set.
163
/// When using completion transformers, like `ic_complete_quoted_word` the `prefix` contains the
164
/// the word to be completed without escape characters or quotes.
165
typedef void (ic_completer_fun_t)(ic_completion_env_t* cenv, const char* prefix );
166
167
/// Set the default completion handler.
168
/// @param completer The completion function
169
/// @param arg Argument passed to the \a completer.
170
/// There can only be one default completion function, setting it again disables the previous one.
171
/// The initial completer use `ic_complete_filename`.
172
void ic_set_default_completer( ic_completer_fun_t* completer, void* arg);
173
174
175
/// In a completion callback (usually from ic_complete_word()), use this function to add a completion.
176
/// (the completion string is copied by isocline and do not need to be preserved or allocated).
177
///
178
/// Returns `true` if the callback should continue trying to find more possible completions.
179
/// If `false` is returned, the callback should try to return and not add more completions (for improved latency).
180
bool ic_add_completion(ic_completion_env_t* cenv, const char* completion);
181
182
/// In a completion callback (usually from ic_complete_word()), use this function to add a completion.
183
/// The `display` is used to display the completion in the completion menu, and `help` is
184
/// displayed for hints for example. Both can be `NULL` for the default.
185
/// (all are copied by isocline and do not need to be preserved or allocated).
186
///
187
/// Returns `true` if the callback should continue trying to find more possible completions.
188
/// If `false` is returned, the callback should try to return and not add more completions (for improved latency).
189
bool ic_add_completion_ex( ic_completion_env_t* cenv, const char* completion, const char* display, const char* help );
190
191
/// In a completion callback (usually from ic_complete_word()), use this function to add completions.
192
/// The `completions` array should be terminated with a NULL element, and all elements
193
/// are added as completions if they start with `prefix`.
194
///
195
/// Returns `true` if the callback should continue trying to find more possible completions.
196
/// If `false` is returned, the callback should try to return and not add more completions (for improved latency).
197
bool ic_add_completions(ic_completion_env_t* cenv, const char* prefix, const char** completions);
198
199
/// Complete a filename.
200
/// Complete a filename given a semi-colon separated list of root directories `roots` and
201
/// semi-colon separated list of possible extensions (excluding directories).
202
/// If `roots` is NULL, the current directory is the root (".").
203
/// If `extensions` is NULL, any extension will match.
204
/// Each root directory should _not_ end with a directory separator.
205
/// If a directory is completed, the `dir_separator` is added at the end if it is not `0`.
206
/// Usually the `dir_separator` is `/` but it can be set to `\\` on Windows systems.
207
/// For example:
208
/// ```
209
/// /ho --> /home/
210
/// /home/.ba --> /home/.bashrc
211
/// ```
212
/// (This already uses ic_complete_quoted_word() so do not call it from inside a word handler).
213
void ic_complete_filename( ic_completion_env_t* cenv, const char* prefix, char dir_separator, const char* roots, const char* extensions );
214
215
216
217
/// Function that returns whether a (utf8) character (of length `len`) is in a certain character class
218
/// @see ic_char_is_separator() etc.
219
typedef bool (ic_is_char_class_fun_t)(const char* s, long len);
220
221
222
/// Complete a _word_ (i.e. _token_).
223
/// Calls the user provided function `fun` to complete on the
224
/// current _word_. Almost all user provided completers should use this function.
225
/// If `is_word_char` is NULL, the default `&ic_char_is_nonseparator` is used.
226
/// The `prefix` passed to `fun` is modified to only contain the current word, and
227
/// any results from `ic_add_completion` are automatically adjusted to replace that part.
228
/// For example, on the input "hello w", a the user `fun` only gets `w` and can just complete
229
/// with "world" resulting in "hello world" without needing to consider `delete_before` etc.
230
/// @see ic_complete_qword() for completing quoted and escaped tokens.
231
void ic_complete_word(ic_completion_env_t* cenv, const char* prefix, ic_completer_fun_t* fun, ic_is_char_class_fun_t* is_word_char);
232
233
234
/// Complete a quoted _word_.
235
/// Calls the user provided function `fun` to complete while taking
236
/// care of quotes and escape characters. Almost all user provided completers should use
237
/// this function. The `prefix` passed to `fun` is modified to be unquoted and unescaped, and
238
/// any results from `ic_add_completion` are automatically quoted and escaped again.
239
/// For example, completing `hello world`, the `fun` always just completes `hel` or `hello w` to `hello world`,
240
/// but depending on user input, it will complete as:
241
/// ```
242
/// hel --> hello\ world
243
/// hello\ w --> hello\ world
244
/// hello w --> # no completion, the word is just 'w'>
245
/// "hel --> "hello world"
246
/// "hello w --> "hello world"
247
/// ```
248
/// with proper quotes and escapes.
249
/// If `is_word_char` is NULL, the default `&ic_char_is_nonseparator` is used.
250
/// @see ic_complete_quoted_word() to customize the word boundary, quotes etc.
251
void ic_complete_qword( ic_completion_env_t* cenv, const char* prefix, ic_completer_fun_t* fun, ic_is_char_class_fun_t* is_word_char );
252
253
254
255
/// Complete a _word_.
256
/// Calls the user provided function `fun` to complete while taking
257
/// care of quotes and escape characters. Almost all user provided completers should use this function.
258
/// The `is_word_char` is a set of characters that are part of a "word". Use NULL for the default (`&ic_char_is_nonseparator`).
259
/// The `escape_char` is the escaping character, usually `\` but use 0 to not have escape characters.
260
/// The `quote_chars` define the quotes, use NULL for the default `"\'\""` quotes.
261
/// @see ic_complete_word() which uses the default values for `non_word_chars`, `quote_chars` and `\` for escape characters.
262
void ic_complete_qword_ex( ic_completion_env_t* cenv, const char* prefix, ic_completer_fun_t* fun,
263
ic_is_char_class_fun_t* is_word_char, char escape_char, const char* quote_chars );
264
265
/// \}
266
267
//--------------------------------------------------------------
268
/// \defgroup highlight Syntax Highlighting
269
/// Basic syntax highlighting.
270
/// \{
271
272
/// A syntax highlight environment
273
struct ic_highlight_env_s;
274
typedef struct ic_highlight_env_s ic_highlight_env_t;
275
276
/// A syntax highlighter callback that is called by readline to syntax highlight user input.
277
typedef void (ic_highlight_fun_t)(ic_highlight_env_t* henv, const char* input, void* arg);
278
279
/// Set a syntax highlighter.
280
/// There can only be one highlight function, setting it again disables the previous one.
281
void ic_set_default_highlighter(ic_highlight_fun_t* highlighter, void* arg);
282
283
/// Set the style of characters starting at position `pos`.
284
void ic_highlight(ic_highlight_env_t* henv, long pos, long count, const char* style );
285
286
/// Experimental: Convenience callback for a function that highlights `s` using bbcode's.
287
/// The returned string should be allocated and is free'd by the caller.
288
typedef char* (ic_highlight_format_fun_t)(const char* s, void* arg);
289
290
/// Experimental: Convenience function for highlighting with bbcodes.
291
/// Can be called in a `ic_highlight_fun_t` callback to colorize the `input` using the
292
/// the provided `formatted` input that is the styled `input` with bbcodes. The
293
/// content of `formatted` without bbcode tags should match `input` exactly.
294
void ic_highlight_formatted(ic_highlight_env_t* henv, const char* input, const char* formatted);
295
296
/// \}
297
298
//--------------------------------------------------------------
299
// Readline with a specific completer and highlighter
300
//--------------------------------------------------------------
301
302
/// \defgroup readline
303
/// \{
304
305
/// Read input from the user using rich editing abilities,
306
/// using a particular completion function and highlighter for this call only.
307
/// both can be NULL in which case the defaults are used.
308
/// @see ic_readline(), ic_set_prompt_marker(), ic_set_default_completer(), ic_set_default_highlighter().
309
char* ic_readline_ex(const char* prompt_text, ic_completer_fun_t* completer, void* completer_arg,
310
ic_highlight_fun_t* highlighter, void* highlighter_arg);
311
312
/// \}
313
314
315
//--------------------------------------------------------------
316
// Options
317
//--------------------------------------------------------------
318
319
/// \defgroup options Options
320
/// \{
321
322
/// Set a prompt marker and a potential marker for extra lines with multiline input.
323
/// Pass \a NULL for the `prompt_marker` for the default marker (`"> "`).
324
/// Pass \a NULL for continuation prompt marker to make it equal to the `prompt_marker`.
325
void ic_set_prompt_marker( const char* prompt_marker, const char* continuation_prompt_marker );
326
327
/// Get the current prompt marker.
328
const char* ic_get_prompt_marker(void);
329
330
/// Get the current continuation prompt marker.
331
const char* ic_get_continuation_prompt_marker(void);
332
333
/// Disable or enable multi-line input (enabled by default).
334
/// Returns the previous setting.
335
bool ic_enable_multiline( bool enable );
336
337
/// Disable or enable sound (enabled by default).
338
/// A beep is used when tab cannot find any completion for example.
339
/// Returns the previous setting.
340
bool ic_enable_beep( bool enable );
341
342
/// Disable or enable color output (enabled by default).
343
/// Returns the previous setting.
344
bool ic_enable_color( bool enable );
345
346
/// Disable or enable duplicate entries in the history (disabled by default).
347
/// Returns the previous setting.
348
bool ic_enable_history_duplicates( bool enable );
349
350
/// Disable or enable automatic tab completion after a completion
351
/// to expand as far as possible if the completions are unique. (disabled by default).
352
/// Returns the previous setting.
353
bool ic_enable_auto_tab( bool enable );
354
355
/// Disable or enable preview of a completion selection (enabled by default)
356
/// Returns the previous setting.
357
bool ic_enable_completion_preview( bool enable );
358
359
/// Disable or enable automatic identation of continuation lines in multiline
360
/// input so it aligns with the initial prompt.
361
/// Returns the previous setting.
362
bool ic_enable_multiline_indent(bool enable);
363
364
/// Disable or enable display of short help messages for history search etc.
365
/// (full help is always dispayed when pressing F1 regardless of this setting)
366
/// @returns the previous setting.
367
bool ic_enable_inline_help(bool enable);
368
369
/// Disable or enable hinting (enabled by default)
370
/// Shows a hint inline when there is a single possible completion.
371
/// @returns the previous setting.
372
bool ic_enable_hint(bool enable);
373
374
/// Set millisecond delay before a hint is displayed. Can be zero. (500ms by default).
375
long ic_set_hint_delay(long delay_ms);
376
377
/// Disable or enable syntax highlighting (enabled by default).
378
/// This applies regardless whether a syntax highlighter callback was set (`ic_set_highlighter`)
379
/// Returns the previous setting.
380
bool ic_enable_highlight(bool enable);
381
382
383
/// Set millisecond delay for reading escape sequences in order to distinguish
384
/// a lone ESC from the start of a escape sequence. The defaults are 100ms and 10ms,
385
/// but it may be increased if working with very slow terminals.
386
void ic_set_tty_esc_delay(long initial_delay_ms, long followup_delay_ms);
387
388
/// Enable highlighting of matching braces (and error highlight unmatched braces).`
389
bool ic_enable_brace_matching(bool enable);
390
391
/// Set matching brace pairs.
392
/// Pass \a NULL for the default `"()[]{}"`.
393
void ic_set_matching_braces(const char* brace_pairs);
394
395
/// Enable automatic brace insertion (enabled by default).
396
bool ic_enable_brace_insertion(bool enable);
397
398
/// Set matching brace pairs for automatic insertion.
399
/// Pass \a NULL for the default `()[]{}\"\"''`
400
void ic_set_insertion_braces(const char* brace_pairs);
401
402
/// \}
403
404
405
//--------------------------------------------------------------
406
// Advanced Completion
407
//--------------------------------------------------------------
408
409
/// \defgroup completex Advanced Completion
410
/// \{
411
412
/// Get the raw current input (and cursor position if `cursor` != NULL) for the completion.
413
/// Usually completer functions should look at their `prefix` though as transformers
414
/// like `ic_complete_word` may modify the prefix (for example, unescape it).
415
const char* ic_completion_input( ic_completion_env_t* cenv, long* cursor );
416
417
/// Get the completion argument passed to `ic_set_completer`.
418
void* ic_completion_arg( const ic_completion_env_t* cenv );
419
420
/// Do we have already some completions?
421
bool ic_has_completions( const ic_completion_env_t* cenv );
422
423
/// Do we already have enough completions and should we return if possible? (for improved latency)
424
bool ic_stop_completing( const ic_completion_env_t* cenv);
425
426
427
/// Primitive completion, cannot be used with most transformers (like `ic_complete_word` and `ic_complete_qword`).
428
/// When completed, `delete_before` _bytes_ are deleted before the cursor position,
429
/// `delete_after` _bytes_ are deleted after the cursor, and finally `completion` is inserted.
430
/// The `display` is used to display the completion in the completion menu, and `help` is displayed
431
/// with hinting. Both `display` and `help` can be NULL.
432
/// (all are copied by isocline and do not need to be preserved or allocated).
433
///
434
/// Returns `true` if the callback should continue trying to find more possible completions.
435
/// If `false` is returned, the callback should try to return and not add more completions (for improved latency).
436
bool ic_add_completion_prim( ic_completion_env_t* cenv, const char* completion,
437
const char* display, const char* help,
438
long delete_before, long delete_after);
439
440
/// \}
441
442
//--------------------------------------------------------------
443
/// \defgroup helper Character Classes.
444
/// Convenience functions for character classes, highlighting and completion.
445
/// \{
446
447
/// Convenience: return the position of a previous code point in a UTF-8 string `s` from postion `pos`.
448
/// Returns `-1` if `pos <= 0` or `pos > strlen(s)` (or other errors).
449
long ic_prev_char( const char* s, long pos );
450
451
/// Convenience: return the position of the next code point in a UTF-8 string `s` from postion `pos`.
452
/// Returns `-1` if `pos < 0` or `pos >= strlen(s)` (or other errors).
453
long ic_next_char( const char* s, long pos );
454
455
/// Convenience: does a string `s` starts with a given `prefix` ?
456
bool ic_starts_with( const char* s, const char* prefix );
457
458
/// Convenience: does a string `s` starts with a given `prefix` ignoring (ascii) case?
459
bool ic_istarts_with( const char* s, const char* prefix );
460
461
462
/// Convenience: character class for whitespace `[ \t\r\n]`.
463
bool ic_char_is_white(const char* s, long len);
464
465
/// Convenience: character class for non-whitespace `[^ \t\r\n]`.
466
bool ic_char_is_nonwhite(const char* s, long len);
467
468
/// Convenience: character class for separators.
469
/// (``[ \t\r\n,.;:/\\(){}\[\]]``.)
470
/// This is used for word boundaries in isocline.
471
bool ic_char_is_separator(const char* s, long len);
472
473
/// Convenience: character class for non-separators.
474
bool ic_char_is_nonseparator(const char* s, long len);
475
476
/// Convenience: character class for letters (`[A-Za-z]` and any unicode > 0x80).
477
bool ic_char_is_letter(const char* s, long len);
478
479
/// Convenience: character class for digits (`[0-9]`).
480
bool ic_char_is_digit(const char* s, long len);
481
482
/// Convenience: character class for hexadecimal digits (`[A-Fa-f0-9]`).
483
bool ic_char_is_hexdigit(const char* s, long len);
484
485
/// Convenience: character class for identifier letters (`[A-Za-z0-9_-]` and any unicode > 0x80).
486
bool ic_char_is_idletter(const char* s, long len);
487
488
/// Convenience: character class for filename letters (_not in_ " \t\r\n`@$><=;|&\{\}\(\)\[\]]").
489
bool ic_char_is_filename_letter(const char* s, long len);
490
491
492
/// Convenience: If this is a token start, return the length. Otherwise return 0.
493
long ic_is_token(const char* s, long pos, ic_is_char_class_fun_t* is_token_char);
494
495
/// Convenience: Does this match the specified token?
496
/// Ensures not to match prefixes or suffixes, and returns the length of the match (in bytes).
497
/// E.g. `ic_match_token("function",0,&ic_char_is_letter,"fun")` returns 0.
498
/// while `ic_match_token("fun x",0,&ic_char_is_letter,"fun"})` returns 3.
499
long ic_match_token(const char* s, long pos, ic_is_char_class_fun_t* is_token_char, const char* token);
500
501
502
/// Convenience: Do any of the specified tokens match?
503
/// Ensures not to match prefixes or suffixes, and returns the length of the match (in bytes).
504
/// E.g. `ic_match_any_token("function",0,&ic_char_is_letter,{"fun","func",NULL})` returns 0.
505
/// while `ic_match_any_token("func x",0,&ic_char_is_letter,{"fun","func",NULL})` returns 4.
506
long ic_match_any_token(const char* s, long pos, ic_is_char_class_fun_t* is_token_char, const char** tokens);
507
508
/// \}
509
510
//--------------------------------------------------------------
511
/// \defgroup term Terminal
512
///
513
/// Experimental: Low level terminal output.
514
/// Ensures basic ANSI SGR escape sequences are processed
515
/// in a portable way (e.g. on Windows)
516
/// \{
517
518
/// Initialize for terminal output.
519
/// Call this before using the terminal write functions (`ic_term_write`)
520
/// Does nothing on most platforms but on Windows it sets the console to UTF8 output and possible
521
/// enables virtual terminal processing.
522
void ic_term_init(void);
523
524
/// Call this when done with the terminal functions.
525
void ic_term_done(void);
526
527
/// Flush the terminal output.
528
/// (happens automatically on newline characters ('\n') as well).
529
void ic_term_flush(void);
530
531
/// Write a string to the console (and process CSI escape sequences).
532
void ic_term_write(const char* s);
533
534
/// Write a string to the console and end with a newline
535
/// (and process CSI escape sequences).
536
void ic_term_writeln(const char* s);
537
538
/// Write a formatted string to the console.
539
/// (and process CSI escape sequences)
540
void ic_term_writef(const char* fmt, ...);
541
542
/// Write a formatted string to the console.
543
void ic_term_vwritef(const char* fmt, va_list args);
544
545
/// Set text attributes from a style.
546
void ic_term_style( const char* style );
547
548
/// Set text attribute to bold.
549
void ic_term_bold(bool enable);
550
551
/// Set text attribute to underline.
552
void ic_term_underline(bool enable);
553
554
/// Set text attribute to italic.
555
void ic_term_italic(bool enable);
556
557
/// Set text attribute to reverse video.
558
void ic_term_reverse(bool enable);
559
560
/// Set text attribute to ansi color palette index between 0 and 255 (or 256 for the ANSI "default" color).
561
/// (auto matched to smaller palette if not supported)
562
void ic_term_color_ansi(bool foreground, int color);
563
564
/// Set text attribute to 24-bit RGB color (between `0x000000` and `0xFFFFFF`).
565
/// (auto matched to smaller palette if not supported)
566
void ic_term_color_rgb(bool foreground, uint32_t color );
567
568
/// Reset the text attributes.
569
void ic_term_reset( void );
570
571
/// Get the palette used by the terminal:
572
/// This is usually initialized from the COLORTERM environment variable. The
573
/// possible values of COLORTERM for each palette are given in parenthesis.
574
///
575
/// - 1: monochrome (`monochrome`)
576
/// - 3: old ANSI terminal with 8 colors, using bold for bright (`8color`/`3bit`)
577
/// - 4: regular ANSI terminal with 16 colors. (`16color`/`4bit`)
578
/// - 8: terminal with ANSI 256 color palette. (`256color`/`8bit`)
579
/// - 24: true-color terminal with full RGB colors. (`truecolor`/`24bit`/`direct`)
580
int ic_term_get_color_bits( void );
581
582
/// \}
583
584
//--------------------------------------------------------------
585
/// \defgroup async ASync
586
/// Async support
587
/// \{
588
589
/// Thread-safe way to asynchronously unblock a readline.
590
/// Behaves as if the user pressed the `ctrl-C` character
591
/// (resulting in returning NULL from `ic_readline`).
592
/// Returns `true` if the event was successfully delivered.
593
/// (This may not be supported on all platforms, but it is
594
/// functional on Linux, macOS and Windows).
595
bool ic_async_stop(void);
596
597
/// \}
598
599
//--------------------------------------------------------------
600
/// \defgroup alloc Custom Allocation
601
/// Register allocation functions for custom allocators
602
/// \{
603
604
typedef void* (ic_malloc_fun_t)( size_t size );
605
typedef void* (ic_realloc_fun_t)( void* p, size_t newsize );
606
typedef void (ic_free_fun_t)( void* p );
607
608
/// Initialize with custom allocation functions.
609
/// This must be called as the first function in a program!
610
void ic_init_custom_alloc( ic_malloc_fun_t* _malloc, ic_realloc_fun_t* _realloc, ic_free_fun_t* _free );
611
612
/// Free a potentially custom alloc'd pointer (in particular, the result returned from `ic_readline`)
613
void ic_free( void* p );
614
615
/// Allocate using the current memory allocator.
616
void* ic_malloc(size_t sz);
617
618
/// Duplicate a string using the current memory allocator.
619
const char* ic_strdup( const char* s );
620
621
/// \}
622
623
#ifdef __cplusplus
624
}
625
#endif
626
627
#endif /// IC_ISOCLINE_H
628
629