I created a simple education tool using BASH script which runs in an X terminal. It displays a prompt, at which users can enter choices, as described in the Bash Guide for Beginners' Catching user input, and previous typed input is pushed up the screen.

 __________________________
|________________________X_|
| ...                    |^|
|       30               | |
|     x 10               | |
|    ------              | |
| >                      |=|
|________________________|v|

Occasionally, I need to display some graphics nearby this text input area, which can be visible while the user is typing. I tried various solutions:

  • Using txt2img from libcasa. This displays the graphic inside the terminal window as colorful ASCII art, but complex graphics were not easily recognizable.
  • Using eog to display the picture. This displays the picture in another window, but requires that the user press "q" or quit the graphic window prior to continuing to use the terminal.

Is there any way to present a split-view window that places the BASH terminal's script in one pane and a high-quality graphic in the other, which can be updated by the BASH script? This might look something like this:

 __________________________
|________________________X_|
|                          |
|           (PNG)          |
|                          |
|==========================|
| ...                    |^|
| How many apples        | |
| do you see in the      | |
| picture?               | |
| >                      |=|
|________________________|v|
  • You might want to look into DBus. Some applications provide a standardized interface to let you control them from different applications, so you could start an image viewer, resize it and display different images from DBus. Beware as DBus programming can be quite frustrating :) – mtak Dec 8 '14 at 15:45

partial answer:

What you need is an image-viewer program that can display an image without grabbing the keyboard focus. Then you can either kill it and re-run it. (start it in the background, and $! will be the PID). Or it can read a list of files to display from a pipe, or better, commands like "display this file now" from a pipe, you could have a persistent pipe to it open as one of the shell's file descriptors.

(I think that's what this q&a is about: background process pipe-input. Extending this to make a new FD as fd 42 so you can write to the pipe with echo foo >&42 might work. Or maybe you need to use coproc for this.)

I looked around some, but didn't find any image viewers that had an option to not grab the focus. It might be possible to add the flag to request that to an existing image viewer's code, and compile a custom version of it.

Your Answer

 

By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

Not the answer you're looking for? Browse other questions tagged or ask your own question.