Rename nmsterm modules to nmstermio, and update function names to align with new module name
modified: Makefile modified: src/nmseffect.c deleted: src/nmsterm.h renamed: src/nmsterm.c -> src/nmstermio.c new file: src/nmstermio.h renamed: src/nmsterm_ncurses.c -> src/nmstermio_ncurses.c modified: src/sneakers.c
This commit is contained in:
parent
bd5614363f
commit
8a09f36cee
8
Makefile
8
Makefile
@ -17,20 +17,20 @@ CFLAGS ?= -Wextra -Wall
|
|||||||
|
|
||||||
.PHONY: all install uninstall clean
|
.PHONY: all install uninstall clean
|
||||||
|
|
||||||
nms: $(OBJ)/nmsterm.o $(OBJ)/nmseffect.o $(OBJ)/nms.o | $(BIN)
|
nms: $(OBJ)/nmstermio.o $(OBJ)/nmseffect.o $(OBJ)/nms.o | $(BIN)
|
||||||
$(CC) $(CFLAGS) -o $(BIN)/$@ $^
|
$(CC) $(CFLAGS) -o $(BIN)/$@ $^
|
||||||
|
|
||||||
sneakers: $(OBJ)/nmsterm.o $(OBJ)/nmseffect.o $(OBJ)/sneakers.o | $(BIN)
|
sneakers: $(OBJ)/nmstermio.o $(OBJ)/nmseffect.o $(OBJ)/sneakers.o | $(BIN)
|
||||||
$(CC) $(CFLAGS) -o $(BIN)/$@ $^
|
$(CC) $(CFLAGS) -o $(BIN)/$@ $^
|
||||||
|
|
||||||
all: nms sneakers
|
all: nms sneakers
|
||||||
|
|
||||||
all-ncurses: nms-ncurses sneakers-ncurses
|
all-ncurses: nms-ncurses sneakers-ncurses
|
||||||
|
|
||||||
nms-ncurses: $(OBJ)/nmsterm_ncurses.o $(OBJ)/nmseffect.o $(OBJ)/nms.o | $(BIN)
|
nms-ncurses: $(OBJ)/nmstermio_ncurses.o $(OBJ)/nmseffect.o $(OBJ)/nms.o | $(BIN)
|
||||||
$(CC) $(CFLAGS) -o $(BIN)/nms $^ -lncurses
|
$(CC) $(CFLAGS) -o $(BIN)/nms $^ -lncurses
|
||||||
|
|
||||||
sneakers-ncurses: $(OBJ)/nmsterm_ncurses.o $(OBJ)/nmseffect.o $(OBJ)/sneakers.o | $(BIN)
|
sneakers-ncurses: $(OBJ)/nmstermio_ncurses.o $(OBJ)/nmseffect.o $(OBJ)/sneakers.o | $(BIN)
|
||||||
$(CC) $(CFLAGS) -o $(BIN)/sneakers $^ -lncurses
|
$(CC) $(CFLAGS) -o $(BIN)/sneakers $^ -lncurses
|
||||||
|
|
||||||
$(OBJ)/%.o: $(SRC)/%.c | $(OBJ)
|
$(OBJ)/%.o: $(SRC)/%.c | $(OBJ)
|
||||||
|
@ -16,7 +16,7 @@
|
|||||||
#include <locale.h>
|
#include <locale.h>
|
||||||
#include <wchar.h>
|
#include <wchar.h>
|
||||||
#include "nmseffect.h"
|
#include "nmseffect.h"
|
||||||
#include "nmsterm.h"
|
#include "nmstermio.h"
|
||||||
|
|
||||||
// Program settings
|
// Program settings
|
||||||
#define TYPE_EFFECT_SPEED 4 // miliseconds per char
|
#define TYPE_EFFECT_SPEED 4 // miliseconds per char
|
||||||
@ -115,20 +115,20 @@ char nmseffect_exec(char *string) {
|
|||||||
setlocale(LC_ALL, "");
|
setlocale(LC_ALL, "");
|
||||||
|
|
||||||
// Initialize terminal
|
// Initialize terminal
|
||||||
nmsterm_init_terminal();
|
nmstermio_init_terminal();
|
||||||
|
|
||||||
if (!nmsterm_get_clearscr()) {
|
if (!nmstermio_get_clearscr()) {
|
||||||
// Get current row position
|
// Get current row position
|
||||||
origRow = nmsterm_get_cursor_row();
|
origRow = nmstermio_get_cursor_row();
|
||||||
|
|
||||||
// nms_get_cursor_row() may display output in some terminals. So
|
// nms_get_cursor_row() may display output in some terminals. So
|
||||||
// we need to reposition the cursor to the start of the row.
|
// we need to reposition the cursor to the start of the row.
|
||||||
nmsterm_move_cursor(origRow, 0);
|
nmstermio_move_cursor(origRow, 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Get terminal window rows/cols
|
// Get terminal window rows/cols
|
||||||
maxRows = nmsterm_get_rows();
|
maxRows = nmstermio_get_rows();
|
||||||
maxCols = nmsterm_get_cols();
|
maxCols = nmstermio_get_cols();
|
||||||
|
|
||||||
// Seed my random number generator with the current time
|
// Seed my random number generator with the current time
|
||||||
srand(time(NULL));
|
srand(time(NULL));
|
||||||
@ -162,7 +162,7 @@ char nmseffect_exec(char *string) {
|
|||||||
i += (mblen(&string[i], 4) - 1);
|
i += (mblen(&string[i], 4) - 1);
|
||||||
} else {
|
} else {
|
||||||
fprintf(stderr, "Unknown character encountered. Quitting.\n");
|
fprintf(stderr, "Unknown character encountered. Quitting.\n");
|
||||||
nmsterm_restore_terminal();
|
nmstermio_restore_terminal();
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -202,55 +202,55 @@ char nmseffect_exec(char *string) {
|
|||||||
|
|
||||||
// Print mask character (or space)
|
// Print mask character (or space)
|
||||||
if (list_pointer->is_space) {
|
if (list_pointer->is_space) {
|
||||||
nmsterm_print_string(list_pointer->source);
|
nmstermio_print_string(list_pointer->source);
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
// print mask character
|
// print mask character
|
||||||
nmsterm_print_string(list_pointer->mask);
|
nmstermio_print_string(list_pointer->mask);
|
||||||
if (list_pointer->width == 2) {
|
if (list_pointer->width == 2) {
|
||||||
nmsterm_print_string(maskCharTable[rand() % MASK_CHAR_COUNT]);
|
nmstermio_print_string(maskCharTable[rand() % MASK_CHAR_COUNT]);
|
||||||
}
|
}
|
||||||
|
|
||||||
// flush output and sleep
|
// flush output and sleep
|
||||||
nmsterm_refresh();
|
nmstermio_refresh();
|
||||||
nmseffect_sleep(TYPE_EFFECT_SPEED);
|
nmseffect_sleep(TYPE_EFFECT_SPEED);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Flush any input up to this point
|
// Flush any input up to this point
|
||||||
nmsterm_clear_input();
|
nmstermio_clear_input();
|
||||||
|
|
||||||
// If autoDecrypt flag is set, we sleep. Otherwise require user to
|
// If autoDecrypt flag is set, we sleep. Otherwise require user to
|
||||||
// press a key to continue.
|
// press a key to continue.
|
||||||
if (autoDecrypt)
|
if (autoDecrypt)
|
||||||
sleep(1);
|
sleep(1);
|
||||||
else
|
else
|
||||||
nmsterm_get_char();
|
nmstermio_get_char();
|
||||||
|
|
||||||
// Jumble loop
|
// Jumble loop
|
||||||
for (i = 0; i < (JUMBLE_SECONDS * 1000) / JUMBLE_LOOP_SPEED; ++i) {
|
for (i = 0; i < (JUMBLE_SECONDS * 1000) / JUMBLE_LOOP_SPEED; ++i) {
|
||||||
|
|
||||||
// Move cursor to start position
|
// Move cursor to start position
|
||||||
nmsterm_move_cursor(origRow, origCol);
|
nmstermio_move_cursor(origRow, origCol);
|
||||||
|
|
||||||
// Print new mask for all characters
|
// Print new mask for all characters
|
||||||
for (list_pointer = list_head; list_pointer != NULL; list_pointer = list_pointer->next) {
|
for (list_pointer = list_head; list_pointer != NULL; list_pointer = list_pointer->next) {
|
||||||
|
|
||||||
// Print mask character (or space)
|
// Print mask character (or space)
|
||||||
if (list_pointer->is_space) {
|
if (list_pointer->is_space) {
|
||||||
nmsterm_print_string(list_pointer->source);
|
nmstermio_print_string(list_pointer->source);
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
// print new mask character
|
// print new mask character
|
||||||
nmsterm_print_string(maskCharTable[rand() % MASK_CHAR_COUNT]);
|
nmstermio_print_string(maskCharTable[rand() % MASK_CHAR_COUNT]);
|
||||||
if (list_pointer->width == 2) {
|
if (list_pointer->width == 2) {
|
||||||
nmsterm_print_string(maskCharTable[rand() % MASK_CHAR_COUNT]);
|
nmstermio_print_string(maskCharTable[rand() % MASK_CHAR_COUNT]);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// flush output and sleep
|
// flush output and sleep
|
||||||
nmsterm_refresh();
|
nmstermio_refresh();
|
||||||
nmseffect_sleep(JUMBLE_LOOP_SPEED);
|
nmseffect_sleep(JUMBLE_LOOP_SPEED);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -258,7 +258,7 @@ char nmseffect_exec(char *string) {
|
|||||||
while (!revealed) {
|
while (!revealed) {
|
||||||
|
|
||||||
// Move cursor to start position
|
// Move cursor to start position
|
||||||
nmsterm_move_cursor(origRow, origCol);
|
nmstermio_move_cursor(origRow, origCol);
|
||||||
|
|
||||||
// Set revealed flag
|
// Set revealed flag
|
||||||
revealed = 1;
|
revealed = 1;
|
||||||
@ -267,7 +267,7 @@ char nmseffect_exec(char *string) {
|
|||||||
|
|
||||||
// Print mask character (or space)
|
// Print mask character (or space)
|
||||||
if (list_pointer->is_space) {
|
if (list_pointer->is_space) {
|
||||||
nmsterm_print_string(list_pointer->source);
|
nmstermio_print_string(list_pointer->source);
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -286,7 +286,7 @@ char nmseffect_exec(char *string) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Print mask
|
// Print mask
|
||||||
nmsterm_print_string(list_pointer->mask);
|
nmstermio_print_string(list_pointer->mask);
|
||||||
|
|
||||||
// Decrement reveal time
|
// Decrement reveal time
|
||||||
list_pointer->time -= REVEAL_LOOP_SPEED;
|
list_pointer->time -= REVEAL_LOOP_SPEED;
|
||||||
@ -296,43 +296,43 @@ char nmseffect_exec(char *string) {
|
|||||||
} else {
|
} else {
|
||||||
|
|
||||||
// print source character
|
// print source character
|
||||||
nmsterm_print_reveal_string(list_pointer->source, colorOn);
|
nmstermio_print_reveal_string(list_pointer->source, colorOn);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// flush output and sleep
|
// flush output and sleep
|
||||||
nmsterm_refresh();
|
nmstermio_refresh();
|
||||||
nmseffect_sleep(REVEAL_LOOP_SPEED);
|
nmseffect_sleep(REVEAL_LOOP_SPEED);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Flush any input up to this point
|
// Flush any input up to this point
|
||||||
nmsterm_clear_input();
|
nmstermio_clear_input();
|
||||||
|
|
||||||
// Check if user must select from a set of options
|
// Check if user must select from a set of options
|
||||||
if (returnOpts != NULL && strlen(returnOpts) > 0) {
|
if (returnOpts != NULL && strlen(returnOpts) > 0) {
|
||||||
|
|
||||||
// Position cursor if necessary
|
// Position cursor if necessary
|
||||||
if (inputPositionY >= 0 && inputPositionX >= 0) {
|
if (inputPositionY >= 0 && inputPositionX >= 0) {
|
||||||
nmsterm_move_cursor(inputPositionY, inputPositionX);
|
nmstermio_move_cursor(inputPositionY, inputPositionX);
|
||||||
}
|
}
|
||||||
|
|
||||||
nmsterm_show_cursor();
|
nmstermio_show_cursor();
|
||||||
|
|
||||||
// Get and validate user selection
|
// Get and validate user selection
|
||||||
while (strchr(returnOpts, ret = nmsterm_get_char()) == NULL) {
|
while (strchr(returnOpts, ret = nmstermio_get_char()) == NULL) {
|
||||||
nmsterm_beep();
|
nmstermio_beep();
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// User must press a key to continue when clearSrc is set
|
// User must press a key to continue when clearSrc is set
|
||||||
// without returnOpts
|
// without returnOpts
|
||||||
else if (nmsterm_get_clearscr()) {
|
else if (nmstermio_get_clearscr()) {
|
||||||
nmsterm_get_char();
|
nmstermio_get_char();
|
||||||
}
|
}
|
||||||
|
|
||||||
// Restore terminal
|
// Restore terminal
|
||||||
nmsterm_restore_terminal();
|
nmstermio_restore_terminal();
|
||||||
|
|
||||||
// Freeing the list.
|
// Freeing the list.
|
||||||
list_pointer = list_head;
|
list_pointer = list_head;
|
||||||
@ -354,7 +354,7 @@ char nmseffect_exec(char *string) {
|
|||||||
* passed an invalid color. No value is returned.
|
* passed an invalid color. No value is returned.
|
||||||
*/
|
*/
|
||||||
void nmseffect_set_foregroundcolor(char *color) {
|
void nmseffect_set_foregroundcolor(char *color) {
|
||||||
nmsterm_set_foregroundcolor(color);
|
nmstermio_set_foregroundcolor(color);
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
@ -382,7 +382,7 @@ void nmseffect_set_autodecrypt(int setting) {
|
|||||||
* true/false value of the 'setting' argument.
|
* true/false value of the 'setting' argument.
|
||||||
*/
|
*/
|
||||||
void nmseffect_set_clearscr(int s) {
|
void nmseffect_set_clearscr(int s) {
|
||||||
nmsterm_set_clearscr(s);
|
nmstermio_set_clearscr(s);
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
@ -1,31 +0,0 @@
|
|||||||
/*
|
|
||||||
* Copyright (c) 2017 Brian Barto
|
|
||||||
*
|
|
||||||
* This program is free software; you can redistribute it and/or modify it
|
|
||||||
* under the terms of the MIT License. See LICENSE for more details.
|
|
||||||
*/
|
|
||||||
|
|
||||||
#ifndef NMSTERM_H
|
|
||||||
#define NMSTERM_H 1
|
|
||||||
|
|
||||||
// Function prototypes
|
|
||||||
void nmsterm_init_terminal(void);
|
|
||||||
void nmsterm_restore_terminal(void);
|
|
||||||
int nmsterm_get_rows(void);
|
|
||||||
int nmsterm_get_cols(void);
|
|
||||||
int nmsterm_get_cursor_row(void);
|
|
||||||
void nmsterm_move_cursor(int, int);
|
|
||||||
void nmsterm_print_string(char *);
|
|
||||||
void nmsterm_refresh(void);
|
|
||||||
void nmsterm_clear_input(void);
|
|
||||||
char nmsterm_get_char(void);
|
|
||||||
void nmsterm_print_reveal_string(char *, int);
|
|
||||||
void nmsterm_show_cursor(void);
|
|
||||||
void nmsterm_beep(void);
|
|
||||||
int nmsterm_get_clearscr(void);
|
|
||||||
void nmsterm_set_clearscr(int);
|
|
||||||
void nmsterm_set_foregroundcolor(char *);
|
|
||||||
int nmsterm_get_cursor_row(void);
|
|
||||||
|
|
||||||
|
|
||||||
#endif
|
|
@ -42,13 +42,13 @@ static int clearScr = 0; // clearScr flag
|
|||||||
static int foregroundColor = COLOR_BLUE; // Foreground color setting
|
static int foregroundColor = COLOR_BLUE; // Foreground color setting
|
||||||
|
|
||||||
// Function prototypes
|
// Function prototypes
|
||||||
static void nmsterm_set_terminal(int);
|
static void nmstermio_set_terminal(int);
|
||||||
|
|
||||||
// Initialize terminal window
|
// Initialize terminal window
|
||||||
void nmsterm_init_terminal(void) {
|
void nmstermio_init_terminal(void) {
|
||||||
|
|
||||||
// Turn off line buffering and echo
|
// Turn off line buffering and echo
|
||||||
nmsterm_set_terminal(0);
|
nmstermio_set_terminal(0);
|
||||||
|
|
||||||
// Save terminal state, clear screen, and home/hide the cursor
|
// Save terminal state, clear screen, and home/hide the cursor
|
||||||
if (clearScr) {
|
if (clearScr) {
|
||||||
@ -60,7 +60,7 @@ void nmsterm_init_terminal(void) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void nmsterm_restore_terminal(void) {
|
void nmstermio_restore_terminal(void) {
|
||||||
|
|
||||||
// Restore screen and cursor is clearSrc is set
|
// Restore screen and cursor is clearSrc is set
|
||||||
if (clearScr) {
|
if (clearScr) {
|
||||||
@ -70,14 +70,14 @@ void nmsterm_restore_terminal(void) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Turn on line buffering and echo
|
// Turn on line buffering and echo
|
||||||
nmsterm_set_terminal(1);
|
nmstermio_set_terminal(1);
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* nms_term_rows() gets and returns the number of rows in the current
|
* Gets and returns the number of rows in the current
|
||||||
* terminal window.
|
* terminal window.
|
||||||
*/
|
*/
|
||||||
int nmsterm_get_rows(void) {
|
int nmstermio_get_rows(void) {
|
||||||
struct winsize w;
|
struct winsize w;
|
||||||
ioctl(STDOUT_FILENO, TIOCGWINSZ, &w);
|
ioctl(STDOUT_FILENO, TIOCGWINSZ, &w);
|
||||||
|
|
||||||
@ -85,29 +85,29 @@ int nmsterm_get_rows(void) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* nms_term_cols() gets and returns the number of cols in the current
|
* Gets and returns the number of cols in the current
|
||||||
* terminal window.
|
* terminal window.
|
||||||
*/
|
*/
|
||||||
int nmsterm_get_cols(void) {
|
int nmstermio_get_cols(void) {
|
||||||
struct winsize w;
|
struct winsize w;
|
||||||
ioctl(STDOUT_FILENO, TIOCGWINSZ, &w);
|
ioctl(STDOUT_FILENO, TIOCGWINSZ, &w);
|
||||||
|
|
||||||
return w.ws_col;
|
return w.ws_col;
|
||||||
}
|
}
|
||||||
|
|
||||||
void nmsterm_move_cursor(int y, int x) {
|
void nmstermio_move_cursor(int y, int x) {
|
||||||
CURSOR_MOVE(y, x);
|
CURSOR_MOVE(y, x);
|
||||||
}
|
}
|
||||||
|
|
||||||
void nmsterm_print_string(char *s) {
|
void nmstermio_print_string(char *s) {
|
||||||
printf("%s", s);
|
printf("%s", s);
|
||||||
}
|
}
|
||||||
|
|
||||||
void nmsterm_refresh(void) {
|
void nmstermio_refresh(void) {
|
||||||
fflush(stdout);
|
fflush(stdout);
|
||||||
}
|
}
|
||||||
|
|
||||||
void nmsterm_clear_input(void) {
|
void nmstermio_clear_input(void) {
|
||||||
int i;
|
int i;
|
||||||
|
|
||||||
ioctl(STDIN_FILENO, FIONREAD, &i);
|
ioctl(STDIN_FILENO, FIONREAD, &i);
|
||||||
@ -117,7 +117,7 @@ void nmsterm_clear_input(void) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
char nmsterm_get_char(void) {
|
char nmstermio_get_char(void) {
|
||||||
struct timespec ts;
|
struct timespec ts;
|
||||||
int t = 50;
|
int t = 50;
|
||||||
char c;
|
char c;
|
||||||
@ -132,7 +132,7 @@ char nmsterm_get_char(void) {
|
|||||||
return c;
|
return c;
|
||||||
}
|
}
|
||||||
|
|
||||||
void nmsterm_print_reveal_string(char *s, int colorOn) {
|
void nmstermio_print_reveal_string(char *s, int colorOn) {
|
||||||
|
|
||||||
// Set bold and foreground color
|
// Set bold and foreground color
|
||||||
BOLD();
|
BOLD();
|
||||||
@ -147,23 +147,23 @@ void nmsterm_print_reveal_string(char *s, int colorOn) {
|
|||||||
CLEAR_ATTR();
|
CLEAR_ATTR();
|
||||||
}
|
}
|
||||||
|
|
||||||
void nmsterm_show_cursor(void) {
|
void nmstermio_show_cursor(void) {
|
||||||
CURSOR_SHOW();
|
CURSOR_SHOW();
|
||||||
}
|
}
|
||||||
|
|
||||||
void nmsterm_beep(void) {
|
void nmstermio_beep(void) {
|
||||||
BEEP();
|
BEEP();
|
||||||
}
|
}
|
||||||
|
|
||||||
int nmsterm_get_clearscr(void) {
|
int nmstermio_get_clearscr(void) {
|
||||||
return clearScr;
|
return clearScr;
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* nmsterm_set_clearscr() sets the clearScr flag according to the
|
* Sets the clearScr flag according to the
|
||||||
* true/false value of the 's' argument.
|
* true/false value of the 's' argument.
|
||||||
*/
|
*/
|
||||||
void nmsterm_set_clearscr(int s) {
|
void nmstermio_set_clearscr(int s) {
|
||||||
if (s)
|
if (s)
|
||||||
clearScr = 1;
|
clearScr = 1;
|
||||||
else
|
else
|
||||||
@ -171,13 +171,13 @@ void nmsterm_set_clearscr(int s) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* nms_set_foreground_color() sets the foreground color of the unencrypted
|
* Sets the foreground color of the unencrypted
|
||||||
* characters as they are revealed to the color indicated by the 'color'
|
* characters as they are revealed to the color indicated by the 'color'
|
||||||
* argument. Valid arguments are "white", "yellow", "magenta", "blue",
|
* argument. Valid arguments are "white", "yellow", "magenta", "blue",
|
||||||
* "green", "red", and "cyan". This function will default to blue if
|
* "green", "red", and "cyan". This function will default to blue if
|
||||||
* passed an invalid color. No value is returned.
|
* passed an invalid color. No value is returned.
|
||||||
*/
|
*/
|
||||||
void nmsterm_set_foregroundcolor(char *c) {
|
void nmstermio_set_foregroundcolor(char *c) {
|
||||||
|
|
||||||
if(strcmp("white", c) == 0)
|
if(strcmp("white", c) == 0)
|
||||||
foregroundColor = COLOR_WHITE;
|
foregroundColor = COLOR_WHITE;
|
||||||
@ -200,10 +200,10 @@ void nmsterm_set_foregroundcolor(char *c) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* nms_get_cursor_row() returns the row position of the cursor as reported
|
* Returns the row position of the cursor as reported
|
||||||
* by the terminal program via the ANSI escape code
|
* by the terminal program via the ANSI escape code
|
||||||
*/
|
*/
|
||||||
int nmsterm_get_cursor_row(void) {
|
int nmstermio_get_cursor_row(void) {
|
||||||
int i, r = 0;
|
int i, r = 0;
|
||||||
int row = 0;
|
int row = 0;
|
||||||
char buf[10];
|
char buf[10];
|
||||||
@ -233,12 +233,12 @@ int nmsterm_get_cursor_row(void) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* nmsterm_set_terminal() turns off terminal echo and line buffering when
|
* Turns off terminal echo and line buffering when
|
||||||
* passed an integer value that evaluates to true. It restores the
|
* passed an integer value that evaluates to true. It restores the
|
||||||
* original terminal values when passed an integer value that evaluates
|
* original terminal values when passed an integer value that evaluates
|
||||||
* to false.
|
* to false.
|
||||||
*/
|
*/
|
||||||
static void nmsterm_set_terminal(int s) {
|
static void nmstermio_set_terminal(int s) {
|
||||||
struct termios tp;
|
struct termios tp;
|
||||||
static struct termios save;
|
static struct termios save;
|
||||||
static int state = 1;
|
static int state = 1;
|
31
src/nmstermio.h
Normal file
31
src/nmstermio.h
Normal file
@ -0,0 +1,31 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (c) 2017 Brian Barto
|
||||||
|
*
|
||||||
|
* This program is free software; you can redistribute it and/or modify it
|
||||||
|
* under the terms of the MIT License. See LICENSE for more details.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#ifndef NMSTERMIO_H
|
||||||
|
#define NMSTERMIO_H 1
|
||||||
|
|
||||||
|
// Function prototypes
|
||||||
|
void nmstermio_init_terminal(void);
|
||||||
|
void nmstermio_restore_terminal(void);
|
||||||
|
int nmstermio_get_rows(void);
|
||||||
|
int nmstermio_get_cols(void);
|
||||||
|
int nmstermio_get_cursor_row(void);
|
||||||
|
void nmstermio_move_cursor(int, int);
|
||||||
|
void nmstermio_print_string(char *);
|
||||||
|
void nmstermio_refresh(void);
|
||||||
|
void nmstermio_clear_input(void);
|
||||||
|
char nmstermio_get_char(void);
|
||||||
|
void nmstermio_print_reveal_string(char *, int);
|
||||||
|
void nmstermio_show_cursor(void);
|
||||||
|
void nmstermio_beep(void);
|
||||||
|
int nmstermio_get_clearscr(void);
|
||||||
|
void nmstermio_set_clearscr(int);
|
||||||
|
void nmstermio_set_foregroundcolor(char *);
|
||||||
|
int nmstermio_get_cursor_row(void);
|
||||||
|
|
||||||
|
|
||||||
|
#endif
|
@ -8,13 +8,12 @@
|
|||||||
#include <string.h>
|
#include <string.h>
|
||||||
#include <ncurses.h>
|
#include <ncurses.h>
|
||||||
|
|
||||||
// Static settings
|
|
||||||
// Static settings
|
// Static settings
|
||||||
static int clearScr = 1; // clearScr flag
|
static int clearScr = 1; // clearScr flag
|
||||||
static int foregroundColor = COLOR_BLUE; // Foreground color setting
|
static int foregroundColor = COLOR_BLUE; // Foreground color setting
|
||||||
|
|
||||||
// Initialize terminal window
|
// Initialize terminal window
|
||||||
void nmsterm_init_terminal(void) {
|
void nmstermio_init_terminal(void) {
|
||||||
initscr();
|
initscr();
|
||||||
cbreak();
|
cbreak();
|
||||||
noecho();
|
noecho();
|
||||||
@ -26,54 +25,54 @@ void nmsterm_init_terminal(void) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void nmsterm_restore_terminal(void) {
|
void nmstermio_restore_terminal(void) {
|
||||||
endwin();
|
endwin();
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* nms_term_rows() gets and returns the number of rows in the current
|
* Gets and returns the number of rows in the current
|
||||||
* terminal window.
|
* terminal window.
|
||||||
*/
|
*/
|
||||||
int nmsterm_get_rows(void) {
|
int nmstermio_get_rows(void) {
|
||||||
return getmaxy(stdscr);
|
return getmaxy(stdscr);
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* nms_term_cols() gets and returns the number of cols in the current
|
* Gets and returns the number of cols in the current
|
||||||
* terminal window.
|
* terminal window.
|
||||||
*/
|
*/
|
||||||
int nmsterm_get_cols(void) {
|
int nmstermio_get_cols(void) {
|
||||||
return getmaxx(stdscr);
|
return getmaxx(stdscr);
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* nms_get_cursor_row() returns the row position of the cursor
|
* Returns the row position of the cursor
|
||||||
*/
|
*/
|
||||||
int nmsterm_get_cursor_row(void) {
|
int nmstermio_get_cursor_row(void) {
|
||||||
return getcury(stdscr);
|
return getcury(stdscr);
|
||||||
}
|
}
|
||||||
|
|
||||||
void nmsterm_move_cursor(int y, int x) {
|
void nmstermio_move_cursor(int y, int x) {
|
||||||
move(y, x);
|
move(y, x);
|
||||||
}
|
}
|
||||||
|
|
||||||
void nmsterm_print_string(char *s) {
|
void nmstermio_print_string(char *s) {
|
||||||
addstr(s);
|
addstr(s);
|
||||||
}
|
}
|
||||||
|
|
||||||
void nmsterm_refresh(void) {
|
void nmstermio_refresh(void) {
|
||||||
refresh();
|
refresh();
|
||||||
}
|
}
|
||||||
|
|
||||||
void nmsterm_clear_input(void) {
|
void nmstermio_clear_input(void) {
|
||||||
flushinp();
|
flushinp();
|
||||||
}
|
}
|
||||||
|
|
||||||
void nmsterm_get_char(void) {
|
void nmstermio_get_char(void) {
|
||||||
getch();
|
getch();
|
||||||
}
|
}
|
||||||
|
|
||||||
void nmsterm_print_reveal_string(char *s, int colorOn) {
|
void nmstermio_print_reveal_string(char *s, int colorOn) {
|
||||||
(void) colorOn;
|
(void) colorOn;
|
||||||
(void) foregroundColor;
|
(void) foregroundColor;
|
||||||
|
|
||||||
@ -91,24 +90,24 @@ void nmsterm_print_reveal_string(char *s, int colorOn) {
|
|||||||
attroff(A_BOLD);
|
attroff(A_BOLD);
|
||||||
}
|
}
|
||||||
|
|
||||||
void nmsterm_show_cursor(void) {
|
void nmstermio_show_cursor(void) {
|
||||||
curs_set(1);
|
curs_set(1);
|
||||||
refresh();
|
refresh();
|
||||||
}
|
}
|
||||||
|
|
||||||
void nmsterm_beep(void) {
|
void nmstermio_beep(void) {
|
||||||
beep();
|
beep();
|
||||||
}
|
}
|
||||||
|
|
||||||
int nmsterm_get_clearscr(void) {
|
int nmstermio_get_clearscr(void) {
|
||||||
return clearScr;
|
return clearScr;
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* nmsterm_set_clearscr() sets the clearScr flag according to the
|
* Sets the clearScr flag according to the
|
||||||
* true/false value of the 's' argument.
|
* true/false value of the 's' argument.
|
||||||
*/
|
*/
|
||||||
void nmsterm_set_clearscr(int s) {
|
void nmstermio_set_clearscr(int s) {
|
||||||
if (s)
|
if (s)
|
||||||
clearScr = 1;
|
clearScr = 1;
|
||||||
else
|
else
|
||||||
@ -116,13 +115,13 @@ void nmsterm_set_clearscr(int s) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* nms_set_foreground_color() sets the foreground color of the unencrypted
|
* Sets the foreground color of the unencrypted
|
||||||
* characters as they are revealed to the color indicated by the 'color'
|
* characters as they are revealed to the color indicated by the 'color'
|
||||||
* argument. Valid arguments are "white", "yellow", "magenta", "blue",
|
* argument. Valid arguments are "white", "yellow", "magenta", "blue",
|
||||||
* "green", "red", and "cyan". This function will default to blue if
|
* "green", "red", and "cyan". This function will default to blue if
|
||||||
* passed an invalid color. No value is returned.
|
* passed an invalid color. No value is returned.
|
||||||
*/
|
*/
|
||||||
void nmsterm_set_foregroundcolor(char *c) {
|
void nmstermio_set_foregroundcolor(char *c) {
|
||||||
|
|
||||||
if(strcmp("white", c) == 0)
|
if(strcmp("white", c) == 0)
|
||||||
foregroundColor = COLOR_WHITE;
|
foregroundColor = COLOR_WHITE;
|
@ -10,7 +10,6 @@
|
|||||||
#include <string.h>
|
#include <string.h>
|
||||||
#include <sys/ioctl.h>
|
#include <sys/ioctl.h>
|
||||||
#include "nmseffect.h"
|
#include "nmseffect.h"
|
||||||
#include "nmsterm.h"
|
|
||||||
|
|
||||||
int main(void) {
|
int main(void) {
|
||||||
int termCols, spaces = 0;
|
int termCols, spaces = 0;
|
||||||
|
Loading…
Reference in New Issue
Block a user