From 4233081da2f2fcffdd864f3d248cc00b00dd1956 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Mon, 16 Sep 2024 13:01:08 +0000 Subject: [PATCH] Bump github.com/charmbracelet/bubbletea from 1.1.0 to 1.1.1 Bumps [github.com/charmbracelet/bubbletea](https://github.com/charmbracelet/bubbletea) from 1.1.0 to 1.1.1. - [Release notes](https://github.com/charmbracelet/bubbletea/releases) - [Changelog](https://github.com/charmbracelet/bubbletea/blob/main/.goreleaser.yml) - [Commits](https://github.com/charmbracelet/bubbletea/compare/v1.1.0...v1.1.1) --- updated-dependencies: - dependency-name: github.com/charmbracelet/bubbletea dependency-type: direct:production update-type: version-update:semver-patch ... Signed-off-by: dependabot[bot] --- go.mod | 2 +- go.sum | 4 +- .../charmbracelet/bubbletea/README.md | 168 ++++++------------ .../charmbracelet/bubbletea/options.go | 8 +- .../github.com/charmbracelet/bubbletea/tea.go | 75 ++++---- vendor/modules.txt | 2 +- 6 files changed, 107 insertions(+), 152 deletions(-) diff --git a/go.mod b/go.mod index 82433f8..c983edc 100644 --- a/go.mod +++ b/go.mod @@ -4,7 +4,7 @@ go 1.22.0 require ( github.com/atotto/clipboard v0.1.4 - github.com/charmbracelet/bubbletea v1.1.0 + github.com/charmbracelet/bubbletea v1.1.1 github.com/spf13/cobra v1.8.1 github.com/tobischo/gokeepasslib/v3 v3.6.0 golang.org/x/term v0.24.0 diff --git a/go.sum b/go.sum index d48e78d..257d756 100644 --- a/go.sum +++ b/go.sum @@ -2,8 +2,8 @@ github.com/atotto/clipboard v0.1.4 h1:EH0zSVneZPSuFR11BlR9YppQTVDbh5+16AmcJi4g1z github.com/atotto/clipboard v0.1.4/go.mod h1:ZY9tmq7sm5xIbd9bOK4onWV4S6X0u6GY7Vn0Yu86PYI= github.com/aymanbagabas/go-osc52/v2 v2.0.1 h1:HwpRHbFMcZLEVr42D4p7XBqjyuxQH5SMiErDT4WkJ2k= github.com/aymanbagabas/go-osc52/v2 v2.0.1/go.mod h1:uYgXzlJ7ZpABp8OJ+exZzJJhRNQ2ASbcXHWsFqH8hp8= -github.com/charmbracelet/bubbletea v1.1.0 h1:FjAl9eAL3HBCHenhz/ZPjkKdScmaS5SK69JAK2YJK9c= -github.com/charmbracelet/bubbletea v1.1.0/go.mod h1:9Ogk0HrdbHolIKHdjfFpyXJmiCzGwy+FesYkZr7hYU4= +github.com/charmbracelet/bubbletea v1.1.1 h1:KJ2/DnmpfqFtDNVTvYZ6zpPFL9iRCRr0qqKOCvppbPY= +github.com/charmbracelet/bubbletea v1.1.1/go.mod h1:9Ogk0HrdbHolIKHdjfFpyXJmiCzGwy+FesYkZr7hYU4= github.com/charmbracelet/lipgloss v0.13.0 h1:4X3PPeoWEDCMvzDvGmTajSyYPcZM4+y8sCA/SsA3cjw= github.com/charmbracelet/lipgloss v0.13.0/go.mod h1:nw4zy0SBX/F/eAO1cWdcvy6qnkDUxr8Lw7dvFrAIbbY= github.com/charmbracelet/x/ansi v0.2.3 h1:VfFN0NUpcjBRd4DnKfRaIRo53KRgey/nhOoEqosGDEY= diff --git a/vendor/github.com/charmbracelet/bubbletea/README.md b/vendor/github.com/charmbracelet/bubbletea/README.md index 9a8d93e..f80e04e 100644 --- a/vendor/github.com/charmbracelet/bubbletea/README.md +++ b/vendor/github.com/charmbracelet/bubbletea/README.md @@ -35,7 +35,7 @@ Be sure to check out [Bubbles][bubbles], a library of common UI components for B Text Input Example from Bubbles

-*** +--- ## Tutorial @@ -49,7 +49,7 @@ By the way, the non-annotated source code for this program is available [on GitHub][tut-source]. [elm]: https://guide.elm-lang.org/architecture/ -[tut-source]:https://github.com/charmbracelet/bubbletea/tree/master/tutorials/basics +[tut-source]: https://github.com/charmbracelet/bubbletea/tree/master/tutorials/basics ### Enough! Let's get to it. @@ -72,9 +72,9 @@ import ( Bubble Tea programs are comprised of a **model** that describes the application state and three simple methods on that model: -* **Init**, a function that returns an initial command for the application to run. -* **Update**, a function that handles incoming events and updates the model accordingly. -* **View**, a function that renders the UI based on the data in the model. +- **Init**, a function that returns an initial command for the application to run. +- **Update**, a function that handles incoming events and updates the model accordingly. +- **View**, a function that renders the UI based on the data in the model. ### The Model @@ -275,11 +275,11 @@ $ dlv connect 127.0.0.1:43000 ``` If you do not explicitly supply the `--listen` flag, the port used will vary -per run, so passing this in makes the debugger easier to use from a script -or your IDE of choice. +per run, so passing this in makes the debugger easier to use from a script +or your IDE of choice. -Additionally, we pass in `--api-version=2` because delve defaults to version 1 -for backwards compatibility reasons. However, delve recommends using version 2 +Additionally, we pass in `--api-version=2` because delve defaults to version 1 +for backwards compatibility reasons. However, delve recommends using version 2 for all new development and some clients may no longer work with version 1. For more information, see the [Delve documentation](https://github.com/go-delve/delve/tree/master/Documentation/api). @@ -305,13 +305,13 @@ your program in another window. ## Libraries we use with Bubble Tea -* [Bubbles][bubbles]: Common Bubble Tea components such as text inputs, viewports, spinners and so on -* [Lip Gloss][lipgloss]: Style, format and layout tools for terminal applications -* [Harmonica][harmonica]: A spring animation library for smooth, natural motion -* [BubbleZone][bubblezone]: Easy mouse event tracking for Bubble Tea components -* [ntcharts][ntcharts]: A terminal charting library built for Bubble Tea and [Lip Gloss][lipgloss] -* [Termenv][termenv]: Advanced ANSI styling for terminal applications -* [Reflow][reflow]: Advanced ANSI-aware methods for working with text +- [Bubbles][bubbles]: Common Bubble Tea components such as text inputs, viewports, spinners and so on +- [Lip Gloss][lipgloss]: Style, format and layout tools for terminal applications +- [Harmonica][harmonica]: A spring animation library for smooth, natural motion +- [BubbleZone][bubblezone]: Easy mouse event tracking for Bubble Tea components +- [ntcharts][ntcharts]: A terminal charting library built for Bubble Tea and [Lip Gloss][lipgloss] +- [Termenv][termenv]: Advanced ANSI styling for terminal applications +- [Reflow][reflow]: Advanced ANSI-aware methods for working with text [bubbles]: https://github.com/charmbracelet/bubbles [lipgloss]: https://github.com/charmbracelet/lipgloss @@ -323,109 +323,44 @@ your program in another window. ## Bubble Tea in the Wild -For some Bubble Tea programs in production, see: - -* [ASCII Movie](https://github.com/gabe565/ascii-movie): a Star Wars ASCII art movie player -* [AT CLI](https://github.com/daskycodes/at_cli): execute AT Commands via serial port connections -* [Aztify](https://github.com/Azure/aztfy): bring Microsoft Azure resources under Terraform -* [brows](https://github.com/rubysolo/brows): a GitHub release browser -* [Canard](https://github.com/mrusme/canard): an RSS client -* [charm](https://github.com/charmbracelet/charm): the official Charm user account manager -* [chatgpt-cli](https://github.com/j178/chatgpt): a CLI for ChatGPT -* [chatgpt-tui](https://github.com/tearingItUp786/chatgpt-tui): a TUI for ChatGPT with SQLite sessions -* [ChatGPTUI](https://github.com/dwisiswant0/chatgptui): a TUI for ChatGPT -* [chezmoi](https://github.com/twpayne/chezmoi): securely manage your dotfiles across multiple machines -* [chip-8](https://github.com/braheezy/chip-8): a CHIP-8 interpreter -* [chtop](https://github.com/chhetripradeep/chtop): monitor your ClickHouse node without leaving the terminal -* [circumflex](https://github.com/bensadeh/circumflex): read Hacker News in the terminal -* [clidle](https://github.com/ajeetdsouza/clidle): a Wordle clone -* [cLive](https://github.com/koki-develop/clive): automate terminal operations and view them live in a browser -* [container-canary](https://github.com/NVIDIA/container-canary): a container validator -* [countdown](https://github.com/aldernero/countdown): a multi-event countdown timer -* [CRT](https://github.com/BigJk/crt): a simple terminal emulator for running Bubble Tea in a dedicated window, with optional shaders -* [cueitup](https://github.com/dhth/cueitup): inspect messages in an AWS SQS queue in a simple and deliberate manner -* [Daytona](https://github.com/daytonaio/daytona): an development environment manager -* [dns53](https://github.com/purpleclay/dns53): dynamic DNS with Amazon Route53; expose your EC2 quickly, securely and privately -* [eks-node-viewer](https://github.com/awslabs/eks-node-viewer): a tool for visualizing dynamic node usage within an EKS cluster -* [End Of Eden](https://github.com/BigJk/end_of_eden): a "Slay the Spire"-like, roguelike deck-builder game -* [enola](https://github.com/sherlock-project/enola): find social media accounts by username across social networks -* [flapioca](https://github.com/kbrgl/flapioca): Flappy Bird on the CLI! -* [fm](https://github.com/knipferrc/fm): a terminal-based file manager -* [fork-cleaner](https://github.com/caarlos0/fork-cleaner): clean up old and inactive forks in your GitHub account -* [fractals-cli](https://github.com/MicheleFiladelfia/fractals-cli): a multiplatform terminal fractal explorer -* [fztea](https://github.com/jon4hz/fztea): a Flipper Zero TUI -* [gama](https://github.com/termkit/gama): manage GitHub Actions from the terminal -* [gambit](https://github.com/maaslalani/gambit): chess in the terminal -* [gembro](https://git.sr.ht/~rafael/gembro): a mouse-driven Gemini browser -* [gh-b](https://github.com/joaom00/gh-b): a GitHub CLI extension for managing branches -* [gh-dash](https://www.github.com/dlvhdr/gh-dash): a GitHub CLI extension for PRs and issues -* [gitflow-toolkit](https://github.com/mritd/gitflow-toolkit): a GitFlow submission tool -* [Glow](https://github.com/charmbracelet/glow): a markdown reader, browser, and online markdown stash -* [go-sweep](https://github.com/maxpaulus43/go-sweep): Minesweeper in the terminal -* [gocovsh](https://github.com/orlangure/gocovsh): explore Go coverage reports from the CLI -* [got](https://github.com/fedeztk/got): a simple translator and text-to-speech app built on simplytranslate's APIs -* [gum](https://github.com/charmbracelet/gum): interactivity and styling for shells and shell scripts -* [hiSHtory](https://github.com/ddworken/hishtory): your shell history in context: synced, and queryable -* [httpit](https://github.com/gonetx/httpit): a rapid http(s) benchmark tool -* [Huh?](https://github.com/charmbracelet/huh): an interactive prompt and form toolkit -* [IDNT](https://github.com/r-darwish/idnt): a batch software uninstaller -* [json-log-viewer](https://github.com/hedhyw/json-log-viewer): an interactive JSON log viewer -* [kboard](https://github.com/CamiloGarciaLaRotta/kboard): a typing game -* [kplay](https://github.com/dhth/kplay): inspect messages in a Kafka topic -* [laboon](https://github.com/arisnacg/laboon): a Docker-desktop-style container manager -* [mc](https://github.com/minio/mc): the official [MinIO](https://min.io) client -* [mergestat](https://github.com/mergestat/mergestat): run SQL queries on git repositories -* [meteor](https://github.com/stefanlogue/meteor): a highly customizable conventional commit message tool -* [mods](https://github.com/charmbracelet/mods): AI on the CLI, built for pipelines -* [nachrichten](https://github.com/zMoooooritz/nachrichten): access up-to-date news in German provided by the [Tagesschau](https://www.tagesschau.de/) -* [Neon Modem Overdrive](https://github.com/mrusme/neonmodem): a BBS-style TUI client for Discourse, Lemmy, Lobste.rs and Hacker News -* [nom](https://github.com/guyfedwards/nom): an RSS reader and manager -* [Noted](https://github.com/torbratsberg/noted): a note viewer and manager -* [outtasync](https://github.com/dhth/outtasync): identify CloudFormation stacks that are out of sync with their template files -* [pathos](https://github.com/chip/pathos): a PATH environment variable editor -* [Plandex](https://github.com/plandex-ai/plandex): a terminal-based AI coding engine for complex tasks -* [portal](https://github.com/ZinoKader/portal): secure transfers between computers -* [prs](https://github.com/dhth/prs): stay up to date with your PRs -* [puffin](https://github.com/siddhantac/puffin): a TUI for hledger to manage your finances -* [pug](https://github.com/leg100/pug): terraform task manager -* [punchout](https://github.com/dhth/punchout): takes the suck out of logging time on JIRA -* [redis-viewer](https://github.com/SaltFishPr/redis-viewer): a Redis database browser -* [redis_tui](https://github.com/mat2cc/redis_tui): a Redis database browser -* [schemas](https://github.com/dhth/schemas): lets you inspect postgres schemas in the terminal -* [scrabbler](https://github.com/wI2L/scrabbler): an automatic draw tool for your duplicate Scrabble games -* [sku](https://github.com/fedeztk/sku): Sudoku on the CLI -* [Slides](https://github.com/maaslalani/slides): a markdown-based presentation tool -* [SlurmCommander](https://github.com/CLIP-HPC/SlurmCommander): a Slurm workload manager -* [Soft Serve](https://github.com/charmbracelet/soft-serve): a command-line-first Git server that runs a TUI over SSH -* [solitaire-tui](https://github.com/brianstrauch/solitaire-tui): Klondike Solitaire for the terminal -* [StormForge Optimize Controller](https://github.com/thestormforge/optimize-controller): a tool for experimenting with application configurations in Kubernetes -* [Storydb](https://github.com/grrlopes/storydb): an improved bash/zsh-style ctrl+r command history finder -* [STTG](https://github.com/wille1101/sttg): a teletext client for SVT, Sweden’s national public television station -* [sttr](https://github.com/abhimanyu003/sttr): a general-purpose text transformer -* [superfile](https://github.com/MHNightCat/superfile) a fancy, modern terminal-based file manager -* [tasktimer](https://github.com/caarlos0/tasktimer): a dead-simple task timer -* [termdbms](https://github.com/mathaou/termdbms): a keyboard and mouse driven database browser -* [tgpt](https://github.com/aandrew-me/tgpt): conversational AI for the CLI; no API keys necessary -* [ticker](https://github.com/achannarasappa/ticker): a terminal stock viewer and stock position tracker -* [trainer](https://github.com/rusinikita/trainer): a Go concurrency coding interview simulator with learning materials -* [tran](https://github.com/abdfnx/tran): securely transfer stuff between computers (based on [portal](https://github.com/ZinoKader/portal)) -* [Trufflehog](https://github.com/trufflesecurity/trufflehog): find leaked credentials -* [Typer](https://github.com/maaslalani/typer): a typing test -* [typioca](https://github.com/bloznelis/typioca): a typing test -* [tz](https://github.com/oz/tz): a scheduling aid for people in multiple time zones -* [ugm](https://github.com/ariasmn/ugm): a unix user and group browser -* [walk](https://github.com/antonmedv/walk): a terminal navigator -* [wander](https://github.com/robinovitch61/wander): a HashiCorp Nomad terminal client -* [WG Commander](https://github.com/AndrianBdn/wg-cmd): a TUI for a simple WireGuard VPN setup -* [wishlist](https://github.com/charmbracelet/wishlist): an SSH directory +There are over 8k applications built with Bubble Tea! Here are a handful of ’em. + +### Staff favourites + +- [chezmoi](https://github.com/twpayne/chezmoi): securely manage your dotfiles across multiple machines +- [circumflex](https://github.com/bensadeh/circumflex): read Hacker News in the terminal +- [gh-dash](https://www.github.com/dlvhdr/gh-dash): a GitHub CLI extension for PRs and issues +- [Tetrigo](https://github.com/Broderick-Westrope/tetrigo): Tetris in the terminal + +### In Industry + +- Microsoft Azure – [Aztify](https://github.com/Azure/aztfy): bring Microsoft Azure resources under Terraform +- Daytona – [Daytona](https://github.com/daytonaio/daytona): open source dev environment manager +- Truffle Security Co. – [Trufflehog](https://github.com/trufflesecurity/trufflehog): find leaked credentials +- NVIDIA – [container-canary](https://github.com/NVIDIA/container-canary) from NVIDIA: a container validator +- AWS – [eks-node-viewer](https://github.com/awslabs/eks-node-viewer) from AWS: a tool for visualizing dynamic node usage within an EKS cluster +- MinIO – [mc](https://github.com/minio/mc) from Min.io: the official [MinIO](https://min.io) client + +### Charm stuff + +- [Glow](https://github.com/charmbracelet/glow): a markdown reader, browser, and online markdown stash +- [Huh?](https://github.com/charmbracelet/huh): an interactive prompt and form toolkit +- [Mods](https://github.com/charmbracelet/mods): AI on the CLI, built for pipelines +- [Wishlist](https://github.com/charmbracelet/wishlist): an SSH directory (and bastion!) + +### There’s so much more where that came from + +For more applications built with Bubble Tea see [Charm & Friends][community]. +Is there something cool you made with Bubble Tea you want to share? [PRs][community] are +welcome! ## Feedback -We'd love to hear your thoughts on this project. Feel free to drop us a note! +We’d love to hear your thoughts on this project. Feel free to drop us a note! -* [Twitter](https://twitter.com/charmcli) -* [The Fediverse](https://mastodon.social/@charmcli) -* [Discord](https://charm.sh/chat) +- [Twitter](https://twitter.com/charmcli) +- [The Fediverse](https://mastodon.social/@charmcli) +- [Discord](https://charm.sh/chat) ## Acknowledgments @@ -437,12 +372,13 @@ of days past. [elm]: https://guide.elm-lang.org/architecture/ [gotea]: https://github.com/tj/go-tea [zb]: https://de.wikipedia.org/wiki/Zeichenorientierte_Benutzerschnittstelle +[community]: https://github.com/charm-and-friends/charm-in-the-wild ## License [MIT](https://github.com/charmbracelet/bubbletea/raw/master/LICENSE) -*** +--- Part of [Charm](https://charm.sh). diff --git a/vendor/github.com/charmbracelet/bubbletea/options.go b/vendor/github.com/charmbracelet/bubbletea/options.go index 4a56fc8..06abf4a 100644 --- a/vendor/github.com/charmbracelet/bubbletea/options.go +++ b/vendor/github.com/charmbracelet/bubbletea/options.go @@ -235,9 +235,13 @@ func WithFPS(fps int) ProgramOption { } } -// WithReportFocus enables reporting when the terminal gains and lost focus. +// WithReportFocus enables reporting when the terminal gains and loses +// focus. When this is enabled [FocusMsg] and [BlurMsg] messages will be sent +// to your Update method. // -// You can then check for FocusMsg and BlurMsg in your model's Update method. +// Note that while most terminals and multiplexers support focus reporting, +// some do not. Also note that tmux needs to be configured to report focus +// events. func WithReportFocus() ProgramOption { return func(p *Program) { p.startupOptions |= withReportFocus diff --git a/vendor/github.com/charmbracelet/bubbletea/tea.go b/vendor/github.com/charmbracelet/bubbletea/tea.go index 5ed9707..87211ba 100644 --- a/vendor/github.com/charmbracelet/bubbletea/tea.go +++ b/vendor/github.com/charmbracelet/bubbletea/tea.go @@ -128,6 +128,10 @@ func (h channelHandlers) shutdown() { type Program struct { initialModel Model + // handlers is a list of channels that need to be waited on before the + // program can exit. + handlers channelHandlers + // Configuration options that will set as the program is initializing, // treated as bits. These options can be set via various ProgramOptions. startupOptions startupOptions @@ -312,6 +316,11 @@ func (p *Program) handleCommands(cmds chan Cmd) chan struct{} { // possible to cancel them so we'll have to leak the goroutine // until Cmd returns. go func() { + // Recover from panics. + if !p.startupOptions.has(withoutCatchPanics) { + defer p.recoverFromPanic() + } + msg := cmd() // this can be long. p.Send(msg) }() @@ -460,7 +469,7 @@ func (p *Program) eventLoop(model Model, cmds chan Cmd) (Model, error) { // terminated by either [Program.Quit], [Program.Kill], or its signal handler. // Returns the final model. func (p *Program) Run() (Model, error) { - handlers := channelHandlers{} + p.handlers = channelHandlers{} cmds := make(chan Cmd) p.errs = make(chan error) p.finished = make(chan struct{}, 1) @@ -507,19 +516,12 @@ func (p *Program) Run() (Model, error) { // Handle signals. if !p.startupOptions.has(withoutSignalHandler) { - handlers.add(p.handleSignals()) + p.handlers.add(p.handleSignals()) } // Recover from panics. if !p.startupOptions.has(withoutCatchPanics) { - defer func() { - if r := recover(); r != nil { - p.shutdown(true) - fmt.Printf("Caught panic:\n\n%s\n\nRestoring terminal...\n\n", r) - debug.PrintStack() - return - } - }() + defer p.recoverFromPanic() } // If no renderer is set use the standard one. @@ -561,7 +563,7 @@ func (p *Program) Run() (Model, error) { model := p.initialModel if initCmd := model.Init(); initCmd != nil { ch := make(chan struct{}) - handlers.add(ch) + p.handlers.add(ch) go func() { defer close(ch) @@ -584,10 +586,10 @@ func (p *Program) Run() (Model, error) { } // Handle resize events. - handlers.add(p.handleResize()) + p.handlers.add(p.handleResize()) // Process commands. - handlers.add(p.handleCommands(cmds)) + p.handlers.add(p.handleCommands(cmds)) // Run event loop, handle updates and draw. model, err := p.eventLoop(model, cmds) @@ -599,21 +601,6 @@ func (p *Program) Run() (Model, error) { p.renderer.write(model.View()) } - // Tear down. - p.cancel() - - // Check if the cancel reader has been setup before waiting and closing. - if p.cancelReader != nil { - // Wait for input loop to finish. - if p.cancelReader.Cancel() { - p.waitForReadLoop() - } - _ = p.cancelReader.Close() - } - - // Wait for all handlers to finish. - handlers.shutdown() - // Restore terminal state. p.shutdown(killed) @@ -668,7 +655,7 @@ func (p *Program) Quit() { // The final render that you would normally see when quitting will be skipped. // [program.Run] returns a [ErrProgramKilled] error. func (p *Program) Kill() { - p.cancel() + p.shutdown(true) } // Wait waits/blocks until the underlying Program finished shutting down. @@ -679,6 +666,22 @@ func (p *Program) Wait() { // shutdown performs operations to free up resources and restore the terminal // to its original state. func (p *Program) shutdown(kill bool) { + p.cancel() + + // Wait for all handlers to finish. + p.handlers.shutdown() + + // Check if the cancel reader has been setup before waiting and closing. + if p.cancelReader != nil { + // Wait for input loop to finish. + if p.cancelReader.Cancel() { + if !kill { + p.waitForReadLoop() + } + } + _ = p.cancelReader.Close() + } + if p.renderer != nil { if kill { p.renderer.kill() @@ -688,7 +691,19 @@ func (p *Program) shutdown(kill bool) { } _ = p.restoreTerminalState() - p.finished <- struct{}{} + if !kill { + p.finished <- struct{}{} + } +} + +// recoverFromPanic recovers from a panic, prints the stack trace, and restores +// the terminal to a usable state. +func (p *Program) recoverFromPanic() { + if r := recover(); r != nil { + p.shutdown(true) + fmt.Printf("Caught panic:\n\n%s\n\nRestoring terminal...\n\n", r) + debug.PrintStack() + } } // ReleaseTerminal restores the original terminal state and cancels the input diff --git a/vendor/modules.txt b/vendor/modules.txt index 1fa3ad5..b659a35 100644 --- a/vendor/modules.txt +++ b/vendor/modules.txt @@ -4,7 +4,7 @@ github.com/atotto/clipboard # github.com/aymanbagabas/go-osc52/v2 v2.0.1 ## explicit; go 1.16 github.com/aymanbagabas/go-osc52/v2 -# github.com/charmbracelet/bubbletea v1.1.0 +# github.com/charmbracelet/bubbletea v1.1.1 ## explicit; go 1.18 github.com/charmbracelet/bubbletea # github.com/charmbracelet/lipgloss v0.13.0