Created
April 15, 2018 04:03
-
-
Save FlyingJester/71719209186f183775265a230c026fcb to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
include <stdlib.h> | |
#include <ncurses.h> | |
/* setting up typing function */ | |
char * nr_echo( int start_y, int start_x, int h, int w ){ | |
int ch, y, x, end_y, end_x, ch_count ; | |
int ch_count_in; | |
char *stored_line; | |
stored_line = malloc(100000); | |
ch = ch_count = 0; | |
y = start_y; | |
x = start_x; | |
end_y = start_y + h - 1; | |
end_x = start_x + w; | |
move( start_y, start_x ); | |
/* main loop, F1 quits */ | |
while (ch != KEY_F(1) ){ | |
ch = getch(); | |
/* backspace when not at the start of a line */ | |
if ( ch == KEY_BACKSPACE && x > start_x ){ | |
x--; | |
mvdelch( y, x ); | |
ch_count--; | |
} | |
/* backspace when at the start of a line */ | |
else if ( ch == KEY_BACKSPACE && x == start_x && y > start_y ){ | |
y--; | |
x = end_x; | |
mvdelch( y, x ); | |
ch_count--; | |
} | |
/* return if enter is pressed and not at bottom of field*/ | |
else if ( ch == '\n' && y <= end_y ){ | |
x = start_x; | |
y++; | |
move( y, x ); | |
stored_line[ch_count] = '\n'; | |
ch_count++; | |
} | |
/* auto return if not at bottom of field */ | |
else if ( x >= end_x && y < end_y ){ | |
x = start_x; | |
y++; | |
stored_line[ch_count] = ch; | |
mvaddch( y, x, stored_line[ch_count] ); | |
x++; | |
ch_count++; | |
} | |
/* main print */ | |
else if ( x <= end_x && y <= end_y ){ | |
stored_line[ch_count] = ch; | |
mvaddch( y, x, stored_line[ch_count] ); | |
x++; | |
ch_count++; | |
} | |
} | |
/* print the array */ | |
return stored_line; | |
} | |
int main(){ | |
FILE *fp; | |
char *save_string; | |
initscr(); /* initializes the screen */ | |
raw(); /* get raw input */ | |
keypad(stdscr, TRUE); /* get special keys */ | |
noecho(); /* we will echo manually */ | |
curs_set(2); /* sets the cursor to a solid rectangle */ | |
/* draws a nice header */ | |
/* doing this manually because i'm a savage */ | |
mvaddstr( 1, 37, "- NROGUE -" ); | |
mvaddstr( 2, 2, "F1: exit F2: save" ); | |
move( 3, 2 ); | |
/* makes a line diving header and body */ | |
{ | |
int n; | |
for ( n = 0; n < 80; n++ ) | |
addch( '_' ); | |
} | |
/* primary function call */ | |
/* starting y, starting x, height, width */ | |
save_string = nr_echo( 5, 2, 40, 80 ); | |
/* ask for file name */ | |
mvaddstr( 0, 2, "save file as:" ); | |
nr_echo( 0, 16, 1, 16 ); | |
endwin(); | |
return 0; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment