C clone of hackertyper.netUnix 'sleep' clone - unsure of safetySearch a file (simple grep clone)
lightning-datatable row number error
Does a 'pending' US visa application constitute a denial?
What is Cash Advance APR?
Why should universal income be universal?
Removing files under particular conditions (number of files, file age)
Open a doc from terminal, but not by its name
L1 and Ln cache: when are they written?
Did Swami Prabhupada reject Advaita?
What if a revenant (monster) gains fire resistance?
New brakes for 90s road bike
If infinitesimal transformations commute why dont the generators of the Lorentz group commute?
How to implement a feedback to keep the DC gain at zero for this conceptual passive filter?
How did Rebekah know that Esau was planning to kill his brother in Genesis 27:42?
How to indicate a cut out for a product window
How can Trident be so inexpensive? Will it orbit Triton or just do a (slow) flyby?
250 Floor Tower
"Spoil" vs "Ruin"
Not using 's' for he/she/it
Freedom of speech and where it applies
Multiplicative persistence
What does chmod -u do?
copy and scale one figure (wheel)
How do you make your own symbol when Detexify fails?
How could a planet have erratic days?
C clone of hackertyper.net
Unix 'sleep' clone - unsure of safetySearch a file (simple grep clone)
$begingroup$
This is a simple c clone of the website hackertyper.net. The code can be found at github.com/Hurricane996/hackertyper. Here is a local copy
Makefile
PREFIX=/usr/local
BINDIR=$(PREFIX)/bin
DATAROOTDIR=$(PREFIX)/share
DATADIR=$(DATAROOTDIR)
MAN1DIR=$(DATAROOTDIR)/man/man1
CFLAGS=-Wall -pedantic -std=c99
LDFLAGS=-lncurses
all: hackertyper
.PHONY: all clean install
hackertyper: hackertyper.o
cc -o $@ $^ $(LDFLAGS)
hackertyper.o: src/hackertyper.c
cc -c $(CFLAGS) -o $@ $^
src/hackertyper.c: src/hackertyper.h
src/hackertyper.h:src/hackertyper.h.in
sed "s@%datadir%@$(DATADIR)@g" src/hackertyper.h.in > src/hackertyper.h
clean:
rm -f hackertyper,.o src/hackertyper.h
install:
install -D -m644 data/hackertyper.txt $(DATADIR)/hackertyper.txt
install -D -m644 man/hackertyper.1 $(MAN1DIR)/hackertyper.1
install -D -m755 hackertyper $(BINDIR)/hackertyper
src/hackertyper.c
#include "hackertyper.h"
char* filename;
FILE* file;
char chars_per_nl = 1;
int main(int argc, char* argv[])
parse_args(argc, argv);
if(open_file(filename) == -1)
return -1;
init();
int clear_msg_flag = 0;
nc_color_green();
int running = 1;
while(running)
// buffer here so that buffering happens before clear_msg
int input_ch = getch();
// message was drawn last time and we need to clear it
if(clear_msg_flag)
clear_msg_flag = 0;
clear_msg();
switch(input_ch)
//C-c
case 3:
running = 0;
break;
//C-d
case 4:
clear();
nc_color_red();
draw_msg("ACCESS DENIED");
clear_msg_flag = 1;
break;
// C-g
case 7:
clear();
nc_color_green();
draw_msg("ACCESS GRANTED");
clear_msg_flag = 1;
break;
case KEY_BACKSPACE:
backspace();
break;
default:
for(int i = 0; i < 5; i++)
int output_ch = fgetc(file);
if(output_ch == EOF)
rewind(file);
output_ch = fgetc(file);
if(output_ch != 'r')
addch(output_ch);
refresh();
break;
end();
void parse_args(int argc, char* argv[])
if(argc > 1)
for(int i = 0; i < argc; i++) strcmp(argv[i], "--version") == 0)
printf(VERSION_TEXT);
exit(0);
if(strcmp(argv[i], "-f") == 0)
if(i+1 >= argc)
fprintf(stderr, HELP_TEXT);
exit(-1);
filename = argv[i+1];
int open_file(char* filename)
filename = filename ? filename : default_filename;
file = fopen(filename, "r");
return file == NULL ? -1 : 0;
void init()
initscr();
raw();
noecho();
scrollok(stdscr, true);
keypad(stdscr, true);
// check line endings
// TODO: expand this to work with endings besides n and rn
char ch;
while(ch !='n' && ch !='r')
ch = fgetc(file);
if (ch == 'r')
chars_per_nl = 2;
rewind(file);
if(has_colors())
start_color();
init_pair(1, COLOR_GREEN, COLOR_BLACK);
init_pair(2, COLOR_RED, COLOR_BLACK);
void nc_color_green()
if(has_colors())
attroff(COLOR_PAIR(2));
attron(COLOR_PAIR(1));
void nc_color_red()
if(has_colors())
attroff(COLOR_PAIR(1));
attron(COLOR_PAIR(2));
void nc_color_default()
if(has_colors())
attroff(COLOR_PAIR(1));
attroff(COLOR_PAIR(2));
void backspace()
fseek(file,-1 ,SEEK_CUR);
int x,y;
getyx(stdscr,y,x);
if(x == 0)
if( y == 0 )
return;
x = getmaxx(stdscr);
// set x to x minus 1
move(--y,--x);
char ch = ' ';
while(ch == ' ' && x != 0)
move(y,--x);
ch=inch();
fseek(file, -chars_per_nl, SEEK_CUR);
else
move(y,x-1);
delch();
// TODO: fix this shit
void draw_msg(char* msg)
int len = strlen(msg);
unsigned char hash = '#';
unsigned char space = ' ';
int w;
int h;
getmaxyx(stdscr, h, w);
move(h/2 - 2, w/2 - len/2 - 3);
for(int i = 0; i < len + 6; i ++)
addch(hash);
move(h/2 - 1, w/2 - len/2 - 3);
addch(hash);
for(int i = 0; i < len + 4; i ++)
addch(space);
addch(hash);
move(h/2, w/2 - len/2 - 3);
printw("# %s #", msg);
move(h/2 + 1, w/2 - len/2 - 3);
addch(hash);
for(int i = 0; i < len + 4; i ++)
addch(space);
addch(hash);
move(h/2 + 2, w/2 - len/2 - 3);
for(int i = 0; i < len + 6; i ++)
addch(hash);
void clear_msg()
nc_color_green();
clear();
move(0, 0);
// seek file to next line
int ch = 0;
while(ch != 'n')
ch = fgetc(file);
void end()
endwin();
fclose(file);
src/hackertyper.h.in
#include <stdio.h>
#include <stdlib.h>
#include <ncurses.h>
#include <string.h>
#define default_filename "%datadir%/hackertyper.txt"
#define HELP_TEXT "
Usage: hackertyper [-f file] [-h] [-v]n
Print text from file to stdout on pressing keys, similar to behavior of website https://www.hackertyper.org/n
n
Options:n
-f FILE, --filename FILE Print text from FILE rather than from default filen
-h, --help Print this help stringn
-v, --version Print version informationn
"
#define VERSION_TEXT "
hackertyper 2.1n
Copyright (C) 2019 Lani Willrichn
License GPLv3+: GNU GPL version 3 or later <https://gnu.org/licenses/gpl.html>n
This is free software: you are free to change and redistribute it.n
There is NO WARRANTY, to the extent permitted by law.n
Written by Lani Willrichn
"
void parse_args(int argc,char* argv[]);
int open_file(char* filename);
void init();
void nc_color_red();
void nc_color_green();
void nc_color_default();
void backspace();
void draw_msg(char* msg);
void clear_msg();
void end();
Some irrelevant files have not been listed including an auto-generated manapge and the data files
c
New contributor
Tornado547 is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
$endgroup$
add a comment |
$begingroup$
This is a simple c clone of the website hackertyper.net. The code can be found at github.com/Hurricane996/hackertyper. Here is a local copy
Makefile
PREFIX=/usr/local
BINDIR=$(PREFIX)/bin
DATAROOTDIR=$(PREFIX)/share
DATADIR=$(DATAROOTDIR)
MAN1DIR=$(DATAROOTDIR)/man/man1
CFLAGS=-Wall -pedantic -std=c99
LDFLAGS=-lncurses
all: hackertyper
.PHONY: all clean install
hackertyper: hackertyper.o
cc -o $@ $^ $(LDFLAGS)
hackertyper.o: src/hackertyper.c
cc -c $(CFLAGS) -o $@ $^
src/hackertyper.c: src/hackertyper.h
src/hackertyper.h:src/hackertyper.h.in
sed "s@%datadir%@$(DATADIR)@g" src/hackertyper.h.in > src/hackertyper.h
clean:
rm -f hackertyper,.o src/hackertyper.h
install:
install -D -m644 data/hackertyper.txt $(DATADIR)/hackertyper.txt
install -D -m644 man/hackertyper.1 $(MAN1DIR)/hackertyper.1
install -D -m755 hackertyper $(BINDIR)/hackertyper
src/hackertyper.c
#include "hackertyper.h"
char* filename;
FILE* file;
char chars_per_nl = 1;
int main(int argc, char* argv[])
parse_args(argc, argv);
if(open_file(filename) == -1)
return -1;
init();
int clear_msg_flag = 0;
nc_color_green();
int running = 1;
while(running)
// buffer here so that buffering happens before clear_msg
int input_ch = getch();
// message was drawn last time and we need to clear it
if(clear_msg_flag)
clear_msg_flag = 0;
clear_msg();
switch(input_ch)
//C-c
case 3:
running = 0;
break;
//C-d
case 4:
clear();
nc_color_red();
draw_msg("ACCESS DENIED");
clear_msg_flag = 1;
break;
// C-g
case 7:
clear();
nc_color_green();
draw_msg("ACCESS GRANTED");
clear_msg_flag = 1;
break;
case KEY_BACKSPACE:
backspace();
break;
default:
for(int i = 0; i < 5; i++)
int output_ch = fgetc(file);
if(output_ch == EOF)
rewind(file);
output_ch = fgetc(file);
if(output_ch != 'r')
addch(output_ch);
refresh();
break;
end();
void parse_args(int argc, char* argv[])
if(argc > 1)
for(int i = 0; i < argc; i++) strcmp(argv[i], "--version") == 0)
printf(VERSION_TEXT);
exit(0);
if(strcmp(argv[i], "-f") == 0)
if(i+1 >= argc)
fprintf(stderr, HELP_TEXT);
exit(-1);
filename = argv[i+1];
int open_file(char* filename)
filename = filename ? filename : default_filename;
file = fopen(filename, "r");
return file == NULL ? -1 : 0;
void init()
initscr();
raw();
noecho();
scrollok(stdscr, true);
keypad(stdscr, true);
// check line endings
// TODO: expand this to work with endings besides n and rn
char ch;
while(ch !='n' && ch !='r')
ch = fgetc(file);
if (ch == 'r')
chars_per_nl = 2;
rewind(file);
if(has_colors())
start_color();
init_pair(1, COLOR_GREEN, COLOR_BLACK);
init_pair(2, COLOR_RED, COLOR_BLACK);
void nc_color_green()
if(has_colors())
attroff(COLOR_PAIR(2));
attron(COLOR_PAIR(1));
void nc_color_red()
if(has_colors())
attroff(COLOR_PAIR(1));
attron(COLOR_PAIR(2));
void nc_color_default()
if(has_colors())
attroff(COLOR_PAIR(1));
attroff(COLOR_PAIR(2));
void backspace()
fseek(file,-1 ,SEEK_CUR);
int x,y;
getyx(stdscr,y,x);
if(x == 0)
if( y == 0 )
return;
x = getmaxx(stdscr);
// set x to x minus 1
move(--y,--x);
char ch = ' ';
while(ch == ' ' && x != 0)
move(y,--x);
ch=inch();
fseek(file, -chars_per_nl, SEEK_CUR);
else
move(y,x-1);
delch();
// TODO: fix this shit
void draw_msg(char* msg)
int len = strlen(msg);
unsigned char hash = '#';
unsigned char space = ' ';
int w;
int h;
getmaxyx(stdscr, h, w);
move(h/2 - 2, w/2 - len/2 - 3);
for(int i = 0; i < len + 6; i ++)
addch(hash);
move(h/2 - 1, w/2 - len/2 - 3);
addch(hash);
for(int i = 0; i < len + 4; i ++)
addch(space);
addch(hash);
move(h/2, w/2 - len/2 - 3);
printw("# %s #", msg);
move(h/2 + 1, w/2 - len/2 - 3);
addch(hash);
for(int i = 0; i < len + 4; i ++)
addch(space);
addch(hash);
move(h/2 + 2, w/2 - len/2 - 3);
for(int i = 0; i < len + 6; i ++)
addch(hash);
void clear_msg()
nc_color_green();
clear();
move(0, 0);
// seek file to next line
int ch = 0;
while(ch != 'n')
ch = fgetc(file);
void end()
endwin();
fclose(file);
src/hackertyper.h.in
#include <stdio.h>
#include <stdlib.h>
#include <ncurses.h>
#include <string.h>
#define default_filename "%datadir%/hackertyper.txt"
#define HELP_TEXT "
Usage: hackertyper [-f file] [-h] [-v]n
Print text from file to stdout on pressing keys, similar to behavior of website https://www.hackertyper.org/n
n
Options:n
-f FILE, --filename FILE Print text from FILE rather than from default filen
-h, --help Print this help stringn
-v, --version Print version informationn
"
#define VERSION_TEXT "
hackertyper 2.1n
Copyright (C) 2019 Lani Willrichn
License GPLv3+: GNU GPL version 3 or later <https://gnu.org/licenses/gpl.html>n
This is free software: you are free to change and redistribute it.n
There is NO WARRANTY, to the extent permitted by law.n
Written by Lani Willrichn
"
void parse_args(int argc,char* argv[]);
int open_file(char* filename);
void init();
void nc_color_red();
void nc_color_green();
void nc_color_default();
void backspace();
void draw_msg(char* msg);
void clear_msg();
void end();
Some irrelevant files have not been listed including an auto-generated manapge and the data files
c
New contributor
Tornado547 is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
$endgroup$
add a comment |
$begingroup$
This is a simple c clone of the website hackertyper.net. The code can be found at github.com/Hurricane996/hackertyper. Here is a local copy
Makefile
PREFIX=/usr/local
BINDIR=$(PREFIX)/bin
DATAROOTDIR=$(PREFIX)/share
DATADIR=$(DATAROOTDIR)
MAN1DIR=$(DATAROOTDIR)/man/man1
CFLAGS=-Wall -pedantic -std=c99
LDFLAGS=-lncurses
all: hackertyper
.PHONY: all clean install
hackertyper: hackertyper.o
cc -o $@ $^ $(LDFLAGS)
hackertyper.o: src/hackertyper.c
cc -c $(CFLAGS) -o $@ $^
src/hackertyper.c: src/hackertyper.h
src/hackertyper.h:src/hackertyper.h.in
sed "s@%datadir%@$(DATADIR)@g" src/hackertyper.h.in > src/hackertyper.h
clean:
rm -f hackertyper,.o src/hackertyper.h
install:
install -D -m644 data/hackertyper.txt $(DATADIR)/hackertyper.txt
install -D -m644 man/hackertyper.1 $(MAN1DIR)/hackertyper.1
install -D -m755 hackertyper $(BINDIR)/hackertyper
src/hackertyper.c
#include "hackertyper.h"
char* filename;
FILE* file;
char chars_per_nl = 1;
int main(int argc, char* argv[])
parse_args(argc, argv);
if(open_file(filename) == -1)
return -1;
init();
int clear_msg_flag = 0;
nc_color_green();
int running = 1;
while(running)
// buffer here so that buffering happens before clear_msg
int input_ch = getch();
// message was drawn last time and we need to clear it
if(clear_msg_flag)
clear_msg_flag = 0;
clear_msg();
switch(input_ch)
//C-c
case 3:
running = 0;
break;
//C-d
case 4:
clear();
nc_color_red();
draw_msg("ACCESS DENIED");
clear_msg_flag = 1;
break;
// C-g
case 7:
clear();
nc_color_green();
draw_msg("ACCESS GRANTED");
clear_msg_flag = 1;
break;
case KEY_BACKSPACE:
backspace();
break;
default:
for(int i = 0; i < 5; i++)
int output_ch = fgetc(file);
if(output_ch == EOF)
rewind(file);
output_ch = fgetc(file);
if(output_ch != 'r')
addch(output_ch);
refresh();
break;
end();
void parse_args(int argc, char* argv[])
if(argc > 1)
for(int i = 0; i < argc; i++) strcmp(argv[i], "--version") == 0)
printf(VERSION_TEXT);
exit(0);
if(strcmp(argv[i], "-f") == 0)
if(i+1 >= argc)
fprintf(stderr, HELP_TEXT);
exit(-1);
filename = argv[i+1];
int open_file(char* filename)
filename = filename ? filename : default_filename;
file = fopen(filename, "r");
return file == NULL ? -1 : 0;
void init()
initscr();
raw();
noecho();
scrollok(stdscr, true);
keypad(stdscr, true);
// check line endings
// TODO: expand this to work with endings besides n and rn
char ch;
while(ch !='n' && ch !='r')
ch = fgetc(file);
if (ch == 'r')
chars_per_nl = 2;
rewind(file);
if(has_colors())
start_color();
init_pair(1, COLOR_GREEN, COLOR_BLACK);
init_pair(2, COLOR_RED, COLOR_BLACK);
void nc_color_green()
if(has_colors())
attroff(COLOR_PAIR(2));
attron(COLOR_PAIR(1));
void nc_color_red()
if(has_colors())
attroff(COLOR_PAIR(1));
attron(COLOR_PAIR(2));
void nc_color_default()
if(has_colors())
attroff(COLOR_PAIR(1));
attroff(COLOR_PAIR(2));
void backspace()
fseek(file,-1 ,SEEK_CUR);
int x,y;
getyx(stdscr,y,x);
if(x == 0)
if( y == 0 )
return;
x = getmaxx(stdscr);
// set x to x minus 1
move(--y,--x);
char ch = ' ';
while(ch == ' ' && x != 0)
move(y,--x);
ch=inch();
fseek(file, -chars_per_nl, SEEK_CUR);
else
move(y,x-1);
delch();
// TODO: fix this shit
void draw_msg(char* msg)
int len = strlen(msg);
unsigned char hash = '#';
unsigned char space = ' ';
int w;
int h;
getmaxyx(stdscr, h, w);
move(h/2 - 2, w/2 - len/2 - 3);
for(int i = 0; i < len + 6; i ++)
addch(hash);
move(h/2 - 1, w/2 - len/2 - 3);
addch(hash);
for(int i = 0; i < len + 4; i ++)
addch(space);
addch(hash);
move(h/2, w/2 - len/2 - 3);
printw("# %s #", msg);
move(h/2 + 1, w/2 - len/2 - 3);
addch(hash);
for(int i = 0; i < len + 4; i ++)
addch(space);
addch(hash);
move(h/2 + 2, w/2 - len/2 - 3);
for(int i = 0; i < len + 6; i ++)
addch(hash);
void clear_msg()
nc_color_green();
clear();
move(0, 0);
// seek file to next line
int ch = 0;
while(ch != 'n')
ch = fgetc(file);
void end()
endwin();
fclose(file);
src/hackertyper.h.in
#include <stdio.h>
#include <stdlib.h>
#include <ncurses.h>
#include <string.h>
#define default_filename "%datadir%/hackertyper.txt"
#define HELP_TEXT "
Usage: hackertyper [-f file] [-h] [-v]n
Print text from file to stdout on pressing keys, similar to behavior of website https://www.hackertyper.org/n
n
Options:n
-f FILE, --filename FILE Print text from FILE rather than from default filen
-h, --help Print this help stringn
-v, --version Print version informationn
"
#define VERSION_TEXT "
hackertyper 2.1n
Copyright (C) 2019 Lani Willrichn
License GPLv3+: GNU GPL version 3 or later <https://gnu.org/licenses/gpl.html>n
This is free software: you are free to change and redistribute it.n
There is NO WARRANTY, to the extent permitted by law.n
Written by Lani Willrichn
"
void parse_args(int argc,char* argv[]);
int open_file(char* filename);
void init();
void nc_color_red();
void nc_color_green();
void nc_color_default();
void backspace();
void draw_msg(char* msg);
void clear_msg();
void end();
Some irrelevant files have not been listed including an auto-generated manapge and the data files
c
New contributor
Tornado547 is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
$endgroup$
This is a simple c clone of the website hackertyper.net. The code can be found at github.com/Hurricane996/hackertyper. Here is a local copy
Makefile
PREFIX=/usr/local
BINDIR=$(PREFIX)/bin
DATAROOTDIR=$(PREFIX)/share
DATADIR=$(DATAROOTDIR)
MAN1DIR=$(DATAROOTDIR)/man/man1
CFLAGS=-Wall -pedantic -std=c99
LDFLAGS=-lncurses
all: hackertyper
.PHONY: all clean install
hackertyper: hackertyper.o
cc -o $@ $^ $(LDFLAGS)
hackertyper.o: src/hackertyper.c
cc -c $(CFLAGS) -o $@ $^
src/hackertyper.c: src/hackertyper.h
src/hackertyper.h:src/hackertyper.h.in
sed "s@%datadir%@$(DATADIR)@g" src/hackertyper.h.in > src/hackertyper.h
clean:
rm -f hackertyper,.o src/hackertyper.h
install:
install -D -m644 data/hackertyper.txt $(DATADIR)/hackertyper.txt
install -D -m644 man/hackertyper.1 $(MAN1DIR)/hackertyper.1
install -D -m755 hackertyper $(BINDIR)/hackertyper
src/hackertyper.c
#include "hackertyper.h"
char* filename;
FILE* file;
char chars_per_nl = 1;
int main(int argc, char* argv[])
parse_args(argc, argv);
if(open_file(filename) == -1)
return -1;
init();
int clear_msg_flag = 0;
nc_color_green();
int running = 1;
while(running)
// buffer here so that buffering happens before clear_msg
int input_ch = getch();
// message was drawn last time and we need to clear it
if(clear_msg_flag)
clear_msg_flag = 0;
clear_msg();
switch(input_ch)
//C-c
case 3:
running = 0;
break;
//C-d
case 4:
clear();
nc_color_red();
draw_msg("ACCESS DENIED");
clear_msg_flag = 1;
break;
// C-g
case 7:
clear();
nc_color_green();
draw_msg("ACCESS GRANTED");
clear_msg_flag = 1;
break;
case KEY_BACKSPACE:
backspace();
break;
default:
for(int i = 0; i < 5; i++)
int output_ch = fgetc(file);
if(output_ch == EOF)
rewind(file);
output_ch = fgetc(file);
if(output_ch != 'r')
addch(output_ch);
refresh();
break;
end();
void parse_args(int argc, char* argv[])
if(argc > 1)
for(int i = 0; i < argc; i++) strcmp(argv[i], "--version") == 0)
printf(VERSION_TEXT);
exit(0);
if(strcmp(argv[i], "-f") == 0)
if(i+1 >= argc)
fprintf(stderr, HELP_TEXT);
exit(-1);
filename = argv[i+1];
int open_file(char* filename)
filename = filename ? filename : default_filename;
file = fopen(filename, "r");
return file == NULL ? -1 : 0;
void init()
initscr();
raw();
noecho();
scrollok(stdscr, true);
keypad(stdscr, true);
// check line endings
// TODO: expand this to work with endings besides n and rn
char ch;
while(ch !='n' && ch !='r')
ch = fgetc(file);
if (ch == 'r')
chars_per_nl = 2;
rewind(file);
if(has_colors())
start_color();
init_pair(1, COLOR_GREEN, COLOR_BLACK);
init_pair(2, COLOR_RED, COLOR_BLACK);
void nc_color_green()
if(has_colors())
attroff(COLOR_PAIR(2));
attron(COLOR_PAIR(1));
void nc_color_red()
if(has_colors())
attroff(COLOR_PAIR(1));
attron(COLOR_PAIR(2));
void nc_color_default()
if(has_colors())
attroff(COLOR_PAIR(1));
attroff(COLOR_PAIR(2));
void backspace()
fseek(file,-1 ,SEEK_CUR);
int x,y;
getyx(stdscr,y,x);
if(x == 0)
if( y == 0 )
return;
x = getmaxx(stdscr);
// set x to x minus 1
move(--y,--x);
char ch = ' ';
while(ch == ' ' && x != 0)
move(y,--x);
ch=inch();
fseek(file, -chars_per_nl, SEEK_CUR);
else
move(y,x-1);
delch();
// TODO: fix this shit
void draw_msg(char* msg)
int len = strlen(msg);
unsigned char hash = '#';
unsigned char space = ' ';
int w;
int h;
getmaxyx(stdscr, h, w);
move(h/2 - 2, w/2 - len/2 - 3);
for(int i = 0; i < len + 6; i ++)
addch(hash);
move(h/2 - 1, w/2 - len/2 - 3);
addch(hash);
for(int i = 0; i < len + 4; i ++)
addch(space);
addch(hash);
move(h/2, w/2 - len/2 - 3);
printw("# %s #", msg);
move(h/2 + 1, w/2 - len/2 - 3);
addch(hash);
for(int i = 0; i < len + 4; i ++)
addch(space);
addch(hash);
move(h/2 + 2, w/2 - len/2 - 3);
for(int i = 0; i < len + 6; i ++)
addch(hash);
void clear_msg()
nc_color_green();
clear();
move(0, 0);
// seek file to next line
int ch = 0;
while(ch != 'n')
ch = fgetc(file);
void end()
endwin();
fclose(file);
src/hackertyper.h.in
#include <stdio.h>
#include <stdlib.h>
#include <ncurses.h>
#include <string.h>
#define default_filename "%datadir%/hackertyper.txt"
#define HELP_TEXT "
Usage: hackertyper [-f file] [-h] [-v]n
Print text from file to stdout on pressing keys, similar to behavior of website https://www.hackertyper.org/n
n
Options:n
-f FILE, --filename FILE Print text from FILE rather than from default filen
-h, --help Print this help stringn
-v, --version Print version informationn
"
#define VERSION_TEXT "
hackertyper 2.1n
Copyright (C) 2019 Lani Willrichn
License GPLv3+: GNU GPL version 3 or later <https://gnu.org/licenses/gpl.html>n
This is free software: you are free to change and redistribute it.n
There is NO WARRANTY, to the extent permitted by law.n
Written by Lani Willrichn
"
void parse_args(int argc,char* argv[]);
int open_file(char* filename);
void init();
void nc_color_red();
void nc_color_green();
void nc_color_default();
void backspace();
void draw_msg(char* msg);
void clear_msg();
void end();
Some irrelevant files have not been listed including an auto-generated manapge and the data files
c
c
New contributor
Tornado547 is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
New contributor
Tornado547 is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
New contributor
Tornado547 is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
asked 11 mins ago
Tornado547Tornado547
1011
1011
New contributor
Tornado547 is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
New contributor
Tornado547 is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
Tornado547 is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
add a comment |
add a comment |
0
active
oldest
votes
Your Answer
StackExchange.ifUsing("editor", function ()
return StackExchange.using("mathjaxEditing", function ()
StackExchange.MarkdownEditor.creationCallbacks.add(function (editor, postfix)
StackExchange.mathjaxEditing.prepareWmdForMathJax(editor, postfix, [["\$", "\$"]]);
);
);
, "mathjax-editing");
StackExchange.ifUsing("editor", function ()
StackExchange.using("externalEditor", function ()
StackExchange.using("snippets", function ()
StackExchange.snippets.init();
);
);
, "code-snippets");
StackExchange.ready(function()
var channelOptions =
tags: "".split(" "),
id: "196"
;
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function()
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled)
StackExchange.using("snippets", function()
createEditor();
);
else
createEditor();
);
function createEditor()
StackExchange.prepareEditor(
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: false,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: null,
bindNavPrevention: true,
postfix: "",
imageUploader:
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
,
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
);
);
Tornado547 is a new contributor. Be nice, and check out our Code of Conduct.
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fcodereview.stackexchange.com%2fquestions%2f216082%2fc-clone-of-hackertyper-net%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
0
active
oldest
votes
0
active
oldest
votes
active
oldest
votes
active
oldest
votes
Tornado547 is a new contributor. Be nice, and check out our Code of Conduct.
Tornado547 is a new contributor. Be nice, and check out our Code of Conduct.
Tornado547 is a new contributor. Be nice, and check out our Code of Conduct.
Tornado547 is a new contributor. Be nice, and check out our Code of Conduct.
Thanks for contributing an answer to Code Review Stack Exchange!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
Use MathJax to format equations. MathJax reference.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fcodereview.stackexchange.com%2fquestions%2f216082%2fc-clone-of-hackertyper-net%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown