Skip to content
This repository has been archived by the owner on Dec 10, 2023. It is now read-only.

Commit

Permalink
added current line underline.
Browse files Browse the repository at this point in the history
  • Loading branch information
MorganPeterson committed Jan 18, 2022
1 parent 2ef76d2 commit 9e772f1
Show file tree
Hide file tree
Showing 6 changed files with 146 additions and 117 deletions.
11 changes: 7 additions & 4 deletions makefile
Original file line number Diff line number Diff line change
@@ -1,10 +1,13 @@
NAME=mpe
CC=gcc
FLAGS+=-O2 -std=c11 -pedantic -W -Wall -g
CC=tcc
FLAGS+=-O2 -std=c99 -pedantic -W -Wall -g

OS:=$(shell uname -s)

LIBS=-lncursesw

ifeq ($(OS),Linux)
FLAGS+=-D_POSIX_C_SOURCE=200809L -D_XOPEN_SOURCE=700 -lncursesw
FLAGS+=-D_POSIX_C_SOURCE=200809L -D_XOPEN_SOURCE=700
endif

SRCD=src
Expand Down Expand Up @@ -161,7 +164,7 @@ $(TMO):$(TM)
$(BIND)/$(NAME):$(MN)
@echo "building $(NAME)"
@mkdir -p $(@D)
@$(CC) $(FLAGS) -o $@ $< $(OBJS)
@$(CC) $(FLAGS) -o $@ $< $(OBJS) $(LIBS)

clean:
@echo "cleaning workspace"
Expand Down
8 changes: 4 additions & 4 deletions src/commands.c
Original file line number Diff line number Diff line change
Expand Up @@ -126,10 +126,10 @@ linebegin(void)
void
lineend(void)
{
/* do nothing if EOF */
if (curbuf->point == pos(curbuf, curbuf->buf_end))
return;
curbuf->point = line_down(curbuf, curbuf->point);
/* do nothing if EOF */
if (curbuf->point == pos(curbuf, curbuf->buf_end))
return;
curbuf->point = line_down(curbuf, curbuf->point);
int32_t p = curbuf->point;
left();
curbuf->point = (*ptr(curbuf, curbuf->point) == '\n') ? curbuf->point : p;
Expand Down
24 changes: 21 additions & 3 deletions src/display.c
Original file line number Diff line number Diff line change
Expand Up @@ -125,10 +125,28 @@ display_prompt_and_response(char *prompt, char *response)
}

