Skip to content

Commit

Permalink
Don't attempt to reload stdin images
Browse files Browse the repository at this point in the history
Resolves artemsen#140.

Signed-off-by: diniamo <[email protected]>
  • Loading branch information
diniamo authored and artemsen committed Jun 12, 2024
1 parent 1a519c8 commit f2bbe75
Show file tree
Hide file tree
Showing 5 changed files with 21 additions and 3 deletions.
2 changes: 1 addition & 1 deletion src/image.c
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,7 @@ struct image* image_from_stdin(void)
}

if (data) {
ctx = image_create("{STDIN}", data, size);
ctx = image_create(STDIN_FILE_NAME, data, size);
}

done:
Expand Down
3 changes: 3 additions & 0 deletions src/image.h
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,9 @@ struct image_info {
char* value; ///< Meta value
};

/** Name used for image, that is read from stdin through pipe. */
#define STDIN_FILE_NAME "{STDIN}"

/**
* Load image from file.
* @param file path to the file to load
Expand Down
7 changes: 5 additions & 2 deletions src/imagelist.c
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,6 @@

/** Number of entries added on reallocation. */
#define ALLOCATE_SIZE 32
/** Name used for image, that is read from stdin through pipe. */
#define STDIN_FILE_NAME "*stdin*"

/** Single list entry. */
struct entry {
Expand Down Expand Up @@ -592,6 +590,11 @@ bool image_list_skip(void)
return image_list_jump(jump_next_file);
}

bool image_list_is_stdin(void)
{
return strcmp(ctx.current->file_path, STDIN_FILE_NAME) == 0;
}

bool image_list_reset(void)
{
// reset cache
Expand Down
8 changes: 8 additions & 0 deletions src/imagelist.h
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,14 @@ struct image_entry image_list_current(void);
*/
bool image_list_skip(void);

/**
* Get whether the current image is from stdin.
*
* This implies that it is also the only image open.
* @return false if the current image is not from stdin
*/
bool image_list_is_stdin(void);

/**
* Reset cache and reload current image.
* @return false if reset failed (no more images)
Expand Down
4 changes: 4 additions & 0 deletions src/viewer.c
Original file line number Diff line number Diff line change
Expand Up @@ -607,6 +607,10 @@ void viewer_free(void)

bool viewer_reload(void)
{
if (image_list_is_stdin()) {
reset_state();
return true;
}
if (!image_list_reset()) {
printf("No more images, exit\n");
ui_stop();
Expand Down

0 comments on commit f2bbe75

Please sign in to comment.