Skip to content

Conversation

@moheladwy
Copy link
Owner

Overview

This PR resolves issue #22 by improving xclip compatibility for terminal emulators on X11 systems. The fix addresses the two main clipboard compatibility issues identified in the issue:

  1. Removed strict type checking: Removed the -t text/plain flag from xclip commands that was causing compatibility issues with various terminal emulators
  2. Added Primary selection support: Extended clipboard functionality to support both Clipboard (Ctrl+V) and Primary (middle-click) selections

Problem Statement

Previously, OCR4Linux only copied extracted text to the Clipboard selection, which caused pasting to fail in many terminal emulators. Additionally, some terminals were picky about the MIME type targets provided by xclip, specifically the -t text/plain flag.

Solution

Modified the copy_to_x11_clipboard() function in OCR4Linux.sh to:

  • Copy to both Clipboard selection (Ctrl+V paste)
  • Copy to Primary selection (middle-click paste)
  • Remove the strict MIME type flag for better terminal compatibility

Changes Made

File: OCR4Linux.sh

# Before:
xclip -selection clipboard -t text/plain -i "$OCR4Linux_HOME/$TEXT_OUTPUT_FILE_NAME"

# After:
xclip -selection clipboard -i "$OCR4Linux_HOME/$TEXT_OUTPUT_FILE_NAME"
xclip -selection primary   -i "$OCR4Linux_HOME/$TEXT_OUTPUT_FILE_NAME"

File: OCR4Linux.py

  • Version bumped to 1.4.0

Testing

The fix ensures that:

  • ✅ Text can be pasted into terminal emulators using middle-click (Primary selection)
  • ✅ Text can be pasted into terminal emulators using Ctrl+V (Clipboard selection)
  • ✅ Compatibility improved across different terminal emulators
  • ✅ Extracted text can still be pasted into browsers and other applications

Benefits

  • Better terminal compatibility: Users can now paste OCR-extracted text into various terminal emulators
  • Support for middle-click paste: Aligns with standard Linux X11 clipboard behavior
  • Power user friendly: Addresses the needs of power users who rely on terminal workflows

Related Issue

Closes #22

Version Update

  • Version bumped from 1.3.0 to 1.4.0 to reflect the enhancement

Copilot AI review requested due to automatic review settings January 13, 2026 14:45
@coderabbitai
Copy link

coderabbitai bot commented Jan 13, 2026

Caution

Review failed

Failed to post review comments

📝 Walkthrough

Summary by CodeRabbit

  • New Features

    • Added enhanced logging throughout the application for better visibility into operations.
    • Improved clipboard handling to copy to both clipboard and primary selections.
  • Improvements

    • Version bumped to 1.4.0 across all components.
    • Enhanced setup process with user-facing status messages and configuration directory creation.
    • Better progress feedback during installation and setup workflows.

✏️ Tip: You can customize this high-level summary in your review settings.

Walkthrough

Version bump to 1.4.0 with enhanced logging for screenshot and clipboard operations in the main script, extended X11 clipboard handling to support both clipboard and primary selections via a new orchestrator function, and added user-facing status messages throughout the setup flow.

Changes

Cohort / File(s) Summary
Version updates
OCR4Linux.py, OCR4Linux.sh, setup.sh
Bumped version string from 1.3.0 to 1.4.0 across all major components
Clipboard and logging enhancements
OCR4Linux.sh
Introduced new run_copy_to_clipboard() orchestrator function; added per-step logging for screenshot capture (Wayland/X11), clipboard operations (Wayland/X11); extended X11 clipboard to copy to both clipboard and primary selections
Setup flow improvements
setup.sh
Added user-facing status messages and progress indicators in check_yay() and install_requirements(); added startup/completion banners and configuration setup steps for creating OCR4Linux config directory
Build configuration
.gitignore
Added ignore rule for VS Code AI instructions file (.github/instructions/codacy.instructions.md)

Sequence Diagram

