8 ms·
Ink: React for interactive command-line apps
- claytongulick 4y ago[flagged]
- brundolf 4y agoVery neat idea. I love how decoupled React is from the different renderers, and how well its paradigm of "render a tree of things that updates as state changes" translates to different kinds of UIs
- blackbear_ 4y agoReact is indeed really neat. At the same time, however, I miss the visual drag & drop GUI designers that were in vogue a few decades ago. HTML and CSS are the tragedy of modern UI design.
- kamikaz1k 4y agoyou can use drag and drop GUI builders on top of react. there's been a lot of attempts at that. a significant recent effort from Wix: https://www.codux.com/ https://www.codux.com/
- WorldMaker 4y agoIt's one of those "grass is greener on the other side" situations. I'm currently bouncing back and forth between VB6 and HTML/CSS and yeah sometimes it is nice to just quickly drag something into place, but other times I really wish I could just use a layout system like CSS Grid (or Flexbox) and give it all the items I need and let it figure out how to lay it out. For instance, recently I had to edit some "tables" in VB6 that turned out to have been hand-drawn with pixel-perfect lines and changes were incredibly slow and I would have murdered for that to be in HTML/CSS. Sometimes I like (and miss) the best of both worlds in XAML where it has drag-and-drop design tools, but also the copy-and-paste and handwrite support of XML, and it has modern layout tools like Grids for auto-layouts/responsive layouts.
- jalk 4y agoAnd you can search/diff the pure text representation which is a major plus as well. I absolutely hate the workflow of constantly moving the mouse back and forth between the visual components and some gigantic property panel sitting at the edge of the window (index-finger programming). Floating windows are even worse, as they always seem to get in the way, so now also spend time on window ceremony (moving / resizing the "floaters"). In graphics tools(InkScape for instance) I almost always move objects around using the cursor keys as my mouse based positioning skills are just not accurate enough (and I know that I'm not the only one) Anybody have good examples of tools (graphics editors for instance) that has a good alternative to that clunky property pane?
- Shorel 4y agoThe grid system of wxWidgets also works like that. It has drag-and-drop design tools, and copy-paste, and it can be written programmatically. So the best of both worlds exists, and it is just not used enough. wxWidgets has Python bindings.
- kaeland 4y agoTry CLOG, https://github.com/rabbibotton/clog https://github.com/rabbibotton/clog
- _2z1p 4y agoThe drag and drop GUI designers used to work because most people were using screens that were approximately the same size and resolution for the most part back then. That is no longer the case today when there is pressure to support everything from a smart watch all the way up to a UHD 4K monitor or TV. Fixed layouts are also much more difficult to localize and translate to other languages than modern layout systems.
- Cthulhu_ 4y agoAnd yet, I found Apple's Interface Builder to work pretty well, for apps that should work on phones and tablets in both portrait and landscape mode. Mind you, this was a long time ago now.
- nathancahill 4y agoApple's IB used a constraint-based layout by default. It was a fairly novel idea at the time. HTML was ill-suited for that until flexbox/grid came along.
- pcl 4y agoYeah, it’s stunning how many UIs fit within their struts and springs model, and how well they model scales to resolution changes.
- FpUser 4y agoModern drag and drop designers / components do support flexible layouts
- manojlds 4y agoThat's what a lot of low code platforms are trying to achieve.
- rcme 4y agoHave you tried WebFlow?
- holoduke 4y agoI worked with many different UI kits. From native windows to Ubuntu to automotive to embedded to Android to Apple. I find HTML and css by far the most convenient UI toolkit there is. Never have creating UIs been so easy as with css. A relief it is.
- seanp2k2 4y agoI view the rise of React and especially Electron as the failure of things like GTK, Qt, and e.g. Swing to make a useable cross-platform GUI toolkit that isn't a total nightmare to work with / compile / debug / install / package...it's literally easier to ship [most of] an entire web browser instead. That's insane to me.
- FpUser 4y ago>"/ compile / debug / install / package" Replace "compile" with transpile, "install" with deploy that are the same things anyways and it sounds like most projects done by web developers. >"That's insane to me" Congrats
- selfmodruntime 4y agoI said this before, but here it goes. People always wished for the *one stack that would work the same 99% of the time for all available platforms. Now that it's here, they hate it. Yes, Electron is bad, but there are alternatives in progress. Layouting with HTML and CSS is here to stay. It's like git, the best of all the worst tools to get the job done.
- flexagoon 4y agoWell, there's also Flutter
- Conscat 4y agoFlutter isn't acceptable for Apple platforms, especially iOS. It technically exists, but barely works.
- selfmodruntime 4y agoAs someone who relies on accessibility, flutter is a nightmare.
- mhink 4y agoOne of my favorite side projects (from several years ago now) was a custom renderer implementation that let one use React to manage the parts of an Electron app outside the page being rendered. [1] I never found the time to actually go through and make it robust enough to use in a production setting, but I remember being very pleased with how much easier it was to use than the native Electron APIs. Maybe I'll revisit this sometime. :) 1: https://github.com/mhink/react-ionize https://github.com/mhink/react-ionize
- brundolf 4y agoHah, that's pretty cool!
- Alifatisk 4y agoI am both afraid and impressed.
- vanjajaja1 4y agosame, I can't decide if this clever and going in the right direction, or solving the wrong problem the wrong way. very unique, either way
- brabel 4y agoCheck the list of apps using it. This one got my attention: https://github.com/sindresorhus/emoj https://github.com/sindresorhus/emoj I do use emojipedia.org quite often, so I must admit I find this would be quite useful :D. But the thought of having a framework like React powering this behind the scenes, right on my freaking terminal, makes me think that there's no hope for future generations to keep software development simple, "lean" for the foreseeable future. Imagine using 100MB to search for emojis.
- vanjajaja1 4y agocool app, I guess my take is: if the terminal renders react, is my terminal a web browser?. Should I be doing my search in a webbrowser instead? If that's not convenient, why is it not convenient? Should the webbrowser experience be fixed instead of bolting webbrowsing in the terminal? and yeah i'm aware of lynx maybe there's some sort of midground where an app is both a display thing and a terminal thing. not sure, but feels like it needs exploring
- deleted 4y ago[deleted]
- nitwit005 4y agoIt's sort of impressive, but feels like it'd take more time to figure out than to make your app work using the "raw" nodejs tty and readline APIs.
- lost_tourist 4y ago
- newah1 4y agovery cool, I'll remember this for my next project in the CLI
- tommy_axle 4y agoI'll need to try Ink but you were also able to do this with react + blessed via https://github.com/Yomguithereal/react-blessed https://github.com/Yomguithereal/react-blessed
- dingosity 4y agokill it. kill it with fire. though to be fair, ncurses isn't a joy to work with.
- robertoandred 4y agoWhy kill it? What's wrong with CLI interfaces?
- retrocryptid 4y agoThere's nothing wrong with CLIs. Emulating the idiocy of HTML in the terminal window is... suboptimal. (n)curses isn't great, but the joy of ncurses is it's so bad you know you need to replace it (or more likely layer something on top of it.)
- robertoandred 4y agoReact isn't HTML.
- lwansbrough 4y agoHoly semantics. JSX is based on XML, which HTML is also based on. I think GP just hates React and JSX, which is valid.
- zokier 4y agoHtml is not really based on xml, historically its more like the other way around, xml was inspired by html(/sgml). Xhtml was distinct dead-end evolutionary branch
- retrocryptid 4y agoIt is true I do not care for xml, html, xhtml or sgml. And the one thing that was decent about sgml, dsssl, we threw away. I do not care for the box model of HTML and would prefer for a segmented flow model so I can easily reason about pages as being... well... pages. I have no problem with declarative layout or semantic documents, but dislike frameworks that conflate the two. But... clearly... if you like react on HTML and want to have browser-like rendering of text on your terminal than more power to you. I'll go off now and build something that demonstrates my concerns. Thx for not severely down-voting my comment before I could begin to clarify...
- toppy 4y agoFor Golang there is Bubbletea [1], Textual [2] for Python and tui-rs for Rust [3]. [1] https://github.com/charmbracelet/bubbletea https://github.com/charmbracelet/bubbletea [2] https://github.com/textualize/textual https://github.com/textualize/textual [3] https://github.com/fdehau/tui-rs https://github.com/fdehau/tui-rs
- glenngillen 4y agoThere’s also r3bl for Rust: https://crates.io/crates/r3bl_rs_utils https://crates.io/crates/r3bl_rs_utils
- fbdab103 4y agoIs tui-rs actively maintained? Currently 52 outstanding pull requests and last commit was ~9 months ago.
- azemetre 4y agoIt has been forked and actively maintained on [1] ratatui crate. You can see this discussion post about it [2]. [1] https://github.com/tui-rs-revival/ratatui https://github.com/tui-rs-revival/ratatui [2] https://github.com/fdehau/tui-rs/issues/654 https://github.com/fdehau/tui-rs/issues/654
- EddieRingle 4y agoThere's also Mosaic, which is an experiment of sorts to build console UI using Kotlin and Jetpack Compose: https://github.com/JakeWharton/mosaic https://github.com/JakeWharton/mosaic
- kelseyfrog 4y agoYoga is a great choice for layout here. In my own terminal-based projects, I was initially worried that there would be a mismatch between its intended use (pixel-based layout) and the chunkiness of character-based layout in terminal apps, but I was happily proven wrong. Yoga is a great choice for laying out terminal apps. I wish there was as nice a library for cascading style sheets in terminal apps, but we can't have it all.
- blooalien 4y ago> I wish there was as nice a library for cascading style sheets in terminal apps, but we can't have it all. In Python we have Will McGugan's "Textual" framework which supports a form of CSS designed specifically for terminal apps.
- lrobinovitch 4y agoSimilarly there is Lipgloss for the Go ecosystem
- blooalien 4y agoAh, yes … from the `charm.sh` people. They have some nice tools, those folks…
- nicoburns 4y agoThere is also Rink, a Rust port of Ink that uses Dioxus instead of React for the high-level API https://github.com/DioxusLabs/dioxus/tree/master/packages/rink https://github.com/DioxusLabs/dioxus/tree/master/packages/ri...
- WorldMaker 4y agoIt might be interesting to see less Flexbox and more CSS Grid support. I think that would make certain styles of TUIs like the Midnight Commander style apps easier to build.
- nicoburns 4y agoI maintain a library (https://github.com/DioxusLabs/taffy https://github.com/DioxusLabs/taffy) that implements both Flexbox and CSS Grid and is designed to be easily embedded (similar to Yoga, which Ink is using), if anyone wants add CSS Grid support to their app/framework.
- DLA 4y agoJust what I was looking for, 1000+ JS dependencies and Yoga's deps to make a CLI app. Nope. Hard pass. But, I do love the concept of components for CLIs. I've had much success with the Charm set of tools for CLIs with Go (https://charm.sh https://charm.sh).
- evan_ 4y ago> Yoga's deps ah yes, all zero of them https://www.npmjs.com/package/yoga-wasm-web?activeTab=dependencies https://www.npmjs.com/package/yoga-wasm-web?activeTab=depend...
- shane_b 4y agothis is very good library that i was a little nervous about at first but i used it to build a custom command line tool for my business and it’s helped so much. it’s also very easy to create fancy cli features that make it feel like a real application.
- bilalq 4y agoThe same tired, disparaging comments for anything done in JS get pretty annoying. No, there are not 1000+ dependencies. The entire transitive closure with dev dependencies comes down to 42 dependencies total. Is that a lot? Maybe, but there is value here. As someone who's authored many CLI tools in the past, libraries like oclif, ink, inquirer, etc were game changers. A little overhead for UX rendering is not material to the performance for many CLI tools. The actual byte streaming/processing and any network calls dwarf the handful of milliseconds you could save by rendering in some more "optimized" way. Being able to render visualizations, handle user input interactions, and responsively re-render are very useful things.
- deleted 4y ago[deleted]
- Brendinooo 4y agoI used this a couple of years ago to build a little CLI tool to monitor a subreddit that people use to sell a commodity. It was fun to work with!
- travisd 4y agoCurious to know -- how do these kinds of things affect accessibility for visually impaired people? If you're using a screenreader, do these kinds of things work?
- MuffinFlavored 4y agoIs there really a good reason in 2023 to have an interactive command line app? I've seen apps that at least maybe display a web server on localhost and then interact with it through the browser Or Electron, etc. I feel like command-line is alienating (deliberately, obviously) a huge portion of potential users. It basically guarantees whatever you made will only get used by tinkerers and not anybody serious (like if I have to pass a proof of concept pet project along to my manager, terminal might make it a non-starter 85% of the time)
- graypegg 4y agoYes definitely. Being able to easily access them via a remote shell is a killer feature IMO. Being able to pipe + automate is useful too if used non-interactively.
- MuffinFlavored 4y ago> Being able to easily access them via a remote shell is a killer feature IMO You mean like being able to access a web page?
- graypegg 4y agoHah, that is a fair point.
- wolletd 4y agoI have systems that have no web server and don't need one and adding one would add complexity and potential security risks to the system. Administration is only done via SSH. There are just situations where the question goes the other way around: Is there any need for _more_ than a command line interface? No. Anyone competent enough to do anything meaningful on that server is also capable of doing it via command line.
- MuffinFlavored 4y agoI don't disagree with you, I'm just devil's advocating/showing an alternative viewpoint: > Is there any need for _more_ than a command line interface? Reworded: is there any need to make this harder to access than the equivalent of: * kube-forwarder + open Chrome to http://localhost:3000 http://localhost:3000 * ssh -L ... * ngrok ...
- jacobp100 4y agoVery glad to see gap support added. I was playing around with a fork to add it, but didn’t get much time to polish it up
- aloer 4y agoI recently used Ink to build a small debugging CLI for a websocket-heavy project of mine. All it does is subscribe to a specific channel and print out the message or send dummy data when I press a specific button. The frontend websocket code could be reused easily so it was very fast to do. Very convenient to run multiple terminals as multiple clients in parallel. Much nicer at least than something like Postman for Websocket tests. Full screen took some time to get right and still flickers when using iterm 2. But it does work on the apple terminal and for now I am happy with that. My only issue is that Ink does not support nested rendering / overlays, i.e. modals.
- latchkey 4y ago> I recently used Ink to build a small debugging CLI for a websocket-heavy project of mine. why not just write tests? i'm getting super down voted on this, but come on... why? this person built some buggy utility and those bugs can end up causing more problems than just writing tests in the first place. no wonder we end up with such buggy junk software... people... write tests!
- ajkjk 4y agothat's not what they wanted to do?
- aobdev 4y agoAutomated testing and debugging are not the same
- latchkey 4y agoI didn't say anything about automated. 99% of the time, I debug using tests. You write the expected output and then fill in the implementation. If you don't get what you expect, something is wrong with your code and it is easy to run it in the debugger to figure out what is wrong. At the end of that, you end up with a test and some code that works. Other people call this TDD.
- 4y ago
- h1fra 4y agoEverytime I see this project I'm flabbergasted (in a very good way) that we can achieve this. I wish Node was portable, it would definitely be far more superior than GO CLIs that lacks this kind of features.
- mofle 4y agoNode.js now supports generating self-contained binaries: https://nodejs.org/api/single-executable-applications.html https://nodejs.org/api/single-executable-applications.html
- h1fra 4y agooh wow, amazing news. Still experimental, but very exciting! thanks for sharing
- garfij 4y agoA sibling comment points at https://github.com/charmbracelet/bubbletea https://github.com/charmbracelet/bubbletea as a Go alternative with a similar architecture
- dang 4y agoRelated: Ink: React for interactive command-line apps - https://news.ycombinator.com/item?id=14831961 https://news.ycombinator.com/item?id=14831961 - July 2017 (42 comments)
- gofreddygo 4y ago"Ink" and "interactive" in the same sentence has a strong association in my mind for Inkle's Ink [1] [1]: https://www.inklestudios.com/ink/ https://www.inklestudios.com/ink/
- pimlottc 4y agoThis was my immediate first thought as well, I thought it was perhaps a React-based implementation of this existing product.
- koromak 4y agoWow, those are some big names. Never heard of this before, very cool.
- Shorel 4y agoWhy would it be called Ink if it doesn't recognize my laptop's pen? It makes no sense, just more search engine noise. FYI: I use the pen with a gnome app called Write, in Ubuntu 22.04.
- thiht 4y agoIt’s like how Firefox doesn’t have anything to do with foxes or fire, wtf
- Shorel 4y agoThere are no other software products called Firefox (right now). Foxes are not software. There is Microsoft Windows Ink which does handwriting recognition. Think about namespaces, in the software namespace, Ink is a loaded term, and most of its use has nothing to do with command-line apps. This is far closer to a Rust implementation of the readline library. Again, nothing to do with pen recognition software, which is the common use of Ink. Just look at this list: https://apps.microsoft.com/store/search/Ink https://apps.microsoft.com/store/search/Ink
- thiht 4y agoYou're intentionally looking for confusion when there is none. They called it Ink because they considered the terminal is a canvas where you draw stuff. That's it. There's no way anyone will ever confuse a CLI rendering lib with an OCR or a vector graphics editor or whatever.
- bweitzman 4y agoPretty neat. I adapted the state management of hooks to Haskell a few years ago. Could be used for similar purposes, but there's no support for templating or styling yet: https://github.com/benweitzman/hooks https://github.com/benweitzman/hooks
- pranshuchittora 4y agoGlad to see this lib on #1. I have built a CLI tool called Autarky a long long time back https://github.com/pranshuchittora/autarky https://github.com/pranshuchittora/autarky. Ink is great to get bare minimums up and running, but the capabilities are quite limited and you can't build full blown interactive dashboards with this like HTOP etc.
- beebeepka 4y agoI guess I am not a visionary because this makes zero sense to me. I guess anything react related receives points simply for existing
- FpUser 4y agoGive it another 30 years and they will "invent" Turbo Vision
- 1letterunixname 4y agoAnd then ObjectVision, OWL, and OWLNext. Just don't forget curses or whiptail. The promises of "easy" and "features" where they don't belong, like using JS and CSS in TUIs is tech debt, security concerns, and resource waste waiting to happen. Picking on a convenient victim, say Rust, it has: cursive, tuikit, ratatui, and termion that make for powerful, safe, performant, and maintainable code. It's always cute when absurd things are made possible, but some ideas are impractical for anything beyond toys. If you want toys, sure, do anything and go nuts with it.
- enricozb 4y agoI tried (and sort of failed) to build something like this for rust [0] (warning it's broken at the moment). It's a lot harder than I expected. Especially since the terminal has no notion of focus, and with Rust it's really hard to not just clone everything you get your hands on when writing a UI library. The borrow checker really feels like it gets in the way of features like signals [1], and partial re-renders. [0]: https://docs.rs/intuitive/latest/intuitive/ https://docs.rs/intuitive/latest/intuitive/ [1]: https://preactjs.com/guide/v10/signals/ https://preactjs.com/guide/v10/signals/
- paxys 4y agoThis looks amazing. Can anyone talk about the added overhead of this? I'm assuming having to bundle all of Node.js/V8 in your executable is one of them. Plus extra processing to re-render the tree for changes. I'm wondering if this is worth it to use for very simple CLI scenarios that can be addressed by more lightweight libraries like Cobra. Maybe so your client-side business logic can stay more unified? It's also really funny to me that what is considered the absolute simplest use case in programming – write a program that outputs a line of text to the console – is still not free from the Node/npm/React experience.
- paulddraper 4y ago> write a program that outputs a line of text to the console Stating the obvious, but if you are outputting a line of text to the console, don't use this.
- paxys 4y agoWhy is that obvious? That was exactly my question. For example using React to generate a simple "hello, world" style website is overkill but not totally unthinkable. Is it worse for the CLI case?
- paulddraper 4y agoNot unthinkable, but equally dumb. <!doctype HTML><html><body>Hello World</body></html> console.log("Hello World") This is for interactive CLI.
- pzmarzly 4y ago> I'm assuming having to bundle all of Node.js/V8 in your executable is one of them I guess you could expect Linux distros to come with Node (though it's probably a quite dated release). Looking at standalone binaries, both bun.sh and Node.js are about 30MB. In comparison, Python 3.10 is 9MB and starts slower than bun but faster than Node. Bundling is easy too, you can take a loot at vercel/pkg https://github.com/vercel/pkg https://github.com/vercel/pkg
- swarfield 4y agoIt's really cool, I've used it before and it's super easy.
- thih9 4y agoHow does it deal with more complex refresh actions? E.g., the online jest demo blinks a lot [1]; is that expected? Are there workarounds? [1]: https://replit.com/@vadimdemedes/ink-jest-demo https://replit.com/@vadimdemedes/ink-jest-demo (tested in safari mobile)
- wstone 4y agoI love Ink. Made a game with it: https://www.npmjs.com/package/5dice https://www.npmjs.com/package/5dice
- seanp2k2 4y agoBack in my day, we had curses and we liked it.
- xrd 4y agoI tried this a long time ago when I was in love with react. It felt difficult to wrap my head around the yoga layout engine. I'm glad others here in this thread seem to like yoga, but I didn't. And, now I really dislike react for various reasons. I would use this if I needed to write a command line app with nodejs: https://github.com/chjj/blessed https://github.com/chjj/blessed
- lucideer 4y agoAlas https://github.com/chjj/blessed/issues/418#issuecomment-1533316110 https://github.com/chjj/blessed/issues/418#issuecomment-1533... I considered blessed for a recent project, but ended up just simplifying the approach & making do with Inquirer + Meow instead due to the maintenance status. Haven't found anything else equivalent to blessed, other than Ink.
- xrd 4y agoDoh. That's not good. Bummer. Can you link to those other projects you used? I'm not familiar. It would be awesome if you had a write-up
- tbeseda 4y agomeow for argument processing and other niceties https://github.com/sindresorhus/meow https://github.com/sindresorhus/meow inquirer for interactivity/input (select, text, boolean, etc) https://github.com/SBoudrias/Inquirer.js https://github.com/SBoudrias/Inquirer.js
- timetraveller26 4y agooh god, why? just kidding, this seems interesting. Something like this with vue should be possible right?
- bilalq 4y agoHas anyone ever gotten ink to work with OCLIF and TypeScript? I never could figure out how to get those to play nice together. It's ESM only, and that makes things so much harder. The ESM transition has by far been the biggest pain point of working with JS/TS these last few years. EDIT: Got it working. Was still a lot more painful than I wish it was. Definitely not converting anything else to use ESM until the landscape here improves.
- brianguertin 4y agoA similar project is Mosaic. It's exactly the same concept, but for Jetpack Compose, the primary toolkit used in modern Android apps. You can use it in desktop JVM apps written in Kotlin. https://github.com/JakeWharton/mosaic https://github.com/JakeWharton/mosaic
- squirtlebonflow 4y agoCan I use this in a website to make a terminal embedded into the site? Basically I mainly want to use the styles
- koito17 4y agoInk is amazing for quickly hacking together TUIs. I recently did so with Nbb (Node Babashka) and and enjoyed the experience overall. My only real complaint is how everything in your VDOM seems to re-render on a state change. IIRC this is being addressed [1], but is something to be mindful of, especially if your users may be using slow machines. [1] https://github.com/vadimdemedes/ink/issues/21 https://github.com/vadimdemedes/ink/issues/21
- dutzi 4y ago~2 years ago I used it to create a dashboard (a fancy table) that renders some data it fetches sporadically from the web. It was a lot of fun to make and stylize, but felt slower than it should. I guess it was the “layout stage” (IIRC lots of h/v-boxes). It was 2 years ago and seems like it’s been well maintained, so maybe they sorted those things out.
- vaughan 4y agoI had the idea recently to unify all the rendering code for my cli apps and thought this might be a good approach - I also wanted to allow cli app output to be rendered in the browser. It wasn't. I guess it might be good for dynamic apps, but I just love having control over exactly what I a printing out. I'm still looking for a way to write cli apps that also can be accessed from a browser. I always find myself wanting better log viewing functionality - like folding, grouping, search, etc. But there is something so nice about the terminal vs gui. I always avoid gui because the toolchain is horrific and then you have to think about the API layers and everything becomes overly complex and slow.
- in9 4y agoI get that such tool needs to exist. In this thread there are a bunch of use cases. But node feels like it shouldn't be used for CLIs (generic ones, i.e. not tied to a specific language and use case). Every time I see a tool that seems usefull its a hassle to install the correct node environment for it to work.