clearok - Linux


Overview

clearok is a Linux command used to enable curses applications to update the screen without having to use refresh after each character is written. It is commonly employed in terminal-based user interfaces (TUIs) and command-line applications.

Syntax

clearok [OPTION]

Options/Flags

  • -c or –config: Reads a configuration file (default: ~/.clearok.conf)
  • -e or –environment-vars: Sets environment variables for the configuration
  • -f or –frame-size=COLUMNS,ROWS: Sets a fixed frame size (default: terminal window size)
  • -h or –help: Displays help information
  • -m or –no-auto-refresh: Prevents automatic screen refresh
  • -p or –no-panel: Disables the use of a panel
  • -t or –timeout=SECONDS: Sets a timeout for the automatic refresh (default: 1)
  • -v or –version: Displays version information

Examples

Basic Usage:

To enable clearok for a simple curses application:

clearok

Using a Configuration File:

To create a configuration file with custom settings:

echo "no-auto-refresh = false" > ~/.clearok.conf

Controlling Screen Refresh:

To prevent automatic refresh and manually trigger it later:

clearok -m
... # After writing to the screen
clearok -f

Common Issues

  • Screen Not Refreshing:
    • Ensure that clearok is enabled using the -c option.
    • Verify that the terminal window is correctly interpreted as a curses terminal.
  • Cursor Jumping:
    • Set a fixed frame size using the -f option to prevent the cursor from jumping around.

Integration

With ncurses:

In ncurses applications, call clearok(curscr, TRUE) before entering the curses environment.

With Bash:

Use the expect command to trigger clearok when a specific pattern is displayed:

expect -c "spawn my_application
    expect \"Choose an option\"
    send \"1\r\"
    clearok -c
    interact"

Related Commands

  • curses: A library for creating TUIs
  • tput: A tool for terminal control
  • terminfo: A database of terminal capabilities