Home

Awesome

Überzug

Überzug is a command line util which allows one to draw images on terminals by using child windows.

Advantages over the w3mimgdisplay program:

Overview

Dependencies

Libraries used in the c extension:

There are also other direct dependencies,
but they will be installed by pip.

Installation

Note: You can improve the performance of image manipulation functions by using pillow-simd instead of pillow.

Communication

The communication is realised via stdin.
A command is a request to execute a specific action with the passed arguments.
(Therefore a command has to contain a key value pair "action": action_name)
Commands are separated with a line break.

Command formats

Actions

Add

Name: add
Description:
Adds an image to the screen.
If there's already an image with the same identifier
it will be replaced.

KeyTypeDescriptionOptional
identifierStringa freely chosen identifier of the imageNo
xIntegerx positionNo
yIntegery positionNo
pathStringpath to the imageNo
widthIntegerdesired width; original width will be used if not setYes
heightIntegerdesired height; original width will be used if not setYes
max_widthIntegerDeprecated: replaced by scalers (this behavior is implemented by the default scaler contain)<br>image will be resized (while keeping it's aspect ratio) if it's width is bigger than max widthYes
max_heightIntegerDeprecated: replaced by scalers (this behavior is implemented by the default scaler contain)<br>image will be resized (while keeping it's aspect ratio) if it's height is bigger than max heightYes
drawBooleanredraw window after adding the image, default TrueYes
synchronously_drawBooleanredraw window immediatelyYes
scalerStringname of the image scaler<br>(algorithm which resizes the image to fit into the placement)Yes
scaling_position_xFloatthe centered position, if possible<br>Specified as factor of the image size,<br>so it should be an element of [0, 1].Yes
scaling_position_yFloatanalogous to scaling_position_xYes

ImageScalers:

NameDescription
cropCrops out an area of the size of the placement size.
distortDistorts the image to the placement size.
fit_containResizes the image that either the width matches the maximum width or the height matches the maximum height while keeping the image ratio.
containResizes the image to a size <= the placement size while keeping the image ratio.
forced_coverResizes the image to cover the entire area which should be filled<br>while keeping the image ratio.<br>If the image is smaller than the desired size<br>it will be stretched to reach the desired size.<br>If the ratio of the area differs<br>from the image ratio the edges will be cut off.
coverThe same as forced_cover but images won't be stretched<br>if they are smaller than the area which should be filled.

Remove

Name: remove
Description:
Removes an image from the screen.

KeyTypeDescriptionOptional
identifierStringa previously used identifierNo
drawBooleanredraw window after removing the image, default TrueYes

Libraries

Just a reminder: This is a GPLv3 licensed project, so if you use any of these libraries you also need to license it with a GPLv3 compatible license.

Bash

The library is deprecated.
Dump associative arrays if you want to use ueberzug with bash.

First of all the library doesn't follow the posix standard,
so you can't use it in any other shell than bash.

Executing ueberzug library will print the path to the library to stdout.

Functions:

Python

First of all everything which isn't mentioned here isn't safe to use and
won't necessarily shipped with new coming versions.

The library is included in ueberzug's package.

import ueberzug.lib.v0 as ueberzug

Classes:

  1. Visibility:
    An enum which contains the visibility states of a placement.

    • VISIBLE
    • INVISIBLE
  2. Placement:
    A placement to put images on.

    Every key value pair of the add action is an attribute (except identifier).
    Changing one of it will lead to building and transmitting an add command if the placement is visible.
    The identifier key value pair is implemented as a property and not changeable.

    Constructor:

    NameTypeOptionalDescription
    canvasCanvasNothe canvas where images should be drawn on
    identifierStringNoa unique string used to address this placement
    visibilityVisibilityYesthe initial visibility state<br>(if it's VISIBLE every attribute without a default value needs to be set)
    **kwargsdictYeskey value pairs of the add action

    Properties:

    NameTypeSetterDescription
    identifierStringNothe identifier of this placement
    canvasCanvasNothe canvas this placement belongs to
    visibilityVisibilityYesthe visibility state of this placement<br>- setting it to VISIBLE leads to the transmission of an add command<br>- setting it to INVISIBLE leads to the transmission of a remove command

    Warning:
    The transmission of a command can lead to an IOError.
    (A transmission happens on assign a new value to an attribute of a visible Placement.
    The transmission is delayed till leaving a with-statement if lazy_drawing is used.)

  3. ScalerOption:
    Enum which contains the useable scaler names.

  4. Canvas:
    Should either be used with a with-statement or with a decorated function.
    (Starts and stops the ueberzug process)

    Constructor:

    NameTypedefaultDescription
    debugboolFalsesuppresses printing stderr if it's false

    Methods:

    NameReturnsDescription
    create_placementPlacementprevents the use of the same identifier multiple times,<br>takes the same arguments as the Placement constructor (excluding canvas parameter)
    __call__FunctionDecorator which returns a function which calls the decorated function with the keyword parameter canvas=this_canvas_object.<br>Of course other arguments are also passed through.
    request_transmission-Transmits queued commands if automatic_transmission is enabled or force=True is passed as keyword argument.

    Properties / Attributes:

    NameTypeSetterDescription
    lazy_drawingcontext manager factoryNoprevents the transmission of commands till the with-statement was left<br>with canvas.lazy_drawing: pass
    synchronous_lazy_drawingcontext manager factoryNoDoes the same as lazy_drawing. Additionally forces the redrawing of the windows to happen immediately.
    automatic_transmissionboolYesTransmit commands instantly on changing a placement. If it's disabled commands won't be transmitted till a lazy_drawing or synchronous_lazy_drawing with-statement was left or request_transmission(force=True) was called. Default: True

Examples

Command formats:

Bash:

# process substitution example:
ueberzug layer --parser bash 0< <(
    declare -Ap add_command=([action]="add" [identifier]="example0" [x]="0" [y]="0" [path]="/some/path/some_image0.jpg")
    declare -Ap add_command=([action]="add" [identifier]="example1" [x]="10" [y]="0" [path]="/some/path/some_image1.jpg")
    sleep 5
    declare -Ap remove_command=([action]="remove" [identifier]="example0")
    sleep 5
)

# group commands example:
{
    declare -Ap add_command=([action]="add" [identifier]="example0" [x]="0" [y]="0" [path]="/some/path/some_image0.jpg")
    declare -Ap add_command=([action]="add" [identifier]="example1" [x]="10" [y]="0" [path]="/some/path/some_image1.jpg")
    read
    declare -Ap remove_command=([action]="remove" [identifier]="example0")
    read
} | ueberzug layer --parser bash

Python library:

  import curses
  import time
  from curses.textpad import Textbox, rectangle
  import ueberzug.lib.v0 as ueberzug
  
  
  @ueberzug.Canvas()
  def main(stdscr, canvas):
      demo = canvas.create_placement('demo', x=10, y=0)
      stdscr.addstr(0, 0, "Enter IM message: (hit Ctrl-G to send)")
  
      editwin = curses.newwin(5, 30, 3, 1)
      rectangle(stdscr, 2, 0, 2+5+1, 2+30+1)
      stdscr.refresh()
  
      box = Textbox(editwin)
  
      # Let the user edit until Ctrl-G is struck.
      box.edit()
  
      # Get resulting contents
      message = box.gather()
      demo.path = ''.join(message.split())
      demo.visibility = ueberzug.Visibility.VISIBLE
      time.sleep(2)
  
  
  if __name__ == '__main__':
      curses.wrapper(main)

Scripts:

Similar projects: