10 ms·
Bubble Tea: fun, functional and stateful way to build terminal apps
- simulate-me 5y agoOne thing that I like about this is the implementation of returning state from the Update function. My only experience with Elm-style architecture is with react / redux which involves meticulously copying pieces of the state object to return two distinct before / after states. Using a Go struct with copy semantics makes this extremely easy and more natural to write in an imperative fashion. One limitation of this is that the model structure can only contain value type (e.g. no pointers, arrays, or maps).
- mordechai9000 5y agoJust curious, I'm not familiar with Go. Will it copy the references anyway, meaning both structures now have a pointer to the same object? That's the way it works in other languages I'm familiar with, so you have to be careful about what you copy and how you use it.
- kgeist 5y ago>Will it copy the references anyway, meaning both structures now have a pointer to the same object? Correct. A value copy is a simple shallow copy. Deep copy requires use of reflection (if you don't want to manually manage copying).
- arccy 5y agoyes, that's what it does in go
- tonyhb 5y agoYes, but it doesn't actually matter. You can use pointers for models, return the same pointer, and it will re-render fine. We do this for our CLI at https://www.inngest.com https://www.inngest.com for creating new serverless functions via a quick walkthrough. It's actually the `tea.Msg` that causes re-renders. Here's the code: https://github.com/charmbracelet/bubbletea/blob/v0.20.0/tea.go#L491-L551 https://github.com/charmbracelet/bubbletea/blob/v0.20.0/tea..... tea.Msg is, in Redux land, an "action" that triggers some state updates and _always_ triggers a re-render, even if nothing changes. This is elm-like, but we have to understand the limitations of what we're working with: a terminal with no way of (nicely) updating elements in place. It's essentially an immediate-mode UI, and so it always paints.
- sriram_malhar 5y agoWell, it does matter, or rather, it could matter. For example, say you needed an undo/redo mechanism. If the model were guaranteed to be immutable model, you could simply hang on to the previous models as a sequence of state changes; undoing/redoing is trivial. If the model is mutable, then the undo/redo system has to defensively make a copy before update is called
- christianrocha 5y agoDo note, however, that paints will only occur if the output changes, and only lines that have changed will be redrawn.
- kgeist 5y ago>One limitation of this is that the model structure can only contain value type (e.g. no pointers, arrays, or maps) How does one manage dynamically sized lists of elements, if arrays are disallowed?
- simulate-me 5y agoYou can use arrays, but if you want to maintain the Elm-like model of before and after states, then you need to explicitly copy the array into the new state rather than rely on Go copying just the pointer.
- mfarstad 5y agoOne of my favorite TUI frameworks. I made https://github.com/mathaou/termdbms https://github.com/mathaou/termdbms with it. A very pleasant experience.
- throwawayboise 5y agoThat looks pretty cool, but as most/all DBMSs come with a TUI utility*, what is the advantage? *(psql, sqlplus, isql, etc....)
- mfarstad 5y agolooks pretty and I think its pretty easy to use. Didn't look at what anyone else had done, tho.
- pstuart 5y agoHa, I checked it out and it was definitely worthy of a star -- then I noticed I'd already done so. Now I just need to get around to playing with it.
- djmips 5y agoI don't like things that pollute our natural language namespace. Couldn't you have named it something unique?
- tsm 5y agoAn overwhelming number of programming-related things "pollute our natural language namespace". Off the top of my head: Ruby, Python, Java, Rails, React, Go, Rust, Elm, Dart, C, C#, Node, Next, Nest, Kafka, LaTeX, bash, fish, cat, Android, Apple, Windows… I'd be happy to search for this with "bubble tea framework" or "bubble tea tui" or similar and it doesn't bother me.
- dvngnt_ 5y agoelm?
- kube-system 5y agoIt’s a type of tree.
- fwip 5y agoYes, an elm is a kind of tree.
- mrtranscendence 5y agoI'm having trouble thinking of a single example of a language, library, or piece of technology that is not either an acronym, a name of something that exists, or a combination of such names. Be it an object (Flask), a concept (Scheme), a letter (C), a person (Sinatra), or an animal (Python). Maybe we need explicit namespacing in English? I'll start saying stuff like "programming languages colon colon ruby" so people can be absolutely sure what I'm talking about.
- hkt 5y agoAlas, people might get the wrong idea about what kind of colon you mean.
- dangets 5y agoThis and the surrounding ecosystem was recently featured on an episode of The Changelog podcast. https://changelog.com/podcast/481 https://changelog.com/podcast/481
- jerodsanto 5y agoThanks for sharing the show! Here's a transcript for those who'd rather read: https://changelog.com/podcast/481#transcript https://changelog.com/podcast/481#transcript And a couple audiogram snippets from the conversation: https://www.youtube.com/watch?v=8-5WAKrt9GQ https://www.youtube.com/watch?v=8-5WAKrt9GQ https://www.youtube.com/watch?v=OE5LzZbojX8 https://www.youtube.com/watch?v=OE5LzZbojX8
- brianzelip 5y agoHey it’s our Internet friend!
- substation13 5y agoThis looks like a really cool project, however I have to say that the Go language seems like a terrible match for the Elm architecture.
- aarpmcgee 5y agoI’m not overly familiar with Go and would be curious to hear more details about this.
- substation13 5y agoSome of the features that make Elm and Elm architecture work so well together: - Light-weight lambda syntax - Sum types and records - Global type inference - Exhaustive match expressions - Powerful generics - Immutability by default - Partial application / currying - Modules - Ecosystem of packages built around pure functions
- cosmotic 5y agoClippy: It looks like you're trying to make a GUI, would you like help with that?
- anderspitman 5y agoI spent a good chunk of time last week looking for a solid cross-platform GUI toolkit. I came to the conclusion that the terminal is the most portable GUI platform available. You can create an app that has windows, buttons, mouse support, etc, statically compile it for Windows, Linux, and Mac, and run it over SSH. The closest you can get to that with real graphics is using a toolkit built on OpenGL, and you'll be forced to dynamically link to X11 or Wayland on Linux. The achilles heel of terminal UIs is that they can't display images.
- Hamcha 5y agoThis is so sad. Every time I boot up Plan9 for fun I'm reminded their remoting solution (drawterm) does graphics just fine (since everything is just files, and graphics is done by writing to a software framebuffer device file). Sure, it's something you can do with SSH via X11 forwarding since forever, but it seems the ecosystem never quite stuck the landing, and now we're here trying to figure out how to make CLI more like GUI for our own sanity. Maybe we should give it another shot? It seems Windows is trying to do something similar with WSLg to achieve seamless integration of Linux apps within Windows 11 (using RDP under the hood), what is everyone else doing?
- oddlama 5y agoI'm actually kind of glad that X11 forwarding didn't stick. TUIs are generally efficiently navigatable using just the keyboard, a property I very much enjoy and frequently miss in "real GUI" apps.
- digisign 5y agoThey can display images, though the resolution is not very high, even with sixels.
- qbasic_forever 5y agoI'd look at Qt or Electron if you need to do cross-platform desktop apps, if for no other reason than accessibility. Sure you can make wacky midnight commander like GUIs in the console, but no screen reader is going to be able to make heads or tails of them and you'll shut out users.
- nepeckman 5y agoI've seen the charm suite on HN before, and everytime I see them I wish they had bindings to other languages. I'm just not interested in Go, but I'm really interested in learning to create ssh applications. Its an application runtime with a lot of potential for the dev space, but almost no quick-start frameworks!
- shirogane86x 5y agoif you need a fun language to learn to make TUIs, haskell has the brick library :) . I've heard very good things about it, it's declarative, only downside is that it doesn't support windows.
- kelvie 5y agoWhy not? There's a lot to hate about every language, but one advantage about Go is that it's fairly easy to context switch in/out of, which makes it great for side projects, because it's cognitive load while using it is really low. Unlike say, Rust. I do love Rust though.
- nepeckman 5y agoI'm only really interested in learning a language if it excites me, or if I'm getting paid to do it. I don't hate Go, and would be fine to learn it on company time for company projects, but there is no spark that would lead me to learn the language on my own. I've written some basic Go, but if I'm using it in personal projects, I'd would have to invest time to understand the ecosystem, runtime, standard lib, best practices, etc.
- ivantse1 5y agoLoved this framework as it helped me build my ssh app idea really quickly (https://github.com/ivantsepp/ssh-slides https://github.com/ivantsepp/ssh-slides)! In fact, it pushed me to finally learn golang haha. Would love seeing more and more ssh apps in the wild.
- BaconPackets 5y agoWe recently did a quick POC with py-cui for a TUI app. It worked pretty well but you quickly see the limits. This looks really interesting and could be a fun way to get into the Go landscape!
- shriphani 5y agoI've been using dialoguer [1], indicatif [2], and colour [3] for the rust ecosystem. Really high quality libraries: [1] https://docs.rs/dialoguer/latest/dialoguer/ https://docs.rs/dialoguer/latest/dialoguer/ [2] https://github.com/console-rs/indicatif https://github.com/console-rs/indicatif [3] https://docs.rs/colour/latest/colour/ https://docs.rs/colour/latest/colour/
- xbar 5y agoThanks. I keep looking for Bubble Tea alternatives in rust. I am glad to have some handles to a few. After seeing some recent posts on HN, I've been fantasizing about a Turbo Rust project.
- sbeckeriv 5y agoI enjoyed using https://github.com/fdehau/tui-rs https://github.com/fdehau/tui-rs on a few side projects.
- tom_brady_4_eva 5y ago
- hamdouni 5y ago