Skip to content

Commit

Permalink
Allow default title format from environment variable.
Browse files Browse the repository at this point in the history
Issue #67
  • Loading branch information
hzeller committed Dec 25, 2021
1 parent faecd1e commit a707ffd
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 5 deletions.
18 changes: 13 additions & 5 deletions man/timg.1.md
Original file line number Diff line number Diff line change
Expand Up @@ -179,18 +179,22 @@ these file decoders (GraphicsMagick or libav respectively).
the opposite of **-V**.

**-\-title=[format-string]**
: Print filename as title above each image. By default, this is just the
filename (`%f`), but it is possible to customize the title by giving a
format string. In this string, the following format specifiers are expanded
: Print title above each image. It is possible to customize the
title by giving a format string. In this string, the following format
specifiers are expanded:

* `%f` = full filename
* `%b` = basename (filename without path)
* `%w` = image width
* `%h` = image height
* `%D` = internal decoder used (image, video, ...)

If no format string is given, this is just the filename (`%f`) or, if
set, what is provided in the `TIMG_DEFAULT_TITLE` environment variable.

**-F**
: Behaves like --title=\"%f\", i.e. the filename is printed as title.
: Behaves like --title=\"%f\", i.e. the filename is printed as title
(or, if set, the `TIMG_DEFAULT_TITLE` environment variable).

**-f** <*filelist-file*>
: Read a list of image filenames to show from this file. The list needs
Expand Down Expand Up @@ -283,8 +287,12 @@ Exit code is

# ENVIRONMENT

**TIMG_DEFAULT_TITLE**
: The default format string used for `--title`. If not given, the default
title format string is \"`%f`\".

**TIMG_USE_UPPER_BLOCK**
: If this environment variable is set to the value **1**, timg will use the
: If this environment variable is set to the value **1**, timg will use the
U+2580 - 'Upper Half Block' (▀) Unicode character.

To display pixels, timg uses a Unicode half block and sets the foreground
Expand Down
7 changes: 7 additions & 0 deletions src/display-options.h
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@

#include "timg-time.h"

#include <stdlib.h>

#include <string>
#include <functional>
#include <limits>
Expand All @@ -31,6 +33,11 @@ static constexpr int kNotInitialized = std::numeric_limits<int>::min();
// Options influencing the rendering, chosen on the command-line or
// programmatically.
struct DisplayOptions {
DisplayOptions() {
static constexpr const char *kFormatEnv = "TIMG_DEFAULT_TITLE";
if (getenv(kFormatEnv)) title_format = getenv(kFormatEnv);
}

int width = -1; // Output size. These need to be set to...
int height = -1; // ... valid values.

Expand Down

0 comments on commit a707ffd

Please sign in to comment.