{"id":15047937,"url":"https://github.com/evgenykislov/ctrl-c","last_synced_at":"2025-07-07T14:08:41.243Z","repository":{"id":46625351,"uuid":"252243486","full_name":"evgenykislov/ctrl-c","owner":"evgenykislov","description":"Crossplatform code to handle Ctrl+C signal","archived":false,"fork":false,"pushed_at":"2025-01-26T10:28:27.000Z","size":18,"stargazers_count":25,"open_issues_count":1,"forks_count":4,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-04-10T01:10:34.844Z","etag":null,"topics":["cplusplus","cplusplus-11","cpp","cpp11","crossplatform","ctrl-c","ctrlc","linux","macos","macosx","windows"],"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/evgenykislov.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","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":"2020-04-01T17:32:59.000Z","updated_at":"2025-02-07T18:59:09.000Z","dependencies_parsed_at":"2025-01-26T11:32:36.436Z","dependency_job_id":null,"html_url":"https://github.com/evgenykislov/ctrl-c","commit_stats":null,"previous_names":[],"tags_count":1,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/evgenykislov%2Fctrl-c","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/evgenykislov%2Fctrl-c/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/evgenykislov%2Fctrl-c/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/evgenykislov%2Fctrl-c/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/evgenykislov","download_url":"https://codeload.github.com/evgenykislov/ctrl-c/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248137886,"owners_count":21053775,"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":["cplusplus","cplusplus-11","cpp","cpp11","crossplatform","ctrl-c","ctrlc","linux","macos","macosx","windows"],"created_at":"2024-09-24T21:06:09.602Z","updated_at":"2025-04-10T01:10:41.483Z","avatar_url":"https://github.com/evgenykislov.png","language":"C++","readme":"# Ctrl+C\n\nCrossplatform source code (C++11) to handle Ctrl+C event in custom functions.\nSupports Windows, Linux and Mac OS X.\n\n## Getting Started\n\nTo catch Ctrl+C event/signal you should call:\n```cpp\nunsigned int CtrlCLibrary::SetCtrlCHandler(std::function\u003cbool(enum CtrlCLibrary::CtrlSignal)\u003e handler);\n```\nhandler - custom handler;\n\n**Return**:\nReturns handler identifier, or CtrlCLibrary::kErrorID in case of error.\n\nTo remove handler you should call:\n```cpp\nvoid CtrlCLibrary::ResetCtrlCHandler(unsigned int id);\n```\nid - handler identifier, returned by CtrlCLibrary::SetCtrlCHandler.\n\n### Installing\n\nYou should copy source files (src/ctrl-c.h, src/ctrl-c.cpp) to your project.\n\n## Example of usage\n\nSource file test/main.cpp contains example of usage Ctrl+C code.\nYou can compile the example by your favourite C++ compiler.\n\n## Authors\n\n**Evgeny Kislov** - [evgenykislov.com](https://evgenykislov.com), [github/evgenykislov](https://github.com/evgenykislov)\n\n## License\n\nThis project is licensed under the MIT License - see the [LICENSE](LICENSE) file for details\n\n## Notes\n\nYou can add a few handlers for Ctrl+C processing. All handlers will be called in LIFO order: first added handler will be called at last.\nEach handler should return bool value:  \n* *true* - to stop processing by other handlers;\n* *false* - to continue processing by other handlers (also, see notes for Windows below).\n\nThe functions to set, reset and handle event are thread-safe.  *Warning*: You shouldn't remove handler from handler code. It will cause deadlock.\n\n#### Errors\nAdding a new handler can return error id (kErrorID) in case of system error or lack of memory.\n\n#### Exceptions\nThe code processes its errors (and any bad_alloc into SetCtrlCHandler call). In this case it will return error identifier (kErrorID).\nOther exceptions aren't processed - you should catch them by your code.\n\n#### Linux and Mac OS X notes\nSetting any handler will cause a previous handler will not work. If first setting causes error, previous handler will not work too - OS will use DEFAULT handler.\nRemoving of all handlers causes set DEFAULT handler for Ctrl+C.\n\n#### Windows notes\nIf all handlers return **false**, a previous handler will be called. It can be default OS handler and your process will be closed.\n","funding_links":[],"categories":["CLI","Recently Updated"],"sub_categories":["[Oct 28, 2024](/content/2024/10/28/README.md)"],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fevgenykislov%2Fctrl-c","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fevgenykislov%2Fctrl-c","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fevgenykislov%2Fctrl-c/lists"}