{"id":19635931,"url":"https://github.com/git-bruh/termbox-widgets","last_synced_at":"2025-04-28T14:14:18.682Z","repository":{"id":123991371,"uuid":"431798102","full_name":"git-bruh/termbox-widgets","owner":"git-bruh","description":"(UNOFFICIAL) Reusable widgets for termbox2 (https://github.com/termbox/termbox2)","archived":false,"fork":false,"pushed_at":"2022-05-17T08:56:49.000Z","size":130,"stargazers_count":4,"open_issues_count":0,"forks_count":1,"subscribers_count":2,"default_branch":"main","last_synced_at":"2025-04-28T14:14:12.816Z","etag":null,"topics":["c","curses","ncurses","termbox","tui","widgets"],"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/git-bruh.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"COPYING","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2021-11-25T10:09:27.000Z","updated_at":"2024-12-31T15:32:41.000Z","dependencies_parsed_at":null,"dependency_job_id":"cf127ff2-db8e-486c-be7b-1c4c5171800b","html_url":"https://github.com/git-bruh/termbox-widgets","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/git-bruh%2Ftermbox-widgets","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/git-bruh%2Ftermbox-widgets/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/git-bruh%2Ftermbox-widgets/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/git-bruh%2Ftermbox-widgets/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/git-bruh","download_url":"https://codeload.github.com/git-bruh/termbox-widgets/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":251326851,"owners_count":21571636,"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":["c","curses","ncurses","termbox","tui","widgets"],"created_at":"2024-11-11T12:27:37.247Z","updated_at":"2025-04-28T14:14:18.649Z","avatar_url":"https://github.com/git-bruh.png","language":"C","funding_links":[],"categories":[],"sub_categories":[],"readme":"# termbox-widgets\n\nSimple reusable widgets for [termbox2](https://github.com/termbox/termbox2).\n\n# Usage\n\nLike termbox2, no build system is provided and the library is provided as a single header. Additionally, this library requires the `stb_ds.h` header file from [stb](https://github.com/nothings/stb) so that must be provided by your project, along with termbox.\n\nIn a single `.c` file, do the following to build the implementation:\n\n```\n#define WIDGETS_IMPL\n#include \"widgets.h\"\n```\n\n`stb_ds.h` needs to be built in a similar manner in a _SEPARATE_ `.c` file with `#define STB_DS_IMPLEMENTATION`.\n\nFor running tests, run `cc -x c widgets.h -lm -DWIDGETS_TESTS -o test \u0026\u0026 ./test`.\n\nThe API is defined in `widgets.h`. Each widget takes a `widget_points` structure containing the coordinates of the rectangle in which it can draw. This makes the library entirely agnostic to user-defined widgets as you only need to ensure that widgets don't overlap and are not forced into defining them in a specific manner like full-fledged UI toolkits do. However, some utility functions like `widget_print_str` and `widget_pad_center` are provided to optionally assist in writing user-defined widgets.\n\nThe widgets defined here depend on the user providing them events instead of using callbacks, which makes the widgets agnostic to key bindings etc. aswell.\n\nHere is an example of a basic input field:\n\n```c\n#define TB_IMPL\n#define WIDGETS_IMPL\n#define STB_DS_IMPLEMENTATION\n#define _GNU_SOURCE\n#include \"widgets.h\"\n#include \u003clocale.h\u003e\n\nint\nmain(void) {\n\tif ((tb_init()) != TB_OK) {\n\t\treturn EXIT_FAILURE;\n\t}\n\ttb_set_input_mode(TB_INPUT_ALT);\n\tsetlocale(LC_ALL, \"\"); /* Fix unicode handling */\n\n\tstruct tb_event event;\n\tstruct input input;\n\n\tif ((input_init(\u0026input, TB_DEFAULT, false)) != 0) {\n\t\treturn EXIT_FAILURE;\n\t}\n\n\tfor (;;) {\n\t\tint tb_ret = tb_poll_event(\u0026event);\n\n\t\t/* poll() can error out if SIGWINCH was received. */\n\t\tif (tb_ret != TB_OK \u0026\u0026 tb_ret != TB_ERR_POLL) {\n\t\t\tbreak;\n\t\t}\n\n\t\t/* Stop on Ctrl + C */\n\t\tif (event.key == TB_KEY_CTRL_C) {\n\t\t\tbreak;\n\t\t}\n\n\t\tenum widget_error ret = WIDGET_NOOP;\n\n\t\tif (!event.key \u0026\u0026 event.ch) {\n\t\t\tret = input_handle_event(\u0026input, INPUT_ADD, event.ch);\n\t\t} else if (event.type == TB_EVENT_KEY) {\n\t\t\t/* Shift + key should jump across a word. */\n\t\t\tbool mod = (event.mod \u0026 TB_MOD_SHIFT);\n\n\t\t\tswitch (event.key) {\n\t\t\tcase TB_KEY_ENTER:\n\t\t\t\tret = input_handle_event(\u0026input, INPUT_ADD, '\\n');\n\t\t\t\tbreak;\n\t\t\tcase TB_KEY_BACKSPACE:\n\t\t\tcase TB_KEY_BACKSPACE2:\n\t\t\t\tret = input_handle_event(\n\t\t\t\t  \u0026input, mod ? INPUT_DELETE_WORD : INPUT_DELETE);\n\t\t\t\tbreak;\n\t\t\tcase TB_KEY_ARROW_RIGHT:\n\t\t\t\tret = input_handle_event(\n\t\t\t\t  \u0026input, mod ? INPUT_RIGHT_WORD : INPUT_RIGHT);\n\t\t\t\tbreak;\n\t\t\tcase TB_KEY_ARROW_LEFT:\n\t\t\t\tret = input_handle_event(\n\t\t\t\t  \u0026input, mod ? INPUT_LEFT_WORD : INPUT_LEFT);\n\t\t\t\tbreak;\n\t\t\t}\n\t\t}\n\n\t\t/* No operation was valid. */\n\t\tif (ret != WIDGET_REDRAW \u0026\u0026 event.type != TB_EVENT_RESIZE) {\n\t\t\tcontinue;\n\t\t}\n\n\t\tint rows = 0; /* Rows taken by current input field after redrawing. */\n\t\tstruct widget_points points = {0};\n\t\tint height = tb_height();\n\t\tconst int input_max_height = 5;\n\n\t\t/* x1, x2, y1, y2 */\n\t\twidget_points_set(\n\t\t  \u0026points, 0, tb_width(), height - input_max_height, height);\n\n\t\ttb_clear();\n\t\tinput_redraw(\u0026input, \u0026points, \u0026rows);\n\t\t/* Possibly more widget redraws here\n\t\t * ... */\n\t\ttb_present();\n\t}\n\n\tinput_finish(\u0026input);\n\ttb_shutdown();\n}\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fgit-bruh%2Ftermbox-widgets","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fgit-bruh%2Ftermbox-widgets","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fgit-bruh%2Ftermbox-widgets/lists"}