Skip to content

Commit

Permalink
Merge branch 'master' of https://github.com/coladict/gti into coladic…
Browse files Browse the repository at this point in the history
…t-master

Frame time / sleep stuff rewritten somewhat. The default value is
now 1000, not 50 - so it's possible to make this much slower. If needed.
Why should that be needed? I don't know.
  • Loading branch information
rwos committed Mar 8, 2017
2 parents 38dad0f + 3d75d56 commit 25a00ce
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 10 deletions.
4 changes: 2 additions & 2 deletions README.md
Expand Up @@ -23,10 +23,10 @@ From source:

The default install PREFIX is `/usr/bin`.

You can change the speed of the car at compile time via a cpp-define.
You can change the speed of the car at runtime via `GTI_SPEED`.
For example:

$ make CFLAGS=-DGTI_SPEED=100 # default is 50
$ GTI_SPEED=2000 gti push # default is 1000

Usage
-----
Expand Down
13 changes: 12 additions & 1 deletion gti.6
Expand Up @@ -11,9 +11,20 @@ parameters or arguments given to \fBgti\fP will be passed through to git.
The car image is derived from the look of an old VW Golf GTI.

.SH ENVIRONMENT
\fBgti\fP respects the GIT environment variable. If GIT is set, its value will
.TP
.B GIT
\fBgti\fP respects the
.RB $ GIT
environment variable. If GIT is set, its value will
be used to launch git after the animation finishes, instead of searching for
git in your PATH.
.TP
.B GTI_SPEED
If
.RB $ GTI_SPEED
is set to a parsable integer, its value is used to control the speed of the
animation.


.SH SEE ALSO
\fBgit\fP(1), \fBsl\fP(6)
Expand Down
20 changes: 13 additions & 7 deletions gti.c
Expand Up @@ -59,7 +59,7 @@ HANDLE WIN_CONSOLE;
#define GIT_NAME "git"

#ifndef GTI_SPEED
# define GTI_SPEED 50
# define GTI_SPEED 1000
#endif

int term_width(void);
Expand All @@ -74,21 +74,27 @@ void draw_std(int x);
void draw_push(int x);
draw_fn_t select_command(int argc, char **argv);

int TERM_WIDTH;
FILE *TERM_FH;
int SLEEP_DELAY;
int TERM_WIDTH;
unsigned int FRAME_TIME;

int main(int argc, char **argv)
{
int i;
char *git_path;
char *tmp;
unsigned int gti_speed;
draw_fn_t draw_fn;

draw_fn = select_command(argc, argv);

tmp = getenv("GTI_SPEED");
if (!tmp || sscanf(tmp, "%u", &gti_speed) != 1) {
gti_speed = GTI_SPEED;
}
open_term();
TERM_WIDTH = term_width();
FRAME_TIME = 1000 * 1000 * 10 / (gti_speed + TERM_WIDTH + 1);

draw_fn = select_command(argc, argv);
init_space();
for (i = -20; i < TERM_WIDTH; i++) {
draw_fn(i);
Expand Down Expand Up @@ -219,7 +225,7 @@ void draw_std(int x)
line_at(x, " ':-:' ':-:' ");
}
/* *INDENT-ON* */
usleep(1000000 / (TERM_WIDTH + GTI_SPEED));
usleep(FRAME_TIME);
}

void draw_push(int x)
Expand All @@ -240,7 +246,7 @@ void draw_push(int x)
line_at(x, " / \\ ':-:' ':-:' ");
}
/* *INDENT-ON* */
usleep(20000000 / (TERM_WIDTH + GTI_SPEED));
usleep(FRAME_TIME * 10);
}

void clear_car(int x)
Expand Down

0 comments on commit 25a00ce

Please sign in to comment.