sequenceDiagram
    participant User
    participant Script as OCR4Linux.sh
    participant SessionCheck as Session Detector
    participant Wayland as Wayland Clipboard<br/>(wl-copy)
    participant X11 as X11 Clipboard<br/>(xclip)
    participant FileSystem as File System
    
    User->>Script: Trigger OCR operation
    Script->>Script: Capture screenshot & run OCR
    Script->>Script: Log: "Copying text to clipboard"
    Script->>SessionCheck: Determine session type
    
    alt Wayland Session
        SessionCheck-->>Script: Wayland detected
        Script->>Wayland: wl-copy < text_file
        Script->>Script: Log: "Text copied to Wayland clipboard"
    else X11 Session
        SessionCheck-->>Script: X11 detected
        Script->>X11: xclip -selection clipboard
        Script->>Script: Log: "Copied to X11 clipboard"
        Script->>X11: xclip -selection primary
        Script->>Script: Log: "Copied to X11 primary selection"
    end
    
    Script->>FileSystem: Remove temporary text file
    Script->>Script: Log: "Cleanup complete"
    Script-->>User: Operation finished
Loading

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

Possibly related issues

Poem

🐰 With whiskers twitching in delight,
Clipboards now paste left and right!
Primary, clipboard, both now blessed,
Logs trace every hop and test.

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Title check ✅ Passed The title 'Improve xclip compatibility for terminal emulators' directly matches the main objective of the changeset: enhancing clipboard functionality for terminal compatibility on X11.
Description check ✅ Passed The description clearly explains the changes addressing issue #22, detailing the removal of the MIME type flag and addition of primary selection support, with code examples and testing confirmation.
Linked Issues check ✅ Passed The pull request successfully addresses all coding requirements from issue #22: removes the -t text/plain flag from xclip commands and adds support for both Clipboard and Primary selections by calling xclip twice.
Out of Scope Changes check ✅ Passed Additional changes include version bumps (1.3.0 to 1.4.0), extensive logging additions, and setup.sh enhancements for user feedback, which are reasonable supporting changes but not strictly required by issue #22.
Docstring Coverage ✅ Passed Docstring coverage is 100.00% which is sufficient. The required threshold is 80.00%.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing touches
  • 📝 Generate docstrings
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch enhance/xclip-compatibility-terminals

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@moheladwy moheladwy self-assigned this Jan 13, 2026
@moheladwy moheladwy added the documentation Improvements or additions to documentation label Jan 13, 2026
@moheladwy moheladwy added the enhancement New feature or request label Jan 13, 2026
@moheladwy moheladwy changed the title Improve xclip compatibility for terminal emulators (#22) Improve xclip compatibility for terminal emulators Jan 13, 2026
Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR improves xclip compatibility for terminal emulators on X11 systems by removing the strict MIME type flag and adding support for the Primary selection (middle-click paste) in addition to the Clipboard selection (Ctrl+V paste). The changes also include enhanced logging throughout the script and version updates across all relevant files.

Changes:

  • Removed -t text/plain flag from xclip commands to improve terminal emulator compatibility
  • Added Primary selection support for X11 clipboard operations (middle-click paste)
  • Enhanced logging messages in setup.sh and OCR4Linux.sh for better user feedback
  • Updated version from 1.3.0 to 1.4.0 across all three main files

Reviewed changes

Copilot reviewed 3 out of 4 changed files in this pull request and generated 1 comment.

File Description
OCR4Linux.sh Core fix: Modified copy_to_x11_clipboard() to remove MIME type flag and add Primary selection support; added logging statements throughout
OCR4Linux.py Version update to 1.4.0
setup.sh Version update to 1.4.0 and added informative echo statements for better user experience during setup
.gitignore Added entry to ignore VS Code AI rules file

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@moheladwy
Copy link
Owner Author

Hi @0xrego

this pr closes your issue successfully, I've tried the fix on Plasma (X11) with Kitty terminal and it's working great :)

let me know if you need anything else

@moheladwy moheladwy merged commit 03c3f0a into main Jan 13, 2026
13 checks passed
@moheladwy moheladwy deleted the enhance/xclip-compatibility-terminals branch January 14, 2026 14:48
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

documentation Improvements or additions to documentation enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Suggestion]: Improving xclip compatibility for Terminal emulators

2 participants