summary refs log tree commit diff stats
diff options
context:
space:
mode:
authortoonn <toonn@toonn.io>2019-12-30 19:40:38 +0100
committertoonn <toonn@toonn.io>2019-12-30 19:40:38 +0100
commitcd4a3723be57abddadfc8738dd91bc52d829155c (patch)
treef50a4f6e8975968dcc659a8f5bdda4735e208ab8
parent9a05536d17bd142a9c15d2e752eb94c9c9c00a4d (diff)
parent407ef979427579cd6fd4b1fa97fe9c5b0eb99ef0 (diff)
downloadranger-cd4a3723be57abddadfc8738dd91bc52d829155c.tar.gz
Merge branch 'sigboe-3dpreview'
-rw-r--r--README.md1
-rw-r--r--doc/ranger.pod11
-rwxr-xr-xranger/data/scope.sh30
3 files changed, 40 insertions, 2 deletions
diff --git a/README.md b/README.md
index bf1533a6..8134bc59 100644
--- a/README.md
+++ b/README.md
@@ -105,6 +105,7 @@ For enhanced file previews (with `scope.sh`):
 * `odt2txt` for OpenDocument text files (`odt`, `ods`, `odp` and `sxw`)
 * `python` or `jq` for JSON files
 * `fontimage` for font previews
+* `openscad` for 3D model previews (`stl`, `off`, `dxf`, `scad`, `csg`)
 
 Installing
 ----------
diff --git a/doc/ranger.pod b/doc/ranger.pod
index 911b6480..33b16b92 100644
--- a/doc/ranger.pod
+++ b/doc/ranger.pod
@@ -1974,6 +1974,17 @@ I<highlight> will pick up command line options specified in this variable. A
 C<--style=> option specified here will override C<HIGHLIGHT_STYLE>. Similarly,
 C<--replace-tabs=> will override C<HIGHLIGHT_TABWIDTH>.
 
+=item OPENSCAD_COLORSCHEME
+
+Specifies the colorscheme used by I<openscad> while previewing 3D models. Read
+I<openscad> man page for colorschemes. Ranger will default to Tomorrow Night.
+
+=item OPENSCAD_IMGSIZE
+
+Specifies the internal resolution I<openscad> will use for rendering 3D models.
+The image will be downscaled to fit the preview pane. This resolution will
+default to "1000,1000" if no value is set.
+
 =item XDG_CONFIG_HOME
 
 Specifies the directory for configuration files. Defaults to F<$HOME/.config>.
diff --git a/ranger/data/scope.sh b/ranger/data/scope.sh
index d4899597..ae09fe39 100755
--- a/ranger/data/scope.sh
+++ b/ranger/data/scope.sh
@@ -44,6 +44,8 @@ HIGHLIGHT_TABWIDTH=${HIGHLIGHT_TABWIDTH:-8}
 HIGHLIGHT_STYLE=${HIGHLIGHT_STYLE:-pablo}
 HIGHLIGHT_OPTIONS="--replace-tabs=${HIGHLIGHT_TABWIDTH} --style=${HIGHLIGHT_STYLE} ${HIGHLIGHT_OPTIONS:-}"
 PYGMENTIZE_STYLE=${PYGMENTIZE_STYLE:-autumn}
+OPENSCAD_IMGSIZE=${RNGR_OPENSCAD_IMGSIZE:-1000,1000}
+OPENSCAD_COLORSCHEME=${RNGR_OPENSCAD_COLORSCHEME:-Tomorrow Night}
 
 handle_extension() {
     case "${FILE_EXTENSION_LOWER}" in
@@ -65,8 +67,10 @@ handle_extension() {
         ## PDF
         pdf)
             ## Preview as text conversion
-            pdftotext -l 10 -nopgbrk -q -- "${FILE_PATH}" - | fmt -w "${PV_WIDTH}" && exit 5
-            mutool draw -F txt -i -- "${FILE_PATH}" 1-10 | fmt -w "${PV_WIDTH}" && exit 5
+            pdftotext -l 10 -nopgbrk -q -- "${FILE_PATH}" - | \
+              fmt -w "${PV_WIDTH}" && exit 5
+            mutool draw -F txt -i -- "${FILE_PATH}" 1-10 | \
+              fmt -w "${PV_WIDTH}" && exit 5
             exiftool "${FILE_PATH}" && exit 5
             exit 1;;
 
@@ -224,6 +228,28 @@ handle_image() {
         #     [ "$rar" ] || [ "$zip" ] && rm -- "${IMAGE_CACHE_PATH}"
         #     ;;
     esac
+
+    # openscad_image() {
+    #     TMPPNG="$(mktemp -t XXXXXX.png)"
+    #     openscad --colorscheme="${OPENSCAD_COLORSCHEME}" \
+    #         --imgsize="${OPENSCAD_IMGSIZE/x/,}" \
+    #         -o "${TMPPNG}" "${1}"
+    #     mv "${TMPPNG}" "${IMAGE_CACHE_PATH}"
+    # }
+
+    # case "${FILE_EXTENSION_LOWER}" in
+    #     ## 3D models
+    #     ## OpenSCAD only supports png image output, and ${IMAGE_CACHE_PATH}
+    #     ## is hardcoded as jpeg. So we make a tempfile.png and just
+    #     ## move/rename it to jpg. This works because image libraries are
+    #     ## smart enough to handle it.
+    #     csg|scad)
+    #         openscad_image "${FILE_PATH}" && exit 6
+    #         ;;
+    #     3mf|amf|dxf|off|stl)
+    #         openscad_image <(echo "import(\"${FILE_PATH}\");") && exit 6
+    #         ;;
+    # esac
 }
 
 handle_mime() {