viewinline 0.2.1__tar.gz → 0.2.2__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: viewinline
3
- Version: 0.2.1
3
+ Version: 0.2.2
4
4
  Summary: Quick look geospatial viewer for iTerm2 compatible terminals
5
5
  Project-URL: Homepage, https://github.com/nkeikon/viewinline
6
6
  Project-URL: Repository, https://github.com/nkeikon/viewinline
@@ -36,6 +36,11 @@ Description-Content-Type: text/markdown
36
36
  **Quick-look geospatial viewer for compatible terminals.**
37
37
  Displays rasters, vectors, and tabular data directly in the terminal with no GUI and no temporary files.
38
38
 
39
+ <p align="center">
40
+ <a href="viewinline_gif1.gif"><img src="viewinline_gif1.gif" width="49%"></a>
41
+ <a href="viewinline_gif2.gif"><img src="viewinline_gif2.gif" width="49%"></a>
42
+ </p>
43
+
39
44
  Think of it as `ls` for geospatial files — designed for quick visual inspection at the command line, not a replacement for QGIS, ArcGIS, or analytical workflows.
40
45
 
41
46
  Particularly useful on HPC systems and remote servers accessed via SSH. Images render on your local terminal without X11 forwarding, VNC, or file downloads.
@@ -101,6 +106,8 @@ The iTerm2 inline image protocol (OSC 1337) is supported by:
101
106
 
102
107
  **tmux/screen:** Inline images don't work inside tmux or screen sessions, even with `allow-passthrough on`. Use a plain terminal tab.
103
108
 
