{"id":29878649,"url":"https://github.com/trippwill/polymer","last_synced_at":"2025-07-31T07:33:49.708Z","repository":{"id":306849381,"uuid":"1027405986","full_name":"trippwill/polymer","owner":"trippwill","description":"An application layer for charmbracelet/bubbletea","archived":false,"fork":false,"pushed_at":"2025-07-28T01:11:57.000Z","size":17,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":0,"default_branch":"main","last_synced_at":"2025-07-28T02:34:16.837Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"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/trippwill.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,"zenodo":null}},"created_at":"2025-07-28T00:37:07.000Z","updated_at":"2025-07-28T01:11:49.000Z","dependencies_parsed_at":"2025-07-28T02:44:25.265Z","dependency_job_id":null,"html_url":"https://github.com/trippwill/polymer","commit_stats":null,"previous_names":["trippwill/polymer"],"tags_count":null,"template":false,"template_full_name":null,"purl":"pkg:github/trippwill/polymer","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/trippwill%2Fpolymer","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/trippwill%2Fpolymer/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/trippwill%2Fpolymer/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/trippwill%2Fpolymer/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/trippwill","download_url":"https://codeload.github.com/trippwill/polymer/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/trippwill%2Fpolymer/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":268004327,"owners_count":24179399,"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","status":"online","status_checked_at":"2025-07-31T02:00:08.723Z","response_time":66,"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":[],"created_at":"2025-07-31T07:33:44.200Z","updated_at":"2025-07-31T07:33:49.680Z","avatar_url":"https://github.com/trippwill.png","language":"Go","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Polymer\n\nA composable Terminal User Interface (TUI) framework for Go, built on top of [Bubble Tea](https://github.com/charmbracelet/bubbletea). Polymer provides a simpler, more structured approach to building complex TUI applications with stack-based navigation, lifecycle hooks, and reusable components.\n\n## Features\n\n- **Simple Interface**: Minimal `Atom` interface with just `Name()`, `Update()`, and `View()` methods\n- **Stack-based Navigation**: Push, pop, replace, and reset operations for intuitive UI flow\n- **Lifecycle Hooks**: Debug and observe your application with `Lens` components\n- **Composable Components**: Reusable UI elements like menus and forms\n- **Bubble Tea Integration**: Seamless compatibility with existing Bubble Tea components\n- **Type Safety**: Full Go type safety with generics support\n\n## Installation\n\n```bash\ngo get github.com/trippwill/polymer\n```\n\n## Quick Start\n\nHere's a simple \"Hello World\" application:\n\n```go\npackage main\n\nimport (\n    \"fmt\"\n    \"os\"\n    \n    tea \"github.com/charmbracelet/bubbletea\"\n    poly \"github.com/trippwill/polymer\"\n)\n\n// HelloAtom is a simple screen that displays a greeting\ntype HelloAtom struct{}\n\nfunc (h HelloAtom) Name() string { return \"Hello\" }\n\nfunc (h HelloAtom) Update(msg tea.Msg) (poly.Atom, tea.Cmd) {\n    // Quit on any key press\n    if _, ok := msg.(tea.KeyMsg); ok {\n        return h, tea.Quit\n    }\n    return h, nil\n}\n\nfunc (h HelloAtom) View() string {\n    return \"Hello, Polymer! (press any key to exit)\\n\"\n}\n\nfunc main() {\n    // Create a host with your root atom\n    host := poly.NewHost(HelloAtom{}, \"Hello App\")\n    \n    // Start the Bubble Tea program\n    program := tea.NewProgram(host)\n    if _, err := program.Run(); err != nil {\n        fmt.Printf(\"Error: %v\\n\", err)\n        os.Exit(1)\n    }\n}\n```\n\n## Core Concepts\n\n### Atom\n\nAn `Atom` is the fundamental building block of a Polymer application. It's similar to a Bubble Tea `Model` but with a simplified interface:\n\n```go\ntype Atom interface {\n    Name() string                           // Identifier for the atom\n    Update(tea.Msg) (Atom, tea.Cmd)        // Handle messages and return new state\n    View() string                           // Render the current state\n}\n```\n\nAtoms can optionally implement the `Initializer` interface to provide setup logic:\n\n```go\ntype Initializer interface {\n    Atom\n    Init() tea.Cmd\n}\n```\n\n### Chain\n\nA `Chain` manages a stack of Atoms, enabling complex navigation patterns:\n\n```go\n// Create a navigation chain starting with a menu\nnav := poly.NewChain(mainMenu)\n\n// Navigation commands\npoly.Push(newAtom)     // Add atom to top of stack\npoly.Pop()             // Remove top atom\npoly.Replace(newAtom)  // Replace top atom\npoly.Reset(newAtom)    // Clear stack and set new root\n```\n\n### Lens\n\nA `Lens` provides lifecycle hooks for debugging and observability:\n\n```go\n// Create a lens with logging hooks\nlens := poly.WithLens(myAtom,\n    poly.WithOnInit(func(atom poly.Atom, cmd tea.Cmd) {\n        log.Printf(\"Atom %s initialized\", atom.Name())\n    }),\n    poly.WithBeforeUpdate(func(atom poly.Atom, msg tea.Msg) {\n        log.Printf(\"Atom %s received message %T\", atom.Name(), msg)\n    }),\n    poly.WithAfterUpdate(func(atom poly.Atom, cmd tea.Cmd) {\n        log.Printf(\"Atom %s updated with command %T\", atom.Name(), cmd)\n    }),\n    poly.WithOnView(func(atom poly.Atom, view string) {\n        log.Printf(\"Atom %s rendered\", atom.Name())\n    }),\n)\n```\n\n### Host\n\nA `Host` bridges Polymer Atoms to Bubble Tea's `Model` interface:\n\n```go\nhost := poly.NewHost(rootAtom, \"My App\")\nprogram := tea.NewProgram(host)\n```\n\nThe host automatically handles `Ctrl+C` and `q` for quitting the application.\n\n## Examples\n\n### Navigation Example\n\n```go\n// Create a menu with navigation\nmainMenu := menu.NewMenu(\"Main Menu\",\n    menu.NewMenuItem(SettingsAtom{}, \"Settings\"),\n    menu.NewMenuItem(AboutAtom{}, \"About\"),\n    menu.NewMenuItem(QuitAtom{}, \"Exit\"),\n)\n\n// Wrap in a navigation chain\nnav := poly.NewChain(mainMenu)\n\n// The menu will automatically push selected atoms onto the stack\n// Users can press 'esc' to pop back to previous screens\n```\n\n### Form Wizard Example\n\n```go\n// Multi-step form using stack navigation\ntype Step1 struct { /* ... */ }\ntype Step2 struct { /* ... */ }\ntype Step3 struct { /* ... */ }\n\nfunc (s Step1) Update(msg tea.Msg) (poly.Atom, tea.Cmd) {\n    switch msg := msg.(type) {\n    case tea.KeyMsg:\n        if msg.String() == \"enter\" {\n            // Move to next step\n            return s, poly.Push(Step2{data: s.collectData()})\n        }\n    }\n    return s, nil\n}\n```\n\n### Error Handling\n\n```go\nfunc (a MyAtom) Update(msg tea.Msg) (poly.Atom, tea.Cmd) {\n    switch msg := msg.(type) {\n    case poly.ErrorMsg:\n        // Handle errors from commands\n        return ErrorAtom{error: error(msg)}, nil\n    }\n    return a, nil\n}\n\n// Emit errors from commands\nfunc someFailingCommand() tea.Cmd {\n    return poly.Error(fmt.Errorf(\"something went wrong\"))\n}\n```\n\n## Gels (Components)\n\nPolymer includes reusable components called \"gels\":\n\n### Menu\n\n```go\nimport \"github.com/trippwill/polymer/gels/menu\"\n\n// Create a menu with items\nmenu := menu.NewMenu(\"Choose an option\",\n    menu.NewMenuItem(atom1, \"First Option\"),\n    menu.NewMenuItem(atom2, \"Second Option\"),\n)\n```\n\n## Adapters\n\nPolymer provides adapters for interoperability with Bubble Tea:\n\n### Using Bubble Tea Models in Polymer\n\n```go\n// Wrap a Bubble Tea model as an Atom\nbubbleTeaModel := textinput.New()\natom := poly.AtomAdapter{\n    Model: bubbleTeaModel,\n    AtomName: \"Text Input\",\n}\n```\n\n### Using Polymer Atoms in Bubble Tea\n\n```go\n// Wrap a Polymer Atom as a Bubble Tea Model\natom := MyAtom{}\nmodel := poly.WrapAtom(atom)\n```\n\n## Debugging and Tracing\n\nUse the trace package for detailed logging:\n\n```go\nimport \"github.com/trippwill/polymer/trace\"\n\n// Set up logging\nlogger := log.New(os.Stderr, \"debug: \", log.LstdFlags)\n\n// Apply logging to your atom\ntraced := poly.WithLens(myAtom, trace.WithLogging(logger)...)\n```\n\n## Building and Running\n\n```bash\n# Build the library\ngo build ./...\n\n# Run the example\ncd examples/wizard\ngo run main.go\n\n# The example demonstrates:\n# - Menu navigation\n# - Stack-based UI flow\n# - Input handling\n# - Multi-screen applications\n```\n\n## Architecture\n\nPolymer follows these design principles:\n\n1. **Composition over Inheritance**: Build complex UIs by composing simple Atoms\n2. **Unidirectional Data Flow**: Messages flow down, state flows up\n3. **Immutable State**: Atoms return new instances rather than mutating themselves\n4. **Minimal Interface**: The `Atom` interface has just three methods\n5. **Bubble Tea Compatibility**: Seamlessly integrate with the Bubble Tea ecosystem\n\n## API Reference\n\n### Core Types\n\n- `Atom` - The main interface for UI components\n- `Chain` - Stack-based navigation manager\n- `Lens` - Lifecycle hooks and observability\n- `Host` - Bubble Tea integration layer\n\n### Navigation Messages\n\n- `PushMsg` - Add atom to stack\n- `PopMsg` - Remove top atom from stack  \n- `ReplaceMsg` - Replace top atom\n- `ResetMsg` - Reset stack to single atom\n\n### Utility Functions\n\n- `OptionalInit(atom)` - Call Init() if atom implements Initializer\n- `Push(atom)`, `Pop()`, `Replace(atom)`, `Reset(atom)` - Navigation commands\n- `Error(err)` - Convert error to command\n\n## Contributing\n\nContributions are welcome! Please feel free to submit a Pull Request.\n\n## License\n\nMIT License - see [LICENSE](LICENSE) file for details.","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ftrippwill%2Fpolymer","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Ftrippwill%2Fpolymer","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ftrippwill%2Fpolymer/lists"}