static void
display_character(buffer_t *b, char_t *p) {
int32_t token_type = parse_text(b, b->page_end);
display_character(buffer_t *b, char_t *p)
{
int32_t curpt = pos(b, p);
int32_t start = line_start(b, b->point);
int32_t end = segment_next(b, start, b->point)-1;
int32_t x,y;

int32_t token_type = parse_text(b, b->page_end);
attron(COLOR_PAIR(token_type));
addch(*p);

if (curpt >= start && curpt <= end)
attron(A_UNDERLINE | A_BOLD);
else
attroff(A_UNDERLINE | A_BOLD);

if (curpt == end) {
getyx(stdscr, y, x);
for (int32_t i = x; i < COLS-1; i++) {
addch(' ');
}
}
addch(*p);
}

void
Expand Down
1 change: 1 addition & 0 deletions src/header.h
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ enum {
HL_MODELINE,
HL_BACKGROUND,
HL_FOREGROUND,
HL_DIM,
};

typedef enum {
Expand Down
216 changes: 111 additions & 105 deletions src/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -22,118 +22,124 @@ char_t *scrap;
int32_t nscrap;

int32_t
main(int argc, char **argv) {
struct sigaction action;
memset(&action, 0, sizeof(action));
action.sa_handler=term_signal;
action.sa_flags=0;
sigaction(SIGTERM, &action, 0);
sigaction(SIGSEGV, &action, 0);

setlocale(LC_ALL, "");

if (initscr() == NULL)
fatal("%s: failed to initialize the screen\n");
raw();
noecho();
idlok(stdscr, 1);

TABSIZE=4;

start_color();
init_colors();

bkgd(COLOR_PAIR(HL_BACKGROUND));

if (argc > 1) {
char_t bname[BNAME_MAX];
char_t fname[FNAME_MAX];

strn_cpy(fname, (char_t*)argv[1], FNAME_MAX);
make_buffer_name(bname, fname);

curbuf = find_buffer(bname, 1);

(void)insert_file(fname, 0);
strn_cpy(curbuf->file_name, fname, FNAME_MAX);
strn_cpy(curbuf->buf_name, bname, BNAME_MAX);
select_syntax(curbuf);
} else {
curbuf = find_buffer(scratch_name, 1);
strn_cpy(curbuf->buf_name, scratch_name, BNAME_MAX);
}

headwin = curwin = new_window();
if (headwin == NULL)
die("window malloc failed", 1);

one_window(headwin);
associate_buffer_to_win(curbuf, headwin);

beginning_of_buffer();

char_t *input;
while (!done) {
update_display();
input = get_key(&key_map, &key_return);
if (key_return != NULL) {
(key_return->func)();
} else {
if (*input > 31 || *input == 0x0A || *input == 0x09) {
insert(input);
} else {
flushinp();
msg("key not bound");
}
}
}
die("QUIT", 0);
main(int argc, char **argv)
{
struct sigaction action;
memset(&action, 0, sizeof(action));
action.sa_handler=term_signal;
action.sa_flags=0;
sigaction(SIGTERM, &action, 0);
sigaction(SIGSEGV, &action, 0);

setlocale(LC_ALL, "");

if (initscr() == NULL)
fatal("%s: failed to initialize the screen\n");
raw();
noecho();
idlok(stdscr, 1);

TABSIZE=4;
if (has_colors()) {
use_default_colors();
start_color();
init_colors();
}

bkgd(COLOR_PAIR(HL_BACKGROUND));

if (argc > 1) {
char_t bname[BNAME_MAX];
char_t fname[FNAME_MAX];

strn_cpy(fname, (char_t*)argv[1], FNAME_MAX);
make_buffer_name(bname, fname);

curbuf = find_buffer(bname, 1);

(void)insert_file(fname, 0);
strn_cpy(curbuf->file_name, fname, FNAME_MAX);
strn_cpy(curbuf->buf_name, bname, BNAME_MAX);
select_syntax(curbuf);
} else {
curbuf = find_buffer(scratch_name, 1);
strn_cpy(curbuf->buf_name, scratch_name, BNAME_MAX);
}

headwin = curwin = new_window();
if (headwin == NULL)
die("window malloc failed", 1);

one_window(headwin);
associate_buffer_to_win(curbuf, headwin);

beginning_of_buffer();

char_t *input;
while (!done) {
update_display();
input = get_key(&key_map, &key_return);
if (key_return != NULL) {
(key_return->func)();
} else {
if (*input > 31 || *input == 0x0A || *input == 0x09) {
insert(input);
} else {
flushinp();
msg("key not bound");
}
}
}
die("QUIT", 0);
}

void
term_signal(int32_t n) {
switch (n) {
case SIGTERM:
die("SIGTERM", n);
break;
case SIGSEGV:
die("SIGSEGV", n);
break;
case SIGWINCH:
endwin();
refresh();
clear();
refresh();
break;
default:
die("UNKNOWN", n);
}
term_signal(int32_t n)
{
switch (n) {
case SIGTERM:
die("SIGTERM", n);
break;
case SIGSEGV:
die("SIGSEGV", n);
break;
case SIGWINCH:
endwin();
refresh();
clear();
refresh();
break;
default:
die("UNKNOWN", n);
}
}

void
die(const char *s, int32_t code) {
free_buffers();
free_windows();
if (curscr != NULL) {
move(LINES-1, 0);
refresh();
noraw();
endwin();
}
perror(s);
done = 1;
exit(code);
die(const char *s, int32_t code)
{
free_buffers();
free_windows();
if (curscr != NULL) {
move(LINES-1, 0);
refresh();
noraw();
endwin();
}
perror(s);
done = 1;
exit(code);
}

void
fatal(char *msg) {
if (curscr != NULL) {
move(LINES-1, 0);
refresh();
noraw();
endwin();
putchar('\n');
}
fprintf(stderr, msg, "editor");
exit(1);
fatal(char *msg)
{
if (curscr != NULL) {
move(LINES-1, 0);
refresh();
noraw();
endwin();
putchar('\n');
}
fprintf(stderr, msg, "editor");
exit(1);
}
3 changes: 2 additions & 1 deletion src/themes.c
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ color_t colors[] = {
void
init_colors(void)
{
init_pair(HL_BACKGROUND, colors[BRIGHTBLUE].eightbit, colors[WHITE].eightbit);
init_pair(HL_BACKGROUND, colors[BLACK].eightbit, colors[WHITE].eightbit);
init_pair(HL_NORMAL, colors[BLACK].eightbit, colors[WHITE].eightbit);
init_pair(HL_SYMBOL, colors[DARKBLUE].eightbit, colors[WHITE].eightbit);
init_pair(HL_NUMBER, colors[ORANGE].eightbit, colors[WHITE].eightbit);
Expand All @@ -54,4 +54,5 @@ init_colors(void)
init_pair(HL_MODELINE, colors[NAVY].eightbit, colors[OFFWHITE].eightbit);
init_pair(HL_KEYWORD, colors[PINK].eightbit, colors[WHITE].eightbit);
init_pair(HL_KEYWORD2, colors[PURPLE].eightbit, colors[WHITE].eightbit);
init_pair(HL_DIM, colors[BLACK].eightbit, colors[OFFWHITE].eightbit);
}

0 comments on commit 9e772f1

Please sign in to comment.