TE
TechEcho
Home24h TopNewestBestAskShowJobs
GitHubTwitter
Home

TechEcho

A tech news platform built with Next.js, providing global tech news and discussions.

GitHubTwitter

Home

HomeNewestBestAskShowJobs

Resources

HackerNews APIOriginal HackerNewsNext.js

© 2025 TechEcho. All rights reserved.

How does apt render its fancy progress bar?

516 pointsby julienpalardover 3 years ago

17 comments

yakubinover 3 years ago
APT&#x27;s progress bar does have issues though. When you shrink the terminal when the progress bar is visible, you&#x27;re going to have gibberish in the terminal. That&#x27;s because the terminal commands to move the cursor by lines work on visual lines, not semantic lines, so they aren&#x27;t invariant under the operation of resizing the terminal window. That&#x27;s a really rough area of Linux terminals: when you resize a window, the terminal is going to rewrap the lines according to semantic lines (based on line feed characters), so it&#x27;s clear that all major terminals understand this distinction, but the terminal API doesn&#x27;t give applications access to moving by semantic lines, so we&#x27;re left with bugs like these.<p>I think PowerShell has the concept of progress reporting specially recognized? That sounds like a good idea. It could be used to render a GUI progress bar and leave the pipeline alone, for the objects. That&#x27;s just my vague idea, since I didn&#x27;t spend much time with PowerShell.
评论 #28854175 未加载
评论 #28854369 未加载
评论 #28854849 未加载
评论 #28857755 未加载
评论 #28854745 未加载
gildasover 3 years ago
For those who wonder how these &quot;\033[1A...&quot; notations are specified, look up &quot;ANSI escape code&quot; on the net, e.g. <a href="https:&#x2F;&#x2F;en.wikipedia.org&#x2F;wiki&#x2F;ANSI_escape_code" rel="nofollow">https:&#x2F;&#x2F;en.wikipedia.org&#x2F;wiki&#x2F;ANSI_escape_code</a>
评论 #28850906 未加载
评论 #28851086 未加载
评论 #28854056 未加载
评论 #28850991 未加载
zorrover 3 years ago
It&#x27;s good to know the underlying low-level terminal commands that make this work like this article explains. But I guess most people will use a terminal abstraction library that has a higher level API to move the cursor, clean the screen etc.<p>Terminals are complex beasts and they can do powerful things. If you&#x27;re interested in this, I can recommend reading the source code for Tmux, JLine3 and some other libraries shell formatting or TUI libraries.
评论 #28850421 未加载
评论 #28850638 未加载
评论 #28850444 未加载
miki123211over 3 years ago
This kind of fancy terminal manipulation is usually an accessibility nightmare.<p>Real GUI frameworks usually provide semantic information to the OS, which allows screen readers to determine that a given control is a progress bar that is 50% filled, and then render that information by playing an appropriately-pitched tone. In a TUI, all they get is a line of fancy symbols changing quickly, with no context as to what those symbols mean. Same for i.e. ncurses based menus. When programs use colors to signify which menu option is selected, screen readers usually get lost.<p>Screen readers specifically designed for text-based systems (such as DOS) usually had ways to work around this issue, but modern, GUI-focused ones don&#x27;t really offer those options any more.
评论 #28851228 未加载
评论 #28851239 未加载
评论 #28851215 未加载
评论 #28851226 未加载
评论 #28851205 未加载
评论 #28851601 未加载
评论 #28851891 未加载
评论 #28851354 未加载
fladdover 3 years ago
Nice. I also looked into this a while ago and came up with a very simplistic (few lines) Python implementation that does this and even allows for some customization: <a href="https:&#x2F;&#x2F;gist.github.com&#x2F;fladd&#x2F;36c422f1c0e9bf02f41f9fad19609d06" rel="nofollow">https:&#x2F;&#x2F;gist.github.com&#x2F;fladd&#x2F;36c422f1c0e9bf02f41f9fad19609d...</a>
评论 #28852645 未加载
评论 #28852535 未加载
brainbagover 3 years ago
Good explanation. It is a nice progress bar, but not particularly unique; many command line tools use progress bars like this.<p>I&#x27;ve always been curious how the Heroku CLI renders its progress bar, which is unique as far as I&#x27;ve seen. It does not seem to use characters, it&#x27;s seemingly a smooth, pixel-based fill like you&#x27;d get in a non-terminal app. Downloading a pg backup is the most common place I see it.
评论 #28851120 未加载
评论 #28851162 未加载
评论 #28853578 未加载
评论 #28851102 未加载
prajwalshettyover 3 years ago
I implemented something like this in bash. I called this status bar sort of implementation as &quot;message bar&quot; to show the ongoing status of the script on a reserved lines on bottom of the screen - I had to implement progress bar one for each task inline (and not on the bottom bar) - and constantly had to switch &quot;states&quot; to save&#x2F;restore the cursor positions on screen.<p>This message bar would also become a prompt and take in user inputs on certain events apart from being a static status bar - super useful for the use case.<p>Cursor positions, scrolling screens, events, progress bar updates, managing child sessions, handling screen resolution changes, taking user inputs...everything had to be catered for in this.<p>I thoroughly enjoyed developing this and still think it was a bit over the board for what I was developing at the time but I was sent on this path of constant learning so couldn&#x27;t look back - was worth it.<p>Here&#x27;s the project: <a href="https:&#x2F;&#x2F;github.com&#x2F;PrajwalSD&#x2F;runSAS" rel="nofollow">https:&#x2F;&#x2F;github.com&#x2F;PrajwalSD&#x2F;runSAS</a>
SavantIdiotover 3 years ago
I wouldn&#x27;t call it fancy: I can&#x27;t change the color so on light backgrounds I can&#x27;t read it. And I&#x27;ve seen certain error messages slice it in two.<p>I&#x27;d call it annoying.
Snetryover 3 years ago
Neat.<p>This is one of those things I always wondered about but never cared enough to actually go and look into myself
评论 #28852687 未加载
shmerlover 3 years ago
A lot of terminals support Unicode, so fancy can be actually fancy in such cases using block characters that produce smooth progress animation. I.e. using those from Left one eighth block to Full block.<p><a href="https:&#x2F;&#x2F;en.wikipedia.org&#x2F;wiki&#x2F;Block_Elements" rel="nofollow">https:&#x2F;&#x2F;en.wikipedia.org&#x2F;wiki&#x2F;Block_Elements</a><p>I once added such progress bar for lgogdownloader.
buserrorover 3 years ago
I use a similar approach in libmish [0], ie I &quot;reserve&quot; the bottom 2 rows, and output the scrolling text in the top parts. Pretty straightforward.<p>[0]: <a href="https:&#x2F;&#x2F;github.com&#x2F;buserror&#x2F;libmish" rel="nofollow">https:&#x2F;&#x2F;github.com&#x2F;buserror&#x2F;libmish</a>
jancsikaover 3 years ago
I&#x27;d prefer a &quot;Double Debian&quot; distro that does the following:<p>1. When I run an apt command, it goes ahead and runs an automated version of the command on a &quot;shadow&quot; apt on the same machine.<p>2. It measures the time it took to do that operation on the shadow apt.<p>3. By the time I respond &quot;y&quot; to the command, it uses the duration from step 2 to display a <i>time-based</i> progress bar that animates smoothly over said duration.<p>4. If the shadow apt command hasn&#x27;t finished by the time I respond &quot;y&quot; to the command, it brings up Ms. Pacman for me to play for a bit.<p>I bet I&#x27;d be a much more satisfied user!
评论 #28856115 未加载
mike_hockover 3 years ago
&gt; std::cout &lt;&lt; ... &lt;&lt; std::to_string(nr_rows - 1)<p>&gt; to_string<p>What if I told you, iostream can output numbers?
agumonkeyover 3 years ago
terminal rendering is fun. it&#x27;s often limited but the few it offers gets you going nicely.
WayToDoorover 3 years ago
Nitpick about the website, but please don&#x27;t use PGP short fingerprints like 0x46EBCD72F08E6717. They can be brute forced [0] very fast to get a different private key with the same fingerprint. You can also use them to generate keys with vanity fingerprints, which is pretty funny [1].<p>[0] <a href="https:&#x2F;&#x2F;github.com&#x2F;lachesis&#x2F;scallion" rel="nofollow">https:&#x2F;&#x2F;github.com&#x2F;lachesis&#x2F;scallion</a> [1] I have 0xDE4444AAAAAAAAAA, took me 5 minutes of bruteforcing on a laptop.
评论 #28850683 未加载
评论 #28850470 未加载
评论 #28850663 未加载
croesover 3 years ago
Shouldn&#x27;t the title be without question mark or &quot;How does apt render it fancy progress bar?&quot;?
评论 #28850955 未加载
评论 #28850947 未加载
评论 #28850587 未加载
评论 #28853071 未加载
评论 #28850585 未加载
评论 #28850655 未加载
quotemstrover 3 years ago
I hate it when programs hardcore control sequences like this. Just look them up at runtime with terminfo --- it&#x27;s really not that hard.
评论 #28852965 未加载