Skip to content

Commit

Permalink
updates and version bump
Browse files Browse the repository at this point in the history
  • Loading branch information
briandowns committed Jan 12, 2020
1 parent 71a31cd commit 6f8652b
Show file tree
Hide file tree
Showing 5 changed files with 44 additions and 38 deletions.
2 changes: 1 addition & 1 deletion Flotsam.toml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ name = "libspinner"
build = "make"
repository = "github.com/briandowns/libspinner"
homepage = ""
version = "0.3.1"
version = "0.3.2"
description = "C library for adding a spinner/indicator to terminal applications."
authors = ["Brian J. Downs"]

Expand Down
14 changes: 10 additions & 4 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -8,15 +8,15 @@ NAME = libspinner

UNAME_S = $(shell uname -s)

ifeq ($(UNAME_S),Linux)
$(NAME).so:
$(CC) -shared -o $(NAME).so spinner.c $(CFLAGS)
endif
ifeq ($(UNAME_S),Darwin)
$(NAME).dylib:
$(CC) -c -dynamiclib -o $(NAME).so spinner.c $(CFLAGS) $(LDFLAGS)
else
$(NAME).so:
$(CC) -shared -o $(NAME).so spinner.c $(CFLAGS)
endif


.PHONY: install
install:
cp spinner.h $(INCDIR)
Expand All @@ -43,6 +43,12 @@ test:
tests/tests
rm -f tests/tests

.PHONY: clean
clean:
rm -f libspinner.so
rm -f example

.PHONY: run-example
run-example:
$(CC) $(CFLAGS) -o example examples/main.c spinner.c

2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ make test
* Chain, pipe, redirect output
* Output final string on spinner/indicator completion

## Available Character Sets
## (sample of) Available Character Sets
(cursor not visible in normal operation)

index | character set | sample gif
Expand Down
44 changes: 22 additions & 22 deletions spinner.c
Original file line number Diff line number Diff line change
Expand Up @@ -34,17 +34,17 @@
#include "spinner.h"

/*
* toggle the cursor on and off
* toggle the cursor on and off.
*/
#define CURSOR_STATE(x) \
switch (x) { \
case 0: \
printf("\e[?25l"); \
break; \
case 1: \
printf("\e[?25h"); \
break; \
} \
#define CURSOR_STATE(x) \
switch (x) { \
case 0: \
printf("\e[?25l"); \
break; \
case 1: \
printf("\e[?25h"); \
break; \
} \
fflush(stdout);

char* char_sets[][MAX_CHARS] = {
Expand Down Expand Up @@ -200,7 +200,7 @@ char* char_sets[][MAX_CHARS] = {
};

spinner_t*
spinner_new(int id)
spinner_new(const int id)
{
spinner_t* s = malloc(sizeof(spinner_t));
s->char_set_id = id;
Expand All @@ -213,7 +213,7 @@ spinner_new(int id)
}

void
spinner_free(spinner_t* s)
spinner_free(spinner_t *s)
{
if (s) {
free(s);
Expand All @@ -227,7 +227,7 @@ spinner_free(spinner_t* s)
* current state.
*/
static int
spinner_state(spinner_t* s)
spinner_state(spinner_t *s)
{
int state;
pthread_mutex_lock(&s->mu);
Expand All @@ -242,9 +242,9 @@ spinner_state(spinner_t* s)
* printing the character to screen.
*/
static void*
spin(void* arg)
spin(void *arg)
{
spinner_t* s = (spinner_t*)arg;
spinner_t *s = (spinner_t*)arg;
if (s->reversed == 1) {
}
for (int i = 0;; i++) {
Expand All @@ -266,7 +266,7 @@ spin(void* arg)
}

void
spinner_start(spinner_t* s)
spinner_start(spinner_t *s)
{
if (s->active > 0) {
return;
Expand All @@ -283,7 +283,7 @@ spinner_start(spinner_t* s)
}

void
spinner_stop(spinner_t* s)
spinner_stop(spinner_t *s)
{
pthread_mutex_lock(&s->mu);
s->active = 0;
Expand All @@ -295,38 +295,38 @@ spinner_stop(spinner_t* s)
}

void
spinner_restart(spinner_t* s)
spinner_restart(spinner_t *s)
{
spinner_stop(s);
spinner_start(s);
}

void
spinner_char_set_update(spinner_t* s, const int id)
spinner_char_set_update(spinner_t *s, const int id)
{
pthread_mutex_lock(&s->mu);
s->char_set_id = id;
pthread_mutex_unlock(&s->mu);
}

void
spinner_update_speed(spinner_t* s, const uint64_t delay)
spinner_update_speed(spinner_t *s, const uint64_t delay)
{
pthread_mutex_lock(&s->mu);
s->delay = delay;
pthread_mutex_unlock(&s->mu);
}

void
spinner_set_output_dest(spinner_t* s, FILE* fd)
spinner_set_output_dest(spinner_t *s, FILE *fd)
{
pthread_mutex_lock(&s->mu);
s->output_dst = fd;
pthread_mutex_unlock(&s->mu);
}

void
spinner_reverse(spinner_t* s)
spinner_reverse(spinner_t *s)
{
pthread_mutex_lock(&s->mu);
if (s->reversed == 0) {
Expand Down
20 changes: 10 additions & 10 deletions spinner.h
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@
/*
* char_sets is the collection of spinners.
*/
extern char* char_sets[][MAX_CHARS];
extern char *char_sets[][MAX_CHARS];

/*
* spinner_t maintains the state of the spinner
Expand All @@ -68,58 +68,58 @@ typedef struct
* struct and sets sane defaults for immediate use.
*/
spinner_t*
spinner_new(int id);
spinner_new(const int id);

/*
* spinner_free frees the used memory of the
* spinner_t pointer.
*/
void
spinner_free(spinner_t* s);
spinner_free(spinner_t *s);

/*
* spinner_start starts the spinner.
*/
void
spinner_start(spinner_t* s);
spinner_start(spinner_t *s);

/*
* spinner_stop stops the spinner.
*/
void
spinner_stop(spinner_t* s);
spinner_stop(spinner_t *s);

/*
* spinner_restart will restart the spinner.
*/
void
spinner_restart(spinner_t* s);
spinner_restart(spinner_t *s);

/*
* spinner_char_set_update updates the character
* set with the new given one.
*/
void
spinner_char_set_update(spinner_t* s, const int id);
spinner_char_set_update(spinner_t *s, const int id);

/*
* spinner_update_speed updates the speed at which
* the spinner is spinning.
*/
void
spinner_update_speed(spinner_t* s, const uint64_t delay);
spinner_update_speed(spinner_t *s, const uint64_t delay);

/*
* spinner_set_output_dest sets the file descriptor to
* write spinner output to.
*/
void
spinner_set_output_dest(spinner_t* s, FILE* fd);
spinner_set_output_dest(spinner_t *s, FILE *fd);

/*
* spinner_reverse reverses the direction of the spinner.
*/
void
spinner_reverse(spinner_t* s);
spinner_reverse(spinner_t *s);

#endif

0 comments on commit 6f8652b

Please sign in to comment.