Skip to main content

How to Create a Two-Panel (Split Screen) Layout in Batch Script

Traditionally, a Batch script is a simple, scrolling waterfall of information. However, for administrative dashboards or monitoring tools, you might want a "Two-Panel" or "Split-Screen" layout. This allows you to show static metadata on one side (e.g., System Info) and a rolling log on the other side, or two distinct side-by-side lists.

In this guide, we will demonstrate how to create a two-panel layout using ANSI Escape Sequences to coordinate cursor movement across the screen.

The Strategy: Absolute Cursor Positioning

To achieve a split-screen look, we don't print everything at once. Instead, we:

  1. Clear the screen (cls).
  2. Generate the ESC character safely to enable ANSI cursor control.
  3. Position the cursor using ESC[Line;ColumnH (Home command) to jump to a specific coordinate.
  4. Print panels independently by jumping back and forth between columns on the same rows.

Implementation Script: A Simple Side-by-Side Dashboard

This script creates a "System Overview" on the left and a "Service Status" on the right. It uses layout constants so you can easily resize the panels.

@echo off
setlocal enabledelayedexpansion

:: 1. Robust ESC Character Generation (Bypasses AutoRun errors)
set "ESC="
for /f %%a in ('powershell -Command "[char]27" 2^>nul') do set "ESC=%%a"
if not defined ESC for /f "delims=" %%a in ('echo prompt $E ^| cmd 2^>nul') do set "ESC=%%a"

if not defined ESC (
echo [ERROR] ANSI Escape codes not supported.
pause & exit /b 1
)

:: Define Colors
set "C_CYAN=!ESC![96m"
set "C_GREEN=!ESC![92m"
set "C_RED=!ESC![91m"
set "C_YELLOW=!ESC![93m"
set "C_RESET=!ESC![0m"

:: Layout Constants
set "leftCol=3"
set "rightCol=44"
set "separatorCol=40"
set "headerRow=5"
set "dataStartRow=7"

cls
:: 2. Draw Dashboard Border and Header
<nul set /p "=!ESC![1;1H!C_CYAN!================================================================================!C_RESET!"
<nul set /p "=!ESC![2;1H ADMINISTRATIVE SYSTEM DASHBOARD"
<nul set /p "=!ESC![3;1H!C_CYAN!================================================================================!C_RESET!"

:: 3. Draw the vertical separator line
for /L %%i in (4, 1, 16) do (
<nul set /p "=!ESC![%%i;%separatorCol%H^|"
)

:: 4. Left Panel: System Information
<nul set /p "=!ESC![!headerRow!;%leftCol%H!C_CYAN![ SYSTEM INFO ]!C_RESET!"
<nul set /p "=!ESC![!dataStartRow!;%leftCol%HOS Name: Windows 10/11"
set /a "r=dataStartRow+1"
<nul set /p "=!ESC![!r!;%leftCol%HPC Name: !COMPUTERNAME!"
set /a "r+=1"
<nul set /p "=!ESC![!r!;%leftCol%HUser: !USERNAME!"
set /a "r+=1"
<nul set /p "=!ESC![!r!;%leftCol%HDrive C: !C_GREEN![########--] 80%%!C_RESET!"

:: 5. Right Panel: Service Health
<nul set /p "=!ESC![!headerRow!;%rightCol%H!C_CYAN![ SERVICE STATUS ]!C_RESET!"
<nul set /p "=!ESC![!dataStartRow!;%rightCol%HActive Directory: !C_GREEN!RUNNING!C_RESET!"
set /a "r=dataStartRow+1"
<nul set /p "=!ESC![!r!;%rightCol%HSQL Server: !C_GREEN!ONLINE!C_RESET!"
set /a "r+=1"
<nul set /p "=!ESC![!r!;%rightCol%HWindows Update: !C_RED!STOPPED!C_RESET!"
set /a "r+=1"
<nul set /p "=!ESC![!r!;%rightCol%HBackup Agent: !C_YELLOW!IDLE!C_RESET!"

:: 6. Footer and Command Area
<nul set /p "=!ESC![18;1H!C_CYAN!================================================================================!C_RESET!"
<nul set /p "=!ESC![19;1H"
set "cmd="
set /p "cmd=Enter Admin Command: "

endlocal
echo Info: Command '!cmd!' received.
pause

Method 2: The Rolling "Live Log" Panel

A more practical layout involves keeping the left panel static while a loop updates the right panel with fresh data. This demonstrates the real power of split-screen, updating one area without disturbing the other.

@echo off
setlocal enabledelayedexpansion

:: Safe ESC generation
for /f %%a in ('powershell -Command "[char]27" 2^>nul') do set "ESC=%%a"

set "C_GREEN=!ESC![92m"
set "C_CYAN=!ESC![96m"
set "C_RESET=!ESC![0m"

set "rightCol=44"
set "logRow=7"

cls
:: Static UI Elements
<nul set /p "=!ESC![1;1H!C_CYAN!================================================================================!C_RESET!"
<nul set /p "=!ESC![2;1H LIVE SERVICE CLIMB MONITOR"
<nul set /p "=!ESC![3;1H!C_CYAN!================================================================================!C_RESET!"
for /L %%i in (4, 1, 16) do (<nul set /p "=!ESC![%%i;40H^|")

:: Static Left Content
<nul set /p "=!ESC![5;3H!C_CYAN![ SERVER CONTEXT ]!C_RESET!"
<nul set /p "=!ESC![7;3HHost: !COMPUTERNAME!"
<nul set /p "=!ESC![8;3HTime: !TIME:~0,8!"

:: Right Panel Header
<nul set /p "=!ESC![5;%rightCol%H!C_CYAN![ REAL-TIME UPDATES ]!C_RESET!"

:: Simulation Loop
for /L %%n in (1, 1, 6) do (
set /a "currentLine=logRow + %%n - 1"

:: Use ESC[K to clear only the right panel area before printing
<nul set /p "=!ESC![!currentLine!;%rightCol%H!ESC![K"
<nul set /p "=!ESC![!currentLine!;%rightCol%H!C_GREEN!Log [%%n]:!C_RESET! Service Integrity Check OK"

:: Sub-second precision delay using blackhole ping
ping 192.0.2.0 -n 1 -w 600 >nul
)

:: Move cursor to finish
<nul set /p "=!ESC![18;1H"
echo.
echo !C_GREEN![SUCCESS]!C_RESET! Monitoring session complete.
endlocal
pause

How It Works: ANSI Breakdown

  • !ESC![Row;ColH: This is the "Cursor Position" code. Row 1, Column 1 is the top-left corner of the terminal.
  • !ESC![K: This is the "Erase in Line" code. It clears all text from the current cursor position to the end of the line. This is crucial for updating a log entry without artifacts from a previous, longer string.
  • <nul set /p: The standard echo command appends a newline character, which pushes the entire screen down and breaks the layout. set /p redirected from nul allows us to print the ANSI command and the text while keeping the cursor exactly where we want it.

Best Practices

  1. Use Layout Constants: Store column numbers in variables like %leftCol%. If you want to make the left panel wider, you only need to change one number at the top of the script.
  2. Clear Row Buffers: When updating only one side of the screen, use ESC[K to ensure that any old text is wiped out before the new data is printed.
  3. Blackhole Ping: Use ping 192.0.2.0 -n 1 -w [ms] for delays. It is far more accurate than pinging 127.0.0.1 because the local system responds instantly.
  4. Error Level Checks: If your script relies heavily on ANSI, check if ESC was defined. This allows your script to fail gracefully on older systems rather than printing "garbage" characters.

Conclusion

The two-panel layout is a powerful way to organize information in a Batch environment. By moving away from a linear "river of text" and toward a structured, coordinate-based grid, you can create immersive and professional administrative tools that provide a high-level overview of complex systems on a single screen.