109
+ **Fallback:** In terminals that do not support inline images, you can fallback to ASCII art by installing [`chafa`](https://hpjansson.org/chafa/) command-line tool. Install `chafa` with your package manager (e.g. `brew install chafa` or `sudo apt install chafa`). You can also force the use of `chafa` by setting the environment variable `INLINE_VIEWER_ENGINE=chafa`.
110
+
104
111
  ## Features
105
112
  - Previews rasters, vectors, and tabular data directly in the terminal
106
113
  - Non-interactive: everything is controlled through command-line options
@@ -218,11 +225,7 @@ CSV and Parquet:
218
225
  ```
219
226
 
220
227
  ## Need help?
221
- You can ask questions about usage via the documentation-based assistant:
222
-
223
- 👉 [Ask the viewtif + viewgeom + viewinline Helper](https://chatgpt.com/g/g-698b61c42f788191b884aed1b99dfcd8-viewtif-viewgeom-viewinline-helper)
224
-
225
- 👉 For NASA staff: find 'viewtif + viewgeom + viewinline Helper' via the ChatGSFC Agent Marketplace
228
+ NASA staff can ask questions about usage via the documentation-based assistant 'viewtif + viewgeom + viewinline Helper' via the ChatGSFC Agent Marketplace.
226
229
 
227
230
  ## License
228
231
  This project is released under the Apache License 2.0 © 2026 Keiko Nomura.
@@ -6,6 +6,11 @@
6
6
  **Quick-look geospatial viewer for compatible terminals.**
7
7
  Displays rasters, vectors, and tabular data directly in the terminal with no GUI and no temporary files.
8
8
 
9
+ <p align="center">
10
+ <a href="viewinline_gif1.gif"><img src="viewinline_gif1.gif" width="49%"></a>
11
+ <a href="viewinline_gif2.gif"><img src="viewinline_gif2.gif" width="49%"></a>
12
+ </p>
13
+
9
14
  Think of it as `ls` for geospatial files — designed for quick visual inspection at the command line, not a replacement for QGIS, ArcGIS, or analytical workflows.
10
15
 
11
16
  Particularly useful on HPC systems and remote servers accessed via SSH. Images render on your local terminal without X11 forwarding, VNC, or file downloads.
@@ -71,6 +76,8 @@ The iTerm2 inline image protocol (OSC 1337) is supported by:
71
76
 
72
77
  **tmux/screen:** Inline images don't work inside tmux or screen sessions, even with `allow-passthrough on`. Use a plain terminal tab.
73
78
 
79
+ **Fallback:** In terminals that do not support inline images, you can fallback to ASCII art by installing [`chafa`](https://hpjansson.org/chafa/) command-line tool. Install `chafa` with your package manager (e.g. `brew install chafa` or `sudo apt install chafa`). You can also force the use of `chafa` by setting the environment variable `INLINE_VIEWER_ENGINE=chafa`.
80
+
74
81
  ## Features
75
82
  - Previews rasters, vectors, and tabular data directly in the terminal
76
83
  - Non-interactive: everything is controlled through command-line options
@@ -188,11 +195,7 @@ CSV and Parquet:
188
195
  ```
189
196
 
190
197
  ## Need help?
191
- You can ask questions about usage via the documentation-based assistant:
192
-
193
- 👉 [Ask the viewtif + viewgeom + viewinline Helper](https://chatgpt.com/g/g-698b61c42f788191b884aed1b99dfcd8-viewtif-viewgeom-viewinline-helper)
194
-
195
- 👉 For NASA staff: find 'viewtif + viewgeom + viewinline Helper' via the ChatGSFC Agent Marketplace
198
+ NASA staff can ask questions about usage via the documentation-based assistant 'viewtif + viewgeom + viewinline Helper' via the ChatGSFC Agent Marketplace.
196
199
 
197
200
  ## License
198
201
  This project is released under the Apache License 2.0 © 2026 Keiko Nomura.
@@ -4,7 +4,7 @@ build-backend = "hatchling.build"
4
4
 
5
5
  [project]
6
6
  name = "viewinline"
7
- version = "0.2.1"
7
+ version = "0.2.2"
8
8
  description = "Quick look geospatial viewer for iTerm2 compatible terminals"
9
9
  readme = "README.md"
10
10
  license = { text = "Apache-2.0" }
@@ -26,13 +26,14 @@ import pandas as pd
26
26
  from PIL import Image, ImageOps, ImageDraw, ImageFont
27
27
  from matplotlib import colormaps
28
28
  import matplotlib as mpl
29
+ import subprocess
29
30
 
30
31
  import warnings
31
32
 
32
33
  warnings.filterwarnings("ignore", message="More than one layer found", category=UserWarning)
33
34
  warnings.filterwarnings("ignore", message="Dataset has no geotransform", category=UserWarning)
34
35
 
35
- __version__ = "0.2.1"
36
+ __version__ = "0.2.2"
36
37
 
37
38
  AVAILABLE_COLORMAPS = [
38
39
  "viridis", "inferno", "magma", "plasma",
@@ -40,6 +41,70 @@ AVAILABLE_COLORMAPS = [
40
41
  "Spectral", "cubehelix", "tab10", "turbo"
41
42
  ]
42
43
 
44
+ _TERMINALS_WITHOUT_IMAGES = [
45
+ 'unknown', 'cygwin', 'tmux', 'screen',
46
+ 'vscode', 'xterm', 'rxvt', 'alacritty', 'foot', 'st', 'kitty',
47
+ 'gnome-terminal', 'xfce4-terminal', 'lxterminal', 'terminator',
48
+ 'tilix', 'hyper', 'windows terminal', 'putty', 'sakura',
49
+ 'terminology', 'eterm', 'guake', 'tilda', 'deepin-terminal',
50
+ ]
51
+
52
+ def detect_terminal() -> dict[str, str]:
53
+ """Detect terminal emulator by checking environment variables and parent process.
54
+ Returns a dictionary of detected terminal-related variables.
55
+ """
56
+ env = os.environ
57
+ terms = {}
58
+ # Check for common terminal-specific variables
59
+ for var in [
60
+ "TERM_PROGRAM", "KONSOLE_VERSION", "KONSOLE_PROFILE_NAME",
61
+ "VTE_VERSION", "TERMINATOR_UUID", "ALACRITTY_SOCKET",
62
+ "WEZTERM_EXECUTABLE", "ITERM_SESSION_ID"
63
+ ]:
64
+ if var in env:
65
+ term = env[var]
66
+ if term:
67
+ terms[var] = term
68
+ # Fallback: check parent process
69
+ if not terms:
70
+ try:
71
+ ppid = os.getppid()
72
+ parent = subprocess.check_output(["ps", "-p", str(ppid), "-o", "comm="]).decode().strip()
73
+ if parent:
74
+ terms["PARENT_PROCESS"] = parent
75
+ except Exception:
76
+ pass
77
+ term = env.get("TERM")
78
+ if term:
79
+ terms["TERM"] = term
80
+ return terms
81
+
82
+ def is_terminal_without_images(term_info: dict[str, str]) -> bool:
83
+ """Determine if the terminal is likely to support inline images based on detected info.
84
+ Args:
85
+ term_info: Dictionary of terminal-related environment variables.
86
+ Returns:
87
+ True if terminal is likely supported, False if known to be unsupported.
88
+ """
89
+ if os.environ.get("INLINE_VIEWER_ENGINE") == "chafa":
90
+ return True
91
+ terms = term_info.values()
92
+ for unsupported in _TERMINALS_WITHOUT_IMAGES:
93
+ if unsupported in terms:
94
+ return True
95
+ return False
96
+
97
+ def is_chafa_available() -> bool:
98
+ """Check if the 'chafa' command-line tool is available for ASCII art fallback."""
99
+ try:
100
+ subprocess.run(["chafa", "--version"], stdout=subprocess.DEVNULL, stderr=subprocess.DEVNULL)
101
+ return True
102
+ except FileNotFoundError:
103
+ return False
104
+
105
+ _TERMINAL_INFO = detect_terminal()
106
+ _TERMINAL_SUPPORTS_IMAGES = not is_terminal_without_images(_TERMINAL_INFO)
107
+
43
108
  # ---------------------------------------------------------------------
44
109
  # Display utilities
45
110
  # ---------------------------------------------------------------------
@@ -52,7 +117,8 @@ def show_inline_image(image_array: np.ndarray, display_scale = None, is_vector:
52
117
  buffer = BytesIO()
53
118
  # Use lower compression level for performance in speed
54
119
  Image.fromarray(image_array).save(buffer, format="PNG", compress_level=1, optimize=False)
55
- encoded = base64.b64encode(buffer.getvalue()).decode("utf-8")
120
+ image_bytes = buffer.getvalue()
121
+ encoded = base64.b64encode(image_bytes).decode("utf-8")
56
122
 
57
123
  if display_scale is None:
58
124
  width_pct = 33 # same default for both
@@ -67,7 +133,19 @@ def show_inline_image(image_array: np.ndarray, display_scale = None, is_vector:
67
133
  # Clamp range
68
134
  width_pct = max(5, min(width_pct, 400))
69
135
 
70
- sys.stdout.write(f"\033]1337;File=inline=1;width={width_pct}%:{encoded}\a\n")
136
+ if _TERMINAL_SUPPORTS_IMAGES:
137
+ sys.stdout.write(f"\033]1337;File=inline=1;width={width_pct}%:{encoded}\a\n")
138
+ else:
139
+ if is_chafa_available():
140
+ chafa_output = subprocess.check_output(
141
+ ["chafa", "-"],
142
+ input=image_bytes
143
+ ).decode()
144
+
145
+ sys.stdout.write(f"\n{chafa_output}\a\n")
146
+ else:
147
+ sys.stdout.write(f"[INFO] Use supported terminal or install 'chafa' for ascii art fallback. Detected: {_TERMINAL_INFO}\n")
148
+
71
149
  sys.stdout.flush()
72
150
 
73
151
 
Binary file
Binary file
File without changes
File without changes