commit 4dc9e55bbccb27fc04e477a3b2785fe5424503f4 Author: Alexander Zhirov Date: Tue Sep 23 22:00:14 2025 +0300 init diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..a65b417 --- /dev/null +++ b/.gitignore @@ -0,0 +1 @@ +lib diff --git a/.vscode/settings.json b/.vscode/settings.json new file mode 100644 index 0000000..d1c022f --- /dev/null +++ b/.vscode/settings.json @@ -0,0 +1,5 @@ +{ + "editor.insertSpaces": false, + "editor.tabSize": 4, + "editor.detectIndentation": false +} \ No newline at end of file diff --git a/LICENSE b/LICENSE new file mode 100644 index 0000000..36b7cd9 --- /dev/null +++ b/LICENSE @@ -0,0 +1,23 @@ +Boost Software License - Version 1.0 - August 17th, 2003 + +Permission is hereby granted, free of charge, to any person or organization +obtaining a copy of the software and accompanying documentation covered by +this license (the "Software") to use, reproduce, display, distribute, +execute, and transmit the Software, and to prepare derivative works of the +Software, and to permit third-parties to whom the Software is furnished to +do so, all subject to the following: + +The copyright notices in the Software and this entire statement, including +the above license grant, this restriction and the following disclaimer, +must be included in all copies of the Software, in whole or in part, and +all derivative works of the Software, unless such copies or derivative +works are solely in the form of machine-executable object code generated by +a source language processor. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT +SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE +FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE, +ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER +DEALINGS IN THE SOFTWARE. diff --git a/README.md b/README.md new file mode 100644 index 0000000..b1de7a4 --- /dev/null +++ b/README.md @@ -0,0 +1,3 @@ +# linenoise + +Минимальная, самодостаточная замена readline, используемая в проектах вроде Redis, MongoDB и Android. diff --git a/dub.json b/dub.json new file mode 100644 index 0000000..061c970 --- /dev/null +++ b/dub.json @@ -0,0 +1,11 @@ +{ + "authors": [ + "Alexander Zhirov" + ], + "copyright": "Copyright © 2025, Alexander Zhirov", + "description": "A small self-contained alternative to readline and libedit.", + "license": "BSL-1.0", + "name": "linenoise", + "targetType": "library", + "targetPath": "lib" +} diff --git a/dub.selections.json b/dub.selections.json new file mode 100644 index 0000000..322586b --- /dev/null +++ b/dub.selections.json @@ -0,0 +1,5 @@ +{ + "fileVersion": 1, + "versions": { + } +} diff --git a/dub.settings.json b/dub.settings.json new file mode 100644 index 0000000..9da886c --- /dev/null +++ b/dub.settings.json @@ -0,0 +1,4 @@ +{ + "defaultArchitecture": "x86_64", + "defaultCompiler": "ldc2" +} diff --git a/source/linenoise.d b/source/linenoise.d new file mode 100644 index 0000000..e43bc51 --- /dev/null +++ b/source/linenoise.d @@ -0,0 +1,66 @@ +module linenoise; + +extern (C) { + +struct LinenoiseState { + int in_completion; /* Пользователь нажал TAB, и теперь мы в режиме автодополнения, + * так что ввод обрабатывается completeLine(). */ + size_t completion_idx; /* Индекс следующего предлагаемого дополнения. */ + int ifd; /* Дескриптор файла stdin терминала. */ + int ofd; /* Дескриптор файла stdout терминала. */ + char* buf; /* Буфер редактируемой строки. */ + size_t buflen; /* Размер буфера редактируемой строки. */ + const(char)* prompt; /* Приглашение для отображения. */ + size_t plen; /* Длина приглашения. */ + size_t pos; /* Текущая позиция курсора. */ + size_t oldpos; /* Предыдущая позиция курсора при обновлении. */ + size_t len; /* Текущая длина редактируемой строки. */ + size_t cols; /* Количество столбцов в терминале. */ + size_t oldrows; /* Строки, использованные последней обновлённой строкой (многострочный режим) */ + int history_index; /* Индекс истории, который мы сейчас редактируем. */ +} + +struct LinenoiseCompletions { + size_t len; + char** cvec; +} + +alias linenoiseCompletionCallback = void function(const(char)*, LinenoiseCompletions*); +alias linenoiseHintsCallback = char* function(const(char)*, int* color, int* bold); +alias linenoiseFreeHintsCallback = void function(void*); + +@nogc nothrow: + +/* Non blocking API. */ +int linenoiseEditStart(LinenoiseState* l, int stdin_fd, int stdout_fd, char* buf, size_t buflen, const(char)* prompt); +char* linenoiseEditFeed(LinenoiseState* l); +void linenoiseEditStop(LinenoiseState* l); +void linenoiseHide(LinenoiseState* l); +void linenoiseShow(LinenoiseState* l); + +/* Blocking API. */ +char* linenoise(const(char)* prompt); +void linenoiseFree(void* ptr); + +/* Completion API. */ +void linenoiseSetCompletionCallback(linenoiseCompletionCallback); +void linenoiseSetHintsCallback(linenoiseHintsCallback); +void linenoiseSetFreeHintsCallback(linenoiseFreeHintsCallback); +void linenoiseAddCompletion(LinenoiseCompletions*, const(char)*); + +/* History API. */ +int linenoiseHistoryAdd(const(char)* line); +int linenoiseHistorySetMaxLen(int len); +int linenoiseHistorySave(const(char)* filename); +int linenoiseHistoryLoad(const(char)* filename); + +/* Other utilities. */ +void linenoiseClearScreen(); +void linenoiseSetMultiLine(int ml); +void linenoisePrintKeyCodes(); +void linenoiseMaskModeEnable(); +void linenoiseMaskModeDisable(); + +extern __gshared char* linenoiseEditMore; + +}