Skip to main content

No project description provided

Project description

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.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

filepreviewer-4.0rc0.tar.gz (5.6 kB view details)

Uploaded Source

Built Distribution

filepreviewer-4.0rc0-py3-none-any.whl (6.5 kB view details)

Uploaded Python 3

File details

Details for the file filepreviewer-4.0rc0.tar.gz.

File metadata

  • Download URL: filepreviewer-4.0rc0.tar.gz
  • Upload date:
  • Size: 5.6 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.3.2 CPython/3.10.6 Linux/5.19.0-32-generic

File hashes

Hashes for filepreviewer-4.0rc0.tar.gz
Algorithm Hash digest
SHA256 5c2f482b2f1859cbef94275871a8fb5e38925ea726e5fe4c9cc5862a697d4d14
MD5 d9e7aa3fb6e393e022e1a50568ff7c60
BLAKE2b-256 5f5c9fa08a43e2e403c4bf8bf688f23ce1258454ee98c037183a6351e5828416

See more details on using hashes here.

File details

Details for the file filepreviewer-4.0rc0-py3-none-any.whl.

File metadata

  • Download URL: filepreviewer-4.0rc0-py3-none-any.whl
  • Upload date:
  • Size: 6.5 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.3.2 CPython/3.10.6 Linux/5.19.0-32-generic

File hashes

Hashes for filepreviewer-4.0rc0-py3-none-any.whl
Algorithm Hash digest
SHA256 12528bc44e4165fa114e96120efd07a9ad0027b32d764e0bb6ea2915c22f9f16
MD5 e958751e5b503905e3b3e3dee6291041
BLAKE2b-256 fdf03d3f80b9f5c5bf11be979767eabaf150043ef646bd80d4a56e2ae22ccdc2

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page