Help us measure site usage?

With your permission, we use self-hosted analytics to understand page usage. It is optional and does not affect the Service. Learn more.

BashadvancedcliAI generated

Terminal System Monitor TUI

Build an interactive system monitor in pure Bash that fills the terminal with live panels, like a simple htop: CPU usage per core, memory and swap, disk usage per mount, network speed per interface, and the top processes. It reads the numbers straight from the Linux /proc filesystem, draws the panels with ANSI escape codes (moving the cursor and redrawing only what changed, so the screen doesn't flicker), switches views with single key presses, colors values green, yellow or red by thresholds, and adapts when the terminal is resized. You'll learn how Linux exposes system information in /proc, ANSI escape codes, reading keys without waiting for Enter, signal handling (SIGWINCH and exit), and structuring a larger Bash program.

Estimate
~12h
Steps
7
Completed by
0
Proposed by
codeseed.app

dialog · ANSI escape codes · /proc filesystem

Project roadmap

  1. 01

    Collect the data

    ~2.5h

    Write functions that read /proc: CPU usage per core from two readings of /proc/stat (the change in busy time divided by the change in total time), memory and swap from /proc/meminfo, disk usage from df, network bytes per interface from /proc/net/dev (turned into a rate from two readings), and the top processes by CPU from ps. Keep the previous readings in variables between refreshes. Done when: each function prints correct values compared with top and free.

  2. 02

    Draw the panel layout

    ~2h

    Use the alternate screen (tput smcup and rmcup) and hide the cursor. Compute panel positions from the terminal size (tput cols and lines), draw boxes with line characters, and write text at exact positions with cursor movement codes (\e[row;colH). Draw usage bars with █ characters. Always restore the terminal on exit with a trap. Done when: the panels are drawn neatly, and the terminal returns to normal after quitting.

  3. 03

    Refresh without flicker

    ~1.5h

    Build the main loop: refresh every N seconds (a -i option, default 2), redrawing only the values inside the panels (padding text to a fixed width to erase old characters) instead of clearing the screen. Build each frame in a variable and print it at once. Done when: the display updates smoothly without flicker.

  4. 04

    Add keyboard controls

    ~1.5h

    Read single key presses without blocking, using read -rsn1 -t with the refresh interval as the timeout, so the loop waits for either a key or the next refresh. Keys: 1 for the summary view, 2 for a detailed process view (sortable by CPU or memory with c and m), + and - to change the interval, and q to quit. Show the keys in a footer. Done when: every key works immediately.

  5. 05

    Color by thresholds

    ~1h

    Color values and bars green, yellow or red based on thresholds from a config file (for example CPU above 70% yellow and above 90% red), and add --no-color. Make sure colors reset after each value so they don't leak into other text. Done when: high values turn yellow and red at the configured thresholds.

  6. 06

    Handle resizing

    ~1.5h

    Trap SIGWINCH to recalculate the layout and redraw everything when the terminal is resized. When the terminal is too small, show a message asking to enlarge it instead of a broken layout. Done when: resizing the window redraws the panels correctly.

  7. 07

    Test it

    ~2h

    Make the data functions read from a configurable /proc path, and write bats-core tests with fixture files for /proc/stat, /proc/meminfo and /proc/net/dev checking the calculations (CPU percentages from two readings, network rates, and memory numbers). Run shellcheck. Done when: the tests pass, and shellcheck reports no warnings.

Ready to build this?

Get a GitHub repo and start building. Your AI reviewer checks each step as you go.

~12h · 7 steps

Tech stack

dialogANSI escape codes/proc filesystem