How does apt render its fancy progress bar?

# · 🔥 515 · 💬 158 · 13 days ago · mdk.fr · julienpalard
Today while running an apt full-upgrade I asked myself how apt does this nice progress bar stuck at the bottom line while still writing scrolling text. We needed no more with a coworker to try to reproduce it! While being very bored in the tube a few years back, I wrote a Headless VT100 emulator, so I remembered some things and had a few hints on how it could be done, so I started poking around with some Python code. I remembered a few instructions like DECSTBM to set the margins, and the various commands to move the cursor up and down so I started with this. After some trials-and-errors bottom margin reservation and log printing worked but the log were displayed on the line near the bottom margin, not where the command started: notice you can run an apt upgrade on the top of your terminal, it displays the progress bar at the bottom, but the logs will start from the top, as if there were no progress bar. And soon we realized it was the missing piece! Saving the cursor position to restore it later!! It soon started to look like an ugly undocumented, but almost working, ... thing?
How does apt render its fancy progress bar?



Archive | Send Feedback | WebAssembly Version (beta)