Skip to content
TheChatArchiveThe Chat Archive
Claudeclaude-3-5-sonnet-20241022· AnthropicHugging Face LMArena Human Preference 140K

how does some linux scripts update termial screen smoothly without flickering?

From a Chatbot Arena battleThe same person sent this prompt to two anonymous models at once. Compare it with o3-mini’s answer.
  1. User

    how does some linux scripts update termial screen smoothly without flickering?

  2. Claude Assistant

    Linux scripts can update the terminal screen smoothly without flickering using several techniques:

    1. Using ANSI escape codes:
    # Move cursor up
    echo -e "\033[1A"
    # Clear line
    echo -e "\033[K"
    # Move cursor to specific position
    echo -e "\033[<line>;<column>H"
    
    1. Using carriage return without newline:
    echo -ne "Progress: $progress\r"
    
    1. Using tput commands:
    # Clear screen
    tput clear
    # Move cursor
    tput cup $row $col
    # Save cursor position
    tput sc
    # Restore cursor position
    tput rc
    
    1. Example of a smooth progress bar:
    #!/bin/bash
    
    progress() {
        local width=50
        local progress=$1
        local done=$((progress*width/100))
        local remaining=$((width-done))
        
        printf "\r[%${done}s%${remaining}s] %d%%" "$(printf '#%.0s' {1..100})" "$(printf ' %.0s' {1..100})" "$progress"
    }
    
    for i in {0..100}; do
        progress $i
        sleep 0.1
    done
    echo
    
    1. Using \033[2J\033[H to clear screen and return cursor:
    clear_screen() {
        echo -e "\033[2J\033[H"
    }
    
    1. Buffering output:
    # Instead of multiple echo commands
    output=""
    output+="Line 1\n"
    output+="Line 2\n"
    output+="Line 3\n"
    echo -e "$output"
    

    Key principles:

    • Avoid printing newlines when updating the same line
    • Use carriage return (\r) to return to start of line
    • Buffer output when possible
    • Use ANSI escape codes or tput for cursor control
    • Clear only what needs to be cleared instead of whole screen

    These techniques help reduce screen flickering by minimizing the number of screen refreshes and controlling exactly what and where to update.

Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.

Identical first prompt