Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix possibly inaccurate animation delays, fixes #35 #48

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,9 @@ if (NOT MAN_OUTPUT_PATH)
endif()

# set some options
#set(CMAKE_C_FLAGS_DEBUG "${CMAKE_C_FLAGS_DEBUG} -Wall -Wextra -g -std=c99 -Wno-unused-result")
#set(CMAKE_C_FLAGS_DEBUG "${CMAKE_C_FLAGS_DEBUG} -Wall -Wextra -g -std=c11 -Wno-unused-result")
#set(CMAKE_BUILD_TYPE Debug)
set(CMAKE_C_FLAGS_RELEASE "${CMAKE_C_FLAGS_RELEASE} -Wall -Wextra -Os -std=c99 -Wno-unused-result")
set(CMAKE_C_FLAGS_RELEASE "${CMAKE_C_FLAGS_RELEASE} -Wall -Wextra -Os -std=c11 -Wno-unused-result")
set(CMAKE_BUILD_TYPE Release)

set(SRC ${PROJECT_SOURCE_DIR}/src)
Expand Down
14 changes: 11 additions & 3 deletions src/catimg.c
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
#include <string.h>
#include "sh_image.h"
#include "sh_utils.h"
#include <unistd.h>
#include <time.h>
#include <signal.h>

#define USAGE "Usage: catimg [-hct] [-w width] [-l loops] [-r resolution] image-file\n\n" \
Expand Down Expand Up @@ -58,6 +58,14 @@ char supportsUTF8() {
|| (LC_CTYPE && strstr(LC_CTYPE, UTF));
}

// sleep for at least delay / 100 seconds
void mysleep(const uint16_t delay) {
struct timespec time;
time.tv_sec = delay / 100;
time.tv_nsec = (delay - 100 * (time.tv_sec)) * 10000;
while (nanosleep(&time, &time));
}

int main(int argc, char *argv[])
{
init_hash_colors();
Expand Down Expand Up @@ -140,9 +148,9 @@ int main(int argc, char *argv[])
for (uint32_t frame = 0; frame < img.frames; frame++) {
if (frame > 0 || loop > 0) {
if (frame > 0)
usleep(img.delays[frame - 1] * 10000);
mysleep(img.delays[frame - 1]);
else
usleep(img.delays[img.frames - 1] * 10000);
mysleep(img.delays[img.frames - 1]);
printf("\e[u");
}
uint32_t index, x, y;
Expand Down