Skip to main content

Preview

preview is a tool for "previewing" files that require a compilatoin step, like LaTeX, Markdown, and more. It works by managing a "build" step and a "view" step, so it can be used to live-preview many different types of files, and if you filetype is not already supported, it is simple to add support for it.

Usage

Install with pip

$ pip install filepreviewer

to preview a file, just pass it to the preview command

$ preview file_to_preview.md

How it works

preview uses a handler to launch a view process in the background, and then run build process when the source file is changed. For example, the just handler can use a justfile like this

PREVIEW_INPUT_FILE := ""
PREVIEW_TMPDIR:= ""

preview-build:
    pandoc {{PREVIEW_INPUT_FILE}} -o {{PREVIEW_TMPDIR}}/out.pdf

preview-view:
    zathura {{PREVIEW_TMPDIR}}/out.pdf

to preview Markdown files by compiling them to a PDF (using Pandoc) and opening then PDF with Zathura, which does automatic reload.

You can use any tool(s) you want to build and view your file. The only requirement is that view process should block. preview will launch it in the background and exit when it returns.

Examples

To preview a Gnuplot script you could use sexpect to open gnuplot and load the script.

PREVIEW_INPUT_FILE := ""
PREVIEW_TMPDIR:= ""

preview-build:
    #! /bin/bash
    if [[ -e preview-gnuplot.sock ]]
    then
      sexpect -sock preview-gnuplot.sock send 'load "{{PREVIEW_INPUT_FILE}}"' -cr
      sexpect -sock preview-gnuplot.sock expect
    fi

preview-view:
    sexpect -sock preview-gnuplot.sock spawn gnuplot
    just --justfile {{justfile()}} PREVIEW_INPUT_FILE={{PREVIEW_INPUT_FILE}} PREVIEW_TMPDIR={{PREVIEW_TMPDIR}} preview-build
    zenity --info --no-markup --text="Click 'OK' when you are done to close the preview."
    sexpect -sock preview-gnuplot.sock send 'exit' -cr
    sexpect -sock preview-gnuplot.sock wait

The use of Zenity here is required to keep the view process from returning immediatly, which would cause preview to terminate.

Handlers

Currently, Preview supports just and Make for handing the build and view steps.

Just handler

To use the just handler, create a file named justfile.<file_extension> that defines a preview-build and preview-view recipe, as well as two variables named PREVIEW_INPUT_FILE and PREVIEW_TMPDIR. Preview will pass the name of the file being previewed, and the path to a temporary directory that is created for the hander to use.

Make handler

To use the make handler, create a file named makefile.<file_extension> that defines the preview-build and preview-view targets. Preview will set two variables named PREVIEW_INPUT_FILE and PREVIEW_TMPDIR that contain the name of the file being previewed, and the path to a temporary directory that is created for the hander to use.

Metadata

Release files for filepreviewer 4.0

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

Source distribution (sdist)

Source distribution for filepreviewer 4.0
File Size Uploaded
filepreviewer-4.0.tar.gz 5.0 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for filepreviewer 4.0
File Interpreter ABI Platform
filepreviewer-4.0-py3-none-any.whl Python 3 none any Details

Total release size: 11.6 kB

Release files / filepreviewer-4.0.tar.gz

Download URL filepreviewer-4.0.tar.gz
Size 5.0 kB
Tags Source
SHA-256 checksum
How to use checksums
85c2afc92b387c16c3ff3d362be50bf5f41381c2c3a3db62dea0824e14af3e4d
BLAKE2b-256 checksum
How to use checksums
4a3296e15dadab8adf702241eb81429893584ac931b0ac1afa461b03c3f89c14
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via poetry/1.4.1 CPython/3.10.6 Linux/5.19.0-32-generic

Release files / filepreviewer-4.0-py3-none-any.whl

Download URL filepreviewer-4.0-py3-none-any.whl
Size 6.5 kB
Tags Python 3
SHA-256 checksum
How to use checksums
937c9cb4e0360e1354e172d6af11060f441e7a951a1251067af385c62a13422c
BLAKE2b-256 checksum
How to use checksums
a4587013e57e94079d1102c2cd9996430637424bbf7f827d5ef06d7a71cf9c7e
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via poetry/1.4.1 CPython/3.10.6 Linux/5.19.0-32-generic

Release history Release notifications | RSS feed

This release

4.0 This release

2 release files

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