{"id":51043750,"url":"https://github.com/floatpane/go-keybind","last_synced_at":"2026-06-22T12:02:25.321Z","repository":{"id":362778073,"uuid":"1256214367","full_name":"floatpane/go-keybind","owner":"floatpane","description":"Zero-dependency keybind Go library","archived":false,"fork":false,"pushed_at":"2026-06-18T16:53:30.000Z","size":86,"stargazers_count":0,"open_issues_count":10,"forks_count":0,"subscribers_count":0,"default_branch":"master","last_synced_at":"2026-06-18T18:27:22.607Z","etag":null,"topics":["cli","configuration","console","go","golang","golang-library","hotkey","hotkeys","input","input-handling","keybind","keybinding","keybindings","keyboard","keyboard-events","keyboard-shortcuts","shortcuts","terminal","tui","user-input"],"latest_commit_sha":null,"homepage":"https://keybind.floatpane.com","language":"Go","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/floatpane.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":"CONTRIBUTING.md","funding":".github/FUNDING.yml","license":"LICENSE","code_of_conduct":"CODE_OF_CONDUCT.md","threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":"SECURITY.md","support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null,"notice":null,"maintainers":null,"copyright":null,"agents":null,"dco":null,"cla":null},"funding":{"github":"floatpane"}},"created_at":"2026-06-01T15:08:55.000Z","updated_at":"2026-06-01T17:56:11.000Z","dependencies_parsed_at":null,"dependency_job_id":null,"html_url":"https://github.com/floatpane/go-keybind","commit_stats":null,"previous_names":["floatpane/go-keybind"],"tags_count":1,"template":false,"template_full_name":null,"purl":"pkg:github/floatpane/go-keybind","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/floatpane%2Fgo-keybind","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/floatpane%2Fgo-keybind/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/floatpane%2Fgo-keybind/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/floatpane%2Fgo-keybind/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/floatpane","download_url":"https://codeload.github.com/floatpane/go-keybind/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/floatpane%2Fgo-keybind/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":34647750,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-05-26T15:22:16.424Z","status":"online","status_checked_at":"2026-06-22T02:00:06.391Z","response_time":106,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"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":["cli","configuration","console","go","golang","golang-library","hotkey","hotkeys","input","input-handling","keybind","keybinding","keybindings","keyboard","keyboard-events","keyboard-shortcuts","shortcuts","terminal","tui","user-input"],"created_at":"2026-06-22T12:02:24.333Z","updated_at":"2026-06-22T12:02:25.313Z","avatar_url":"https://github.com/floatpane.png","language":"Go","funding_links":["https://github.com/sponsors/floatpane"],"categories":[],"sub_categories":[],"readme":"\u003cdiv align=\"center\"\u003e\n\n# go-keybind\n\n**Key-binding config for Go TUI apps. Parse and normalize key strings, load/save JSON keybind files with merge-with-defaults semantics, validate for intra-area conflicts.**\n\n[![Go Version](https://img.shields.io/github/go-mod/go-version/floatpane/go-keybind)](https://golang.org)\n[![Go Reference](https://pkg.go.dev/badge/github.com/floatpane/go-keybind.svg)](https://pkg.go.dev/github.com/floatpane/go-keybind)\n[![GitHub release (latest by date)](https://img.shields.io/github/v/release/floatpane/go-keybind)](https://github.com/floatpane/go-keybind/releases)\n[![CI](https://github.com/floatpane/go-keybind/actions/workflows/ci.yml/badge.svg)](https://github.com/floatpane/go-keybind/actions/workflows/ci.yml)\n[![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](LICENSE)\n\n\u003c/div\u003e\n\n`go-keybind` provides two focused utilities for Go TUI applications:\n\n1. **A `Key` type** — parse and normalize keyboard shortcut strings. Catches\n   typos (`\"crtl+c\"`), canonicalizes aliases (`\"escape\"` → `\"esc\"`, `\"return\"` →\n   `\"enter\"`, `\"meta\"` → `\"alt\"`), fixes modifier order, and produces a comparable\n   value you can switch on.\n\n2. **A generic JSON config loader** — `Load[T]`, `Save[T]`, and `Validate` work\n   with any app-defined struct. Fields the user didn't touch keep their compiled-in\n   defaults, the file is written on first run, and `Validate` catches intra-area\n   conflicts without false-positives for intentional cross-area duplicates.\n\nExtracted from [matcha](https://github.com/floatpane/matcha)'s config package.\nZero external dependencies.\n\n## Install\n\n```bash\ngo get github.com/floatpane/go-keybind\n```\n\nRequires Go 1.26+.\n\n## Usage\n\n### Parse and compare key strings\n\n```go\nk, err := keybind.Parse(\"ctrl+shift+a\")\n// k.Ctrl = true, k.Shift = true, k.Base = \"a\"\n// k.String() = \"ctrl+shift+a\"\n\n// Aliases normalize to the same Key:\na, _ := keybind.Parse(\"escape\")\nb, _ := keybind.Parse(\"esc\")\nfmt.Println(a == b) // true\n\n// Modifier order doesn't matter in input:\nc, _ := keybind.Parse(\"shift+ctrl+a\")\nd, _ := keybind.Parse(\"ctrl+shift+a\")\nfmt.Println(c == d) // true\n```\n\n### Load a keybind config from disk\n\n```go\ntype MyKeys struct {\n    Quit   string `json:\"quit\"`\n    Reload string `json:\"reload\"`\n    NavUp  string `json:\"nav_up\"`\n}\n\ncfg, err := keybind.Load(cfgDir, \"keybinds.json\", MyKeys{\n    Quit:   \"ctrl+c\",\n    Reload: \"r\",\n    NavUp:  \"k\",\n})\n// If keybinds.json didn't exist it was created with the defaults.\n// Fields absent from an existing file keep their default values.\n```\n\n### Validate for conflicts\n\n```go\nconflicts := keybind.Validate(map[string]map[string]string{\n    \"global\": {\"quit\": cfg.Quit, \"reload\": cfg.Reload},\n    \"nav\":    {\"up\": cfg.NavUp, \"down\": cfg.NavDown},\n})\n// Cross-area duplicates (\"d\" for delete in two different views) are fine.\n// Only intra-area conflicts (two actions bound to the same key) are reported.\n```\n\n### Use in a TUI event loop\n\n```go\nquitKey := keybind.MustParse(cfg.Quit) // panics on bad config value\n\n// In your event handler:\nif event.String() == quitKey.String() {\n    return tea.Quit\n}\n```\n\n## Supported keys\n\n**Modifiers:** `ctrl`, `alt` (= `meta` = `opt`), `shift`\n\n**Special keys:**\n\n| Canonical | Aliases |\n|-----------|---------|\n| `enter` | `return` |\n| `esc` | `escape` |\n| `tab` | — |\n| `backspace` | `bs` |\n| `space` | — |\n| `up`, `down`, `left`, `right` | — |\n| `delete` | `del` |\n| `insert` | — |\n| `home`, `end` | — |\n| `pgup` | `pageup` |\n| `pgdown` | `pagedown`, `pgdn` |\n| `f1` … `f12` | — |\n\nAny single printable character is also accepted (`a`, `A`, `1`, `/`, `[`…).\n\n## Documentation\n\nFull API reference: [pkg.go.dev/github.com/floatpane/go-keybind](https://pkg.go.dev/github.com/floatpane/go-keybind)\n\nGuides: see [`docs/`](docs/).\n\n## Sister projects\n\n| Project | Role |\n|---------|------|\n| [floatpane/matcha](https://github.com/floatpane/matcha) | Reference consumer — inbox, email, composer, folder keybinds. |\n\n## Contributing\n\nPRs welcome. See [CONTRIBUTING.md](CONTRIBUTING.md).\n\n## Security\n\nReport vulnerabilities privately via [SECURITY.md](SECURITY.md).\n\n## License\n\nMIT. See [LICENSE](LICENSE).\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ffloatpane%2Fgo-keybind","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Ffloatpane%2Fgo-keybind","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ffloatpane%2Fgo-keybind/lists"}