]> git.mdlowis.com Git - projs/tide.git/commitdiff
checkpoint commit for tide command execution
authorMichael D. Lowis <mike.lowis@gentex.com>
Fri, 22 Nov 2019 03:00:13 +0000 (22:00 -0500)
committerMichael D. Lowis <mike.lowis@gentex.com>
Fri, 22 Nov 2019 03:00:13 +0000 (22:00 -0500)
config.h
inc/edit.h
src/lib/draw.c
src/lib/job.c
src/lib/view.c
src/lib/xpty.c
src/tide.c

index 4b9023def11144ad6200359ccaed3926c92e1f7a..9f7b532b626aa857d8cf563dbce51ce01094bee3 100644 (file)
--- 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 */
index d50783a2da0957403371ffeaa71d3b65092154ae..651742735c6f1e475d4bd6e2ae9c091cbca78a4d 100644 (file)
@@ -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);
index d9a14b6caf01cb07dd64528c9cba846466ce8eae..a5755f565b332f21bd1e3fca39c1a7d3a37ee726 100644 (file)
@@ -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);
index 2c0bbbfe6254bb7ad34c5741b26f4d44ea9c1793..08f1c8c4f9891a1a94d57a39e2a5c6ea97af7932 100644 (file)
@@ -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);
     }
 }
 
index 40de89e21735a022b0a18c1de1d4536d49fa0ab3..87e24e107b7fdc2143de4cef5862e86c59d83db5 100644 (file)
@@ -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);
index c165d34dec9ee8fa9ba9d8a5bb872b445030fe81..d551149d1f2c214d6139cd88c890a03f9d301030 100644 (file)
@@ -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);
index 5143166e3b647be8a086394d6f6cabb3de986095..b13302c21cdd752bf8902122403945e66e226b33 100644 (file)
@@ -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);
 }