commit e8bbe90094ec128b340f2a261f5c2567ee2fe11d
parent 3cdde6d19f1fae9a0e2d5e837171b32e2ec3247c
Author: Emma Weaver <emma@waeaves.com>
Date: Sun, 3 May 2026 00:07:38 -0400
Bug fixes / improved prettiness
Diffstat:
6 files changed, 34 insertions(+), 23 deletions(-)
diff --git a/.gitignore b/.gitignore
@@ -1,3 +1,4 @@
typie
*.o
+config.mk
diff --git a/config.mk b/config.mk
@@ -1,9 +0,0 @@
-# update this file to match your system's configuration.
-
-VERSION = 0.0
-
-PREFIX = /usr/local
-MANPREFIX = $(PREFIX)/share/man
-
-FLAGS = -std=c99 -pedantic -Wall -Wno-deprecated-declarations -Os
-CC = c99 $(FLAGS)
diff --git a/examples/shakespeare b/examples/shakespeare
@@ -0,0 +1 @@
+If music be the food of love, play on; Give me excess of it, that, surfeiting, The appetite may sicken, and so die. That strain again! it had a dying fall: O, it came o'er my ear like the sweet sound, That breathes upon a bank of violets, Stealing and giving odour! Enough; no more: 'Tis not so sweet now as it was before. O spirit of love! how quick and fresh art thou, That, notwithstanding thy capacity Receiveth as the sea, nought enters there, Of what validity and pitch soe'er, But falls into abatement and low price, Even in a minute: so full of shapes is fancy That it alone is high fantastical.
diff --git a/main.c b/main.c
@@ -114,14 +114,17 @@ write_output(State state)
out,
"millis %d" "\n"\
"wpm %d" "\n"\
- "accuracy %d%%" "\n",
+ "accuracy %d%%",
(int) time_millis,
wpm,
accuracy
);
- if (state.flags & FLAG_FILE)
+ if (state.flags & FLAG_FILE) {
fclose(out);
+ } else {
+ printf("\n\n");
+ }
}
int
@@ -136,19 +139,32 @@ get_length(const char * string)
return index;
}
+
+void
+init_state(State * state)
+{
+ state->flags = 0;
+ state->index = 0;
+ state->jumps.buffer = jumps_buffer;
+ state->jumps.length = 0;
+ state->line_lengths = line_lengths_buffer;
+ state->chars_printed = chars_printed_buffer;
+ state->chars_printed_index = 0;
+ state->index = 0;
+ state->row = 0;
+ state->max_row = 0;
+ state->column = 0;
+ state->line_lengths[0] = 0;
+}
+
int
main(int argc, const char * argv[])
{
struct termios termios_original;
State state;
int result;
-
- state.index = 0;
- state.jumps.buffer = jumps_buffer;
- state.jumps.length = 0;
- state.line_lengths = line_lengths_buffer;
- state.chars_printed = chars_printed_buffer;
- state.chars_printed_index = 0;
+
+ init_state(&state);
result = set_flags(&state, argc, argv);
if (result > 0) {
@@ -175,8 +191,9 @@ main(int argc, const char * argv[])
exit(1);
}
+ printf("\033[%dB", state.max_row - state.row);
restore_termios(termios_original);
- printf(COLOR_RESET);
+ printf(COLOR_RESET "\n");
write_output(state);
diff --git a/typer.c b/typer.c
@@ -79,6 +79,8 @@ wrap(State * state)
state->column = extras;
state->row++;
+ if(state->row > state->max_row)
+ state->max_row = state->row;
state->line_lengths[state->row] = 0;
}
@@ -266,10 +268,6 @@ on_enter(State * state)
void
start_typing(State * state)
{
- state->index = 0;
- state->row = 0;
- state->column = 0;
- state->line_lengths[0] = 0;
show_remaining(state);
}
diff --git a/typer.h b/typer.h
@@ -53,6 +53,9 @@ typedef struct {
int column;
int row;
+ /* so that the terminal resumes after the end of the prompt */
+ int max_row;
+
int * line_lengths;
/* for wrapping, we have to record what has been printed. */