{"id":13577818,"url":"https://github.com/hoelzro/lua-linenoise","last_synced_at":"2025-07-31T01:12:36.479Z","repository":{"id":65612860,"uuid":"2616602","full_name":"hoelzro/lua-linenoise","owner":"hoelzro","description":"Lua bindings for linenoise with UTF-8 support (https://github.com/yhirose/linenoise/tree/utf8-support)","archived":false,"fork":false,"pushed_at":"2020-06-20T18:28:01.000Z","size":16442,"stargazers_count":48,"open_issues_count":2,"forks_count":13,"subscribers_count":5,"default_branch":"master","last_synced_at":"2025-02-25T07:45:22.074Z","etag":null,"topics":["linenoise","lua","lua-bindings"],"latest_commit_sha":null,"homepage":"","language":"C","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/hoelzro.png","metadata":{"files":{"readme":"README.md","changelog":"Changes","contributing":null,"funding":null,"license":"COPYING","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2011-10-20T22:03:12.000Z","updated_at":"2025-02-15T06:14:56.000Z","dependencies_parsed_at":"2023-01-31T19:15:58.094Z","dependency_job_id":null,"html_url":"https://github.com/hoelzro/lua-linenoise","commit_stats":null,"previous_names":[],"tags_count":11,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/hoelzro%2Flua-linenoise","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/hoelzro%2Flua-linenoise/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/hoelzro%2Flua-linenoise/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/hoelzro%2Flua-linenoise/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/hoelzro","download_url":"https://codeload.github.com/hoelzro/lua-linenoise/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":242650897,"owners_count":20163610,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["linenoise","lua","lua-bindings"],"created_at":"2024-08-01T15:01:24.603Z","updated_at":"2025-03-09T05:30:47.262Z","avatar_url":"https://github.com/hoelzro.png","language":"C","funding_links":[],"categories":["C"],"sub_categories":[],"readme":"# lua-linenoise - Lua binding for the linenoise command line library\n\nLinenoise (https://github.com/antirez/linenoise) is a delightfully simple command\nline library.  This Lua module is simply a binding for it.\n\nThe main Linenoise upstream has stagnated a bit, so this binding tracks https://github.com/yhirose/linenoise/tree/utf8-support, which\nincludes things like UTF-8 support and ANSI terminal escape sequence detection.\n\nThis repository also contains a Windows-compatible version of linenoise taken from MSOpenTech's [Windows port](https://github.com/MSOpenTech/redis) of redis.\n\n# Compilation\n\nIf you use LuaRocks, you can run `luarocks make` on the latest rockspec.\n\nYou can also build with make. When building this module using make, you may use the original linenoise source included in\nthe repository, or you may set the Makefile variable `LIBLINENOISE` to override\nit:\n\n```sh\nmake LIBLINENOISE=-llinenoise\n# OR:\nmake LIBLINENOISE=/path/to/liblinenoise.a\n```\n\nYou may need to change the value of the LN_EXPORT macro in lua-linenoise.c to the appropriate keyword to ensure the luaopen_linenoise function is exported properly (I don't know much about C or Unix-like systems, so I may have gotten it wrong).\n\nIf you have Visual Studio 2012 (even the free Express version), you can compile this module with the Windows-compatible linenoise source using the included solution file (you'll need to edit the include paths and import library dependencies to match your configuration).\n\nIf you prefer to compile using other tools, just link lua-linenoise.c with line-noise-windows/linenoise.c and line-noise-windows/win32fixes.c to create the Windows-compatible DLL.\n\n# Usage\n\nThis library is a fairly thin wrapper over linenoise itself, so the function calls\nare named similarly.  I may develop a \"porcelain\" layer in the future.\n\n## L.linenoise(prompt)\n\nPrompts for a line of input, using *prompt* as the prompt string.  Returns nil if\nno more input is available; Returns nil and an error string if an error occurred.\n\n## L.historyadd(line)\n\nAdds *line* to the history list.\n\n## L.historysetmaxlen(length)\n\nSets the history list size to *length*.\n\n## L.historysave(filename)\n\nSaves the history list to *filename*.\n\n## L.historyload(filename)\n\nLoads the history list from *filename*.\n\n## L.clearscreen()\n\nClears the screen.\n\n## L.setcompletion(callback)\n\nSets the completion callback.  This callback is called with two arguments:\n\n  * A completions object.  Use object:add or L.addcompletion to add a completion to this object.\n  * The current line of input.\n\n## L.addcompletion(completions, string)\n\nAdds *string* to the list of completions.\n\nAll functions return nil on error; functions that don't have an obvious return value\nreturn true on success.\n\n## L.setmultiline(multiline)\n\nEnables multi-line mode if *multiline* is true, disables otherwise.\n\n## L.sethints(callback)\n\nSets a hints callback to provide hint information on the right hand side of the\nprompt.  *calback* should be a function that takes a single parameter (a\nstring, the line entered so far) and returns zero, one, or two values.  Zero\nvalues means no hint.  The first value may be *nil* for no hint, or a string\nvalue for a hint.  If the first value is a string, the second value may be a table\nwith the *color* and *bold* keys - *color* is an ANSI terminal color code (such as\nthose provided by the [lua-term](https://luarocks.org/modules/hoelzro/lua-term) colors\nmodule), whereas *bold* is a boolean indicating whether or not the hint should be printed\nas bold.\n\n## L.printkeycodes()\n\nPrints linenoise key codes.  Primarly used for debugging.\n\n## L.enableutf8()\n\nEnables UTF-8 handling.\n\n# Example\n\n```lua\nlocal L = require 'linenoise'\nlocal colors = require('term').colors -- optional\n-- L.clearscreen()\nprint '----- Testing lua-linenoise! ------'\nlocal prompt, history = '? ', 'history.txt'\nL.historyload(history) -- load existing history\nL.setcompletion(function(completion,str)\n   if str == 'h' then\n    completion:add('help')\n    completion:add('halt')\n  end\nend)\nL.sethints(function(str)\n  if str == 'h' then\n    return ' bold hints in red', { color = colors.red, bold = true }\n  end\nend)\n\nL.enableutf8()\n\nlocal line, err = L.linenoise(prompt)\nwhile line do\n    if #line \u003e 0 then\n        print(line:upper())\n        L.historyadd(line)\n        L.historysave(history) -- save every new line\n    end\n    line, err = L.linenoise(prompt)\nend\nif err then\n  print('An error occurred: ' .. err)\nend\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fhoelzro%2Flua-linenoise","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fhoelzro%2Flua-linenoise","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fhoelzro%2Flua-linenoise/lists"}