4 ms·
Show HN: ProgressLine – Track commands progress in a compact one-line format
A bit about me:
Originally, I'm an iOS developer, but over time, I became interested in CLI and DevEx, which ultimately led to the creation of my first CLI utility in Swift.
Project creation story:
I enjoy interactive and functional command-line interfaces with good UX, which often includes beautifully displaying the progress of ongoing operations. I wanted the ability to show a nice progress status for any command or script, but at the time, I couldn't find any solutions that suited my needs. Most community offerings are good libraries for specific programming languages. So, I decided this was the perfect moment to test my skills and Swift's capabilities in writing CLI utilities.
In my opinion, Swift did an excellent job (although it doesn't have as rich a set of relevant libraries as Rust, for example).
The main challenge turned out to be cross-platform support:
- Currently (Swift 5.10), Swift doesn't support full cross-compilation, making it impossible to build a Linux version on macOS. However, this capability will be available in Swift 6! This limitation forced me to use Docker, slightly complicating the release flow.
- Unlike macOS, Linux doesn't come with pre-installed Swift libraries (obviously), so they need to be embedded (statically linked) into the binary file, which significantly increases its size, even after stripping. I hope the strip process will become more efficient in the future.
Overall, I'm pleased with the result and would be thrilled if my small utility proves useful to others. :)
- nsjolj 2y ago[flagged]
- snthpy 2y agoInteresting. Does it do any parsing of the output to try and detect progress indicators like 70% or does it just display the elapsed time asking with the last line of output?
- kattouf 2y agoSorry if this is misleading: percentages are part of the standard log of the piped command (Swift compiler), you can see in the example on GitHub that without the utility, percentages are also present > does it just display the elapsed time asking with the last line of output so yeah, that's the behavior
- aargh_aargh 2y agoA related tool, except for monitoring I/O, is Progress [1]. Imagine that behind the scenes it does something like lsof every second (-m flag) and tracks the progress of any file open by the specified process(es) (-c or -a flags). Works great for copying and downloading, doesn't work for rewriting in-place. This reminds me that I wanted to modify my GNU Screen hardstatus to call it. [1] https://github.com/Xfennec/progress https://github.com/Xfennec/progress
- kattouf 2y agoThank you for sharing, it really does a good job (real progress tracking) that my solution doesn't cover, maybe it will be more suitable for someone. I'll try to use it myself too :thumbs-up:
- dolmen 2y agoSee also 'colout' to colorize a text stream. https://github.com/nojhan/colout https://github.com/nojhan/colout
- kattouf 2y agoThank you, I didn’t know about this tool, I’ll take it into service :thumbs-up:
- jiehong 2y agoA CLI written in swift? Nice! But it’s more of a timer than a progress line/bar as far as I understand.
- kattouf 2y agoYes, you’re right! But it was so difficult for me to come up with a fitting name that accurately reflects what it does (the classic computer science problem).
- teo_zero 2y agoI'm old-school: progressline() { local s=`ttysize w` local n=0 while read x; do for i in `seq $n`; do echo -ne "\e[2K\e[A" done echo -ne "\e[2K\r$x" n=$((${#x}/$s)) done echo }
- kattouf 2y agoNice! I would replace `ttysize w` with `tput cols` for use on macOS, and it works. However, for some reason, it erases too many lines when I tested it. Maybe something is going wrong with the "n" calculation. For test I used `ping google.com | progressline`
- teo_zero 2y agoYes, "n" calculation is approximate: it's just the number of chars divided by the terminal's width. No guarantees it works with UTF-8, escape sequences, or if the terminal get resized while it's running... Sorry, this is just a quick hack!
- kattouf 2y agoGot it, no need to sorry, this is a still cool example :thumbs-up:
- efilife 2y agoIt's standard, not standart
- kattouf 2y agoThanks for noticing!