From: Michael D. Lowis Date: Fri, 22 Nov 2019 03:00:13 +0000 (-0500) Subject: checkpoint commit for tide command execution X-Git-Url: https://git.mdlowis.com/?a=commitdiff_plain;h=c6513ec989a04544e561dbb2d3037536d03dce64;p=projs%2Ftide.git checkpoint commit for tide command execution --- diff --git a/config.h b/config.h index 4b9023d..9f7b532 100644 --- a/config.h +++ b/config.h @@ -73,7 +73,7 @@ static int Palette[ClrCount] = { [ScrollFg] = 0xFFFFEA, /* Scroll region foreground */ [VerBdr] = 0x99994C, /* Vertical border */ [HorBdr] = 0x000000, /* Horizontal border */ - [Point] = 0xFFFFFF, /* Point background */ + [Point] = 0xEFEFDA, /* Point background */ [Purple] = 0x6666CC, /* Purple */ [Red] = 0xCC0000, /* Red */ [Orange] = 0xFF7700, /* Orange */ diff --git a/inc/edit.h b/inc/edit.h index d50783a..6517427 100644 --- a/inc/edit.h +++ b/inc/edit.h @@ -171,6 +171,7 @@ void view_undo(View* view); void view_redo(View* view); void view_paste(View* view, char* str); void view_putstr(View* view, char* str); +void view_putraw(View* view, char* str); char* view_getstr(View* view); char* view_getcmd(View* view); char* view_getword(View* view); diff --git a/src/lib/draw.c b/src/lib/draw.c index d9a14b6..a5755f5 100644 --- a/src/lib/draw.c +++ b/src/lib/draw.c @@ -42,27 +42,35 @@ void draw_view(XConf* x, View* view, XftFont* font, size_t nrows, drawcsr* csr, { Row* row = view_getrow(view, i + view->index); size_t posx = (csr->x + 2), y = (csr->y + 2 + (i * fheight)); - for (size_t i = 0; i < row->len; i++) + if (row->off == buf_end(&(view->buffer))) { - int rune = row->cols[i].rune; - if (rune == '\r' || rune == '\n' || rune == '\t') - rune = ' '; - if (buf_inpoint(&(view->buffer), row->cols[i].off)) - draw_rect(x, Point, posx, y, row->cols[i].width, fheight); - if (buf_insel(&(view->buffer), row->cols[i].off)) - draw_rect(x, sel, posx, y, row->cols[i].width, fheight); - if (row->cols[i].off == view->buffer.selection.end) - csr_drawn = draw_csr(x, view, fg, fheight, posx, y, csr_drawn); - if (csrsync && row->cols[i].off == view->buffer.selection.beg) + draw_csr(x, view, fg, fheight, posx, y, csr_drawn); + break; + } + else + { + for (size_t i = 0; i < row->len; i++) { - XWarpPointer(x->display, None, x->self, 0, 0, x->width, x->height, posx + row->cols[i].width/2, y + fheight*3/4); - csrsync = false; + int rune = row->cols[i].rune; + if (rune == '\r' || rune == '\n' || rune == '\t') + rune = ' '; + if (buf_inpoint(&(view->buffer), row->cols[i].off)) + draw_rect(x, Point, posx, y, row->cols[i].width, fheight); + if (buf_insel(&(view->buffer), row->cols[i].off)) + draw_rect(x, sel, posx, y, row->cols[i].width, fheight); + if (row->cols[i].off == view->buffer.selection.end) + csr_drawn = draw_csr(x, view, fg, fheight, posx, y, csr_drawn); + if (csrsync && row->cols[i].off == view->buffer.selection.beg) + { + XWarpPointer(x->display, None, x->self, 0, 0, x->width, x->height, posx + row->cols[i].width/2, y + fheight*3/4); + csrsync = false; + } + specs = realloc(specs, sizeof(XftGlyphSpec) * ++nspecs); + specs[nspecs-1].glyph = XftCharIndex(x->display, font, rune); + specs[nspecs-1].x = posx; + specs[nspecs-1].y = y + font->ascent; + posx += row->cols[i].width; } - specs = realloc(specs, sizeof(XftGlyphSpec) * ++nspecs); - specs[nspecs-1].glyph = XftCharIndex(x->display, font, rune); - specs[nspecs-1].x = posx; - specs[nspecs-1].y = y + font->ascent; - posx += row->cols[i].width; } } x11_draw_glyphs(x, Palette[fg], font, specs, nspecs); diff --git a/src/lib/job.c b/src/lib/job.c index 2c0bbbf..08f1c8c 100644 --- a/src/lib/job.c +++ b/src/lib/job.c @@ -41,7 +41,7 @@ static void pipe_read(Job* job) { buffer[nread] = '\0'; buf_logstart(&pipedata->dest->buffer); - view_putstr(pipedata->dest, buffer); + view_putraw(pipedata->dest, buffer); } } diff --git a/src/lib/view.c b/src/lib/view.c index 40de89e..87e24e1 100644 --- a/src/lib/view.c +++ b/src/lib/view.c @@ -507,6 +507,15 @@ void view_putstr(View* view, char* str) ensure(view_valid(view)); } +void view_putraw(View* view, char* str) +{ + void (*fn)(int) = BUF->oninsert; + BUF->oninsert = NULL; + buf_puts(BUF, str); + BUF->oninsert = fn; + ensure(view_valid(view)); +} + char* view_getstr(View* view) { return buf_gets(BUF); diff --git a/src/lib/xpty.c b/src/lib/xpty.c index c165d34..d551149 100644 --- a/src/lib/xpty.c +++ b/src/lib/xpty.c @@ -14,10 +14,11 @@ static int Pty_Fd = -1; static void putb(int byte) { - if (byte == '\n') + if (byte == '\n' && buf_inpoint(&(EditView->buffer), EditView->buffer.selection.end-1)) { char* str = buf_getsat(&(EditView->buffer), EditView->buffer.point.beg, EditView->buffer.point.end); EditView->buffer.point.beg = EditView->buffer.point.end; + printf("write '%s'\n", str); writefd(Pty_Fd, str, strlen(str)); free(str); } @@ -50,9 +51,7 @@ static void xpty_read(Job* job) EditView->buffer.point = sel; /* insert the text */ - EditView->buffer.oninsert = NULL; - view_putstr(EditView, buffer); - EditView->buffer.oninsert = putb; + view_putraw(EditView, buffer); /* adjust the original selection and swap it back */ nread = (EditView->buffer.point.end - start); diff --git a/src/tide.c b/src/tide.c index 5143166..b13302c 100644 --- a/src/tide.c +++ b/src/tide.c @@ -440,53 +440,46 @@ static Tag* tag_lookup(char* cmd) static void cmd_exec(char* cmd) { - if (xpty_active()) + /* parse the command sigils */ + char op = '\0', **execcmd = NULL; + if (rissigil(*cmd)) op = *(cmd++); + execcmd = (op == ':' ? SedCmd : ShellCmd); + execcmd[2] = cmd; + + /* get the selection that the command will operate on */ + if (op && op != '<' && op != '!' && op != '&' && !view_selsize(win_view(EDIT))) { - xpty_send(cmd); + view_selectall(win_view(EDIT)); } - else - { - /* parse the command sigils */ - char op = '\0', **execcmd = NULL; - if (rissigil(*cmd)) op = *(cmd++); - execcmd = (op == ':' ? SedCmd : ShellCmd); - execcmd[2] = cmd; - - /* get the selection that the command will operate on */ - if (op && op != '<' && op != '!' && op != '&' && !view_selsize(win_view(EDIT))) - { - view_selectall(win_view(EDIT)); - } - char* input = view_getstr(win_view(EDIT)); - size_t len = (input ? strlen(input) : 0); - View *tags = win_view(TAGS), *edit = win_view(EDIT), *curr = win_view(FOCUSED); + char* input = view_getstr(win_view(EDIT)); + size_t len = (input ? strlen(input) : 0); + View *tags = win_view(TAGS), *edit = win_view(EDIT), *curr = win_view(FOCUSED); - /* execute the job */ - if (op == '!' || op == '&') - { - free(input); - if (op == '&') - { - xpty_run(win_view(EDIT), execcmd); - } - else - { - job_start(execcmd, NULL, 0, NULL); - } - } - else if (op == '>') - { - job_start(execcmd, input, len, tags); - } - else if (op == '|' || op == ':') + /* execute the job */ + if (op == '!' || op == '&') + { + free(input); + if (op == '&') { - job_start(execcmd, input, len, edit); + xpty_run(win_view(EDIT), execcmd); } else { - job_start(execcmd, input, len, (op != '<' ? curr : edit)); + job_start(execcmd, NULL, 0, NULL); } } + else if (op == '>') + { + job_start(execcmd, input, len, tags); + } + else if (op == '|' || op == ':') + { + job_start(execcmd, input, len, edit); + } + else + { + job_start(execcmd, input, len, (op != '<' ? curr : edit)); + } } static void exec(char* cmd, char* arg) @@ -582,7 +575,17 @@ static void execute(char* arg) { (void)arg; char* str = view_getcmd(win_view(FOCUSED)); - if (str) exec(str, NULL); + if (str) + { + if (xpty_active()) + { + xpty_send(str); + } + else + { + exec(str, NULL); + } + } free(str); }