Skip to main content
                         ___    _________________   ______________  __
                        /   |  / ____/ ____/  _/ | / /  _/_  __/\ \/ /
                       / /| | / /_  / /_   / //  |/ // /  / /    \  / 
                      / ___ |/ __/ / __/ _/ // /|  // /  / /     / /  
                     /_/  |_/_/   /_/   /___/_/ |_/___/ /_/     /_/   

The ultimate, highly-aesthetic replacement for cat and bat.

Python Version License: MIT Code Style: Black


🚀 Overview

Affinity is a next-generation terminal tool designed for developers who want the rich viewing experience of modern IDEs (like VS Code) directly in their command line.

Say goodbye to plain text dumps. Affinity parses your code, wraps it in beautiful Unicode borders, syntax-highlights every token flawlessly, and visually connects logical code blocks using intelligent vertical scope guides.


Advanced Tools

Affinity is more than just a viewer. It is a fully composable toolkit:

  • affinity mirage: Launch the full-screen interactive IDE mode! Browse files, vim-edit inline, and cleanly copy code over SSH natively using our zero-artifact dual-buffer engine.
  • affinity watch script.py: Watches the file and instantly re-renders the syntax highlighting every time you save.
  • affinity diff old.py new.py: A stunning side-by-side/unified terminal diff viewer.
  • affinity run script.py: Executes the python script inline, presenting stdout and exit codes elegantly below the syntax-highlighted source.
  • Piping Support: Native stdin support means cat log.txt | affinity automatically syntax-highlights the piped stream!

✨ Spectacular Features

Feature Description
🎨 VS Code Scope Guides Intelligent vertical indentation guides that dynamically track scopes.
🌈 Syntax Highlighting Real-time, hierarchical token parsing powered by Pygments.
📦 Unicode UI Frames Beautiful frames that seamlessly resize to your terminal width without breaking.
🌲 Directory Viewer Automatically renders beautiful file trees when passed a directory instead of a file.
🎭 Theme Engine First-class support for Monokai, Dracula, One Dark, Nord, Solarized, and more.
🔍 Search Highlighting Find occurrences instantly within files via the --search flag.
🎯 Focus Mode Jump straight to the context you need with --line <num> highlighting.
⚡ Auto-Wrapping Long lines gracefully wrap to the next line keeping your UI boxed flawlessly.

💻 Installation

Affinity is officially published on PyPI and can be installed globally with a single command!

To install Affinity across your entire system, simply run:

pip install affinity-code-viewer

Install from Source

If you prefer to install from source without messing with system environments, clone this repository and run the startup script. It bypasses environment headaches and securely installs the package exclusively for your local user.

git clone https://github.com/your-username/affinity.git
cd affinity
./start.sh

Note: The script will automatically add ~/.local/bin to your PATH if it isn't already there!

Uninstallation

To cleanly wipe Affinity and all its artifacts from your system:

# Remove Affinity and clean up build artifacts
./remove.sh

🛠️ CLI Usage

Affinity was designed with an intuitive, human-first command-line interface.

# 📖 Basic File Viewing
affinity main.py

# 🌲 View an entire directory tree
affinity src/

# 🧛 Use a specific color theme
affinity main.py --theme dracula

# 🔍 Highlight search terms in the file
affinity config.yaml --search "database"

# 🎯 Highlight a specific line
affinity server.rs --line 145

# 🚫 Disable all formatting (acts like standard 'cat')
affinity data.txt --plain

# ℹ️ View all available CLI options
affinity --help

⚙️ Configuration

Tired of passing the --theme flag every time? Affinity supports permanent user configuration.

Simply create a file at ~/.config/affinity/config.toml:

# Default configuration
theme = "dracula"
line_numbers = true
wrap = true
scope_guides = true

🧬 Architecture

Affinity achieves its stunning visuals by bridging Pygments (for robust token lexing) and Rich (for terminal ANSI rendering).

Unlike standard bat, Affinity intercepts the token stream and injects calculated │ characters at precise indentation boundaries by reading mathematical spaces, ensuring that syntax colors (spans) are perfectly preserved even when slicing text arrays on the fly.


🤝 Contributing

We welcome contributions from developers across the globe!

  1. Fork the repository
  2. Create your feature branch (git checkout -b feature/AmazingFeature)
  3. Commit your changes (git commit -m 'Add some AmazingFeature')
  4. Push to the branch (git push origin feature/AmazingFeature)
  5. Open a Pull Request

❓ FAQ

Q: Does Affinity support binary files?
A: Yes! Affinity detects binary signatures automatically and gracefully prevents terminal garbage output.

Q: Why not just use bat?
A: bat is incredible, but Affinity goes a step further by natively rendering VS Code-like vertical indentation guides. This makes reading heavily nested Python or YAML files infinitely easier in the terminal.


Built with ❤️ for developers everywhere.

Metadata

Release files for affinity-code-viewer 0.1.5

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for affinity-code-viewer 0.1.5
File Size Uploaded Provenance
affinity_code_viewer-0.1.5.tar.gz 18.2 kB Without provenance Details

Built distribution (wheel)

Table of built distributions (wheels) for affinity-code-viewer 0.1.5
File Interpreter ABI Platform
affinity_code_viewer-0.1.5-py3-none-any.whl Python 3 none any Details

Total release size: 38.1 kB

Release files / affinity_code_viewer-0.1.5.tar.gz

Download URL affinity_code_viewer-0.1.5.tar.gz
Size 18.2 kB
Tags Source
SHA-256 checksum
How to use checksums
ebcc5a4a117b6cda47bf5535542f92b155fdc7ecc9f7f09a46abb57dcc01e07a
BLAKE2b-256 checksum
How to use checksums
256bf2cabda66f7443b4f35eb3036e8f9507c48597e599ef27d7d71dc9dd3778
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.13.14

Release files / affinity_code_viewer-0.1.5-py3-none-any.whl

Download URL affinity_code_viewer-0.1.5-py3-none-any.whl
Size 19.9 kB
Tags Python 3
SHA-256 checksum
How to use checksums
ca742c2924b0374bf15412e7fcf03eaa3821c0094523985f4fcd44c75291d602
BLAKE2b-256 checksum
How to use checksums
46b8a1975306695872d70e33e1bbd21567fd93ce7c940fcc2114b36a61828ddd
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.13.14

Security for affinity-code-viewer 0.1.5

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page