Add a prompt
This commit is contained in:
parent
1025c25eb9
commit
44e09d1662
1
.gitignore
vendored
Normal file → Executable file
1
.gitignore
vendored
Normal file → Executable file
@ -2,3 +2,4 @@
|
||||
*.o
|
||||
*.txt
|
||||
text
|
||||
text.exe
|
||||
|
9
makefile
9
makefile
@ -2,13 +2,13 @@
|
||||
|
||||
CC=gcc
|
||||
CFLAGS=-Wall -g
|
||||
OBJS=text.o page.o line.o
|
||||
OBJS=text.o page.o line.o prompt.o
|
||||
LIBS=-lncurses
|
||||
|
||||
text: $(OBJS)
|
||||
$(CC) $(CFLAGS) -o text $(OBJS) $(LIBS)
|
||||
$(CC) $(CFLAGS) -o text.exe $(OBJS) $(LIBS)
|
||||
|
||||
text.o: text.c text.h page.h line.h
|
||||
text.o: text.c text.h page.h line.h prompt.h
|
||||
$(CC) $(CFLAGS) -c text.c
|
||||
|
||||
page.o: page.c page.h line.h
|
||||
@ -17,5 +17,8 @@ page.o: page.c page.h line.h
|
||||
line.o: line.c line.h
|
||||
$(CC) $(CFLAGS) -c line.c
|
||||
|
||||
prompt.o: prompt.c prompt.h
|
||||
$(CC) $(CFLAGS) -c prompt.c
|
||||
|
||||
clean:
|
||||
rm -f $(OBJS) text
|
||||
|
33
prompt.c
Normal file
33
prompt.c
Normal file
@ -0,0 +1,33 @@
|
||||
#include "prompt.h"
|
||||
|
||||
void prompt_string(const char *message, char *name)
|
||||
{
|
||||
echo();
|
||||
WINDOW *prompt = subwin(stdscr, PROMPT_LINES, PROMPT_COLS,
|
||||
center_y(PROMPT_LINES), center_x(PROMPT_COLS));
|
||||
mvwprintw(prompt, 1, 1, message);
|
||||
box(prompt, 0, 0);
|
||||
wmove(prompt, PROMPT_OFFY, PROMPT_OFFX);
|
||||
|
||||
wattron(prompt, A_REVERSE);
|
||||
wprintw(prompt, " ");
|
||||
wmove(prompt, PROMPT_OFFY, PROMPT_OFFX);
|
||||
wgetstr(prompt, name);
|
||||
wattroff(prompt, A_REVERSE);
|
||||
|
||||
wborder(prompt, ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ');
|
||||
werase(prompt);
|
||||
wrefresh(prompt);
|
||||
delwin(prompt);
|
||||
noecho();
|
||||
}
|
||||
|
||||
int center_x(int width)
|
||||
{
|
||||
return (COLS - width) / 2;
|
||||
}
|
||||
|
||||
int center_y(int height)
|
||||
{
|
||||
return (LINES - height) / 2;
|
||||
}
|
17
prompt.h
Normal file
17
prompt.h
Normal file
@ -0,0 +1,17 @@
|
||||
#ifndef PROMPT_H
|
||||
#define PROMPT_H
|
||||
|
||||
#include <ncurses.h>
|
||||
#include <string.h>
|
||||
|
||||
#define PROMPT_LINES 5
|
||||
#define PROMPT_COLS 20
|
||||
|
||||
#define PROMPT_OFFX 1
|
||||
#define PROMPT_OFFY 3
|
||||
|
||||
void prompt_string(const char *message, char *name);
|
||||
int center_x(int width);
|
||||
int center_y(int height);
|
||||
|
||||
#endif
|
8
text.c
8
text.c
@ -53,6 +53,7 @@ int main(int argc, char *argv[])
|
||||
print_page(&page, beg, end);
|
||||
getyx(stdscr, y, x);
|
||||
|
||||
char status[NAME_LIMIT + 10];
|
||||
while(true)
|
||||
{
|
||||
beg = 0 + y_offset;
|
||||
@ -66,7 +67,12 @@ int main(int argc, char *argv[])
|
||||
break;
|
||||
case KEY_F(5):
|
||||
save_file(argc, argv, &page);
|
||||
char status[NAME_LIMIT + 10];
|
||||
sprintf(status, "Saved as \'%s\'", page.filename);
|
||||
update_status(status);
|
||||
break;
|
||||
case KEY_F(6):
|
||||
prompt_string("Save As:", page.filename);
|
||||
save_file(argc, argv, &page);
|
||||
sprintf(status, "Saved as \'%s\'", page.filename);
|
||||
update_status(status);
|
||||
break;
|
||||
|
Loading…
x
Reference in New Issue
Block a user