darkuranium / tclib Goto Github PK
View Code? Open in Web Editor NEWSet of single-file public domain libraries.
Set of single-file public domain libraries.
Right now, all history is discarded on exit. It should be read or written from/to a file or a custom stream.
This might require another dependency, tc_stream
(since I expect that to be needed for some other libraries as well).
Currently, only a single callback exists. Instead, multiple events should be recognized and passed to the user.
I have already decided to go with option nr. 3, but for the record, there were three options:
N callbacks registered separately
void tcedit_register_tabcomplete(int (*cb)(<...>), void* udata);
void tcedit_register_echo(<...>, void* udata);
N callbacks registered at once (via a struct)
typedef struct TC_EditHandler {
int (*tabcomplete)(<...>);
<...>
void* udata;
} TC_EditHandler;
void tcedit_register_handler(TC_EditHandler* handler);
A single callback which is passed an event type.
typedef struct TC_EditEvent {
int type;
TC_String* input;
<...>
} TC_EditEvent;
typedef int TC_EditCallback(TC_EditEvent* event, void* udata);
void tcedit_register_callback(TC_EditCallback* callback, void* udata);
Using the insert key should change between insert and overwrite modes.
Currently, the only check for terminal colors is to see if $TERM
equals xterm
. Proper checking should be done.
In non-Windows, the libraries currently silently assume the input is UTF-8. The information is (mostly) available, and it should be used to convert the locale-specific char
encoding to UTF-8.
See /tests/TEST-os-conv.c for a few conversion options.
Double underscores anywhere in an identifier are reserved in C++ (their use was temporary anyways). They should be replaced with some other syntax.
Windows and POSIX handle colors differently --- in POSIX, one can use \e[39m
(foreground) or \e[0m
(both) to reset the colors. For that purpose, TCTERM_FG_DEFAULT
and TCTERM_BG_DEFAULT
should be added, which resolve to some system-specific "default" color.
Perhaps TCTERM_{FG,BG}_STARTING
should also be added to specify the selected color at program start (which is distinct from the default color of the terminal).
The tcterm_get_cursor_pos()
function currently flushes all input in order to get the data in POSIX — that should be fixed.
The best way to do that is to take advantage of buffering (depends on #12 being implemented), then do a flush and fetch position. The CREAD
flag might perhaps be helpful here.
Custom allocators can be very useful, so support should be added.
The simplest method is via #define
s:
#define TC_MALLOC(size) my_malloc(size)
#define TC_MEMCPY(dst, src, size) my_memcpy(dst, src, size)
... however, a method that can pass some sort of user data should be devised (to avoid globals).
The tc_string
library has a tcstr_utf8_find_char(str, off)
function, which finds the Unicode code point index for a given offset.
The inverse function for that is missing and should be implemented.
The libraries are limited to getting (and storing in history) only a single line of input. This should be added.
Some sort of an API is needed to provide support for this.
$ echo '
foo
bar'
> foo
bar
# (( up arrow key ))
$ echo '
foo
bar'
The headers are currently almost completely undocumented. That should be remedied.
The libraries which can be tested effectively (which is most of them at the moment), should get some tests made — perhaps with continuous integration.
Currently, tcterm_getc()
is the only way of getting input and it is slow. For that purpose, buffering and/or some sort of a tcterm_read()
should be added.
Currently, the libraries are strictly C. They should be changed so that they can be compiled with a C++ compiler. This mostly involves adding extern "C"
and explicit void*
→T*
casts.
Furthermore, @q66 has asked me to make it compile with -Wold-style-cast
, which means adding something akin to:
#ifdef __cplusplus
#define TC_STATIC_CAST(T,val) static_cast<T>(val)
#else
#define TC_STATIC_CAST(T,val) ((T)(val))
#endif
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.