Modified!

This commit is contained in:
Andrew Pamment 2021-12-14 21:42:16 +10:00
parent 4a0558d24f
commit 0aa48c58e2
5 changed files with 23 additions and 22 deletions

View File

@ -1,13 +1,13 @@
# makefile for text.c
CC=gcc
CFLAGS=-Wall -g
CC=i686-quinn-gcc
CFLAGS=-Wall
OBJS=text.o page.o line.o prompt.o
HEADERS=$(subst .o,.h,$(OBJS)) # text.h page.h ...
LIBS=-lncurses
LIBS=-lpdcurses -lSDL -lquinn -lfreetype -lpng -lz
text: $(OBJS)
$(CC) $(CFLAGS) -o text $(OBJS) $(LIBS)
$(CC) $(CFLAGS) -o text.exe $(OBJS) $(LIBS)
text.o: text.c $(HEADERS)
$(CC) $(CFLAGS) -c text.c
@ -24,7 +24,7 @@ page.o: page.c page.h line.h
cleanall: clean cleantxt
clean:
rm -f $(OBJS) text
rm -f $(OBJS) text.exe
cleantxt:
rm -f *.txt

2
page.h
View File

@ -2,7 +2,7 @@
#define PAGE_H
/* PAGE struct definition and related functions */
#include <ncurses.h> // might have to move this
#include <curses.h> // might have to move this
#include "line.h"
#define PAGE_SIZE 500 /* Default number of lines */

View File

@ -1,7 +1,7 @@
#ifndef PROMPT_H
#define PROMPT_H
#include <ncurses.h>
#include <curses.h>
#include <string.h>
#define PROMPT_STRING_LINES 5

27
text.c
View File

@ -11,7 +11,7 @@
int y_offset = 0; // TODO: move to local scope
int tab_offset = 0;
#define DEBUG
// #define DEBUG
void print_loc(int x, int y)
{
@ -48,7 +48,7 @@ int main(int argc, char *argv[])
/* curses interface */
initscr();
noecho();
keypad(stdscr, true);
keypad(stdscr, 1);
int beg = 0;
int end = WIN_SIZE;
@ -56,19 +56,18 @@ int main(int argc, char *argv[])
int i;
update_status("Press F4 to quit");
update_status(page.filename, "");
print_page(&page, beg, end);
getyx(stdscr, y, x);
char status[NAME_LIMIT + 10];
while(true)
while(1)
{
print_loc(x, y);
beg = 0 + y_offset;
end = WIN_SIZE + y_offset;
int ch = getch();
update_status("Press F4 to quit"); // default text
update_status(page.filename, ""); // default text
switch(ch)
{
case KEY_F(4):
@ -78,15 +77,13 @@ int main(int argc, char *argv[])
break;
case KEY_F(5):
save_file(&page);
sprintf(status, "Saved as \'%s\'", page.filename);
update_status(status);
update_status(page.filename, "Saved!");
break;
case KEY_F(6):
prompt_string("Save As:", page.filename, NAME_LIMIT);
save_file(&page);
sprintf(status, "Saved as \'%s\'", page.filename);
print_page(&page, beg, end);
update_status(status);
update_status(page.filename, "Saved!");
break;
case KEY_UP:
move_up(&page, &x, &y);
@ -103,6 +100,7 @@ int main(int argc, char *argv[])
case KEY_DC:
case 127: // backspace key...
case KEY_BACKSPACE:
case '\b':
if(strlen(page.text[y + y_offset].line) == 0)
{ // can only delete blank lines for now
remove_line(&page, y + y_offset);
@ -146,14 +144,17 @@ endnc:
} // main
// prints a message at the bottom of the window
void update_status(char *info)
void update_status(char *filename, char *info)
{
int oldy, oldx; getyx(stdscr, oldy, oldx);
char status[81];
snprintf(status, 80, "F4: Quit F5: Save F6: Save As File: %-25.25s %s", filename, info);
attron(A_REVERSE);
move(LINES - 1, 0);
clrtoeol();
printw(info);
printw(status);
attroff(A_REVERSE);
move(oldy, oldx);

4
text.h
View File

@ -5,12 +5,12 @@
#include <stdlib.h> // declared in line.h
#include <ctype.h>
#include <string.h> // declared in line.h
#include <ncurses.h> // -lncurses. declared in page.h
#include <curses.h> // -lncurses. declared in page.h
#include "page.h"
#include "prompt.h"
void update_status(char *info);
void update_status(char *filename, char *info);
int count_lines(FILE *fp);
void load_file(PAGE *p, char* filename);