env["CFLAGS"] += %w[-g]
env["CPPPATH"] += %w[. inc]
env["LIBPATH"] += %w[.]
+ env["LIBS"] += ["util"]
# env["CPPFLAGS"] << "-DNDEBUG"
## STAGING
+* fetch: don't exit on rulesets with no launch or exec rules
* picktag: reimplement in C using binary search
* fetch: add option to capture output of command
* fetch: handle quotes around second arg
EditBg, EditFg, EditSel,
TagsBg, TagsFg, TagsSel,
ScrollBg, ScrollFg,
- VerBdr, HorBdr, WinBdr,
+ VerBdr, HorBdr, Point,
ClrCount
};
[ScrollFg] = 0xF0F0E5, /* Scroll region foreground */
[VerBdr] = 0x909047, /* Vertical border */
[HorBdr] = 0x000000, /* Horizontal border */
- [WinBdr] = 0x000000, /* Window border */
+ [Point] = 0x98BE8F, /* Window border */
};
#pragma GCC diagnostic pop
EditLog log; /* underlying log of edit operations */
Sel selection; /* the currently selected text */
Sel point; /* tracks external command I/O */
+ void (*oninsert)(int byte);
} Buf;
enum {
void buf_selln(Buf* buf);
void buf_selclr(Buf* buf, int dir);
bool buf_insel(Buf* buf, size_t off);
+bool buf_inpoint(Buf* buf, size_t off);
void buf_selword(Buf* buf, bool (*isword)(Rune));
void buf_selall(Buf* buf);
void buf_selctx(Buf* buf, bool (*isword)(Rune));
bool xpty_active(void);
int xpty_run(View* view, char** cmd);
-void xpty_send(uint32_t key);
size_t beg = buf_selbeg(buf);
if (s && *s)
{
- while (*s)
+ for (; *s; s++)
{
- putch(buf, *(s++), &(buf->selection));
+ putch(buf, *s, &(buf->selection));
+ if (buf->oninsert)
+ {
+ buf->oninsert(*s);
+ }
}
editlog_add(buf, beg, buf_selend(buf), NULL);
}
size_t nbytes = sel.end - sel.beg;
if (nbytes > 0)
{
+ /* adjust the point according to the characters deleted */
+ size_t bpoint = ((sel.beg <= buf->point.beg) ? (buf->point.beg - sel.beg) : 0u);
+ size_t inpoint = (min(buf->point.end, sel.end) - max(buf->point.beg, sel.beg));
+ buf->point.beg -= bpoint;
+ buf->point.end -= (bpoint + inpoint);
+
+ /* perform the delete */
buf->status = MODIFIED;
char* str = buf_gets(buf);
gapbuf_del(&buf->contents, sel.beg, nbytes);
- sel.end = sel.beg = (sel.beg < sel.end ? sel.beg : sel.end);
- if (sel.end <= buf->point.beg)
- {
- buf->point.beg -= (buf->point.beg - sel.end);
- }
- if (sel.end <= buf->point.end)
- {
- buf->point.end -= (buf->point.end - sel.end);
- }
+ sel.end = sel.beg;
buf->selection = sel;
editlog_add(buf, sel.beg, sel.end, str);
}
return (off >= buf_selbeg(buf) && off < buf_selend(buf));
}
+bool buf_inpoint(Buf* buf, size_t off)
+{
+ require(buf != NULL);
+ bool empty_point = (buf->point.beg == buf->point.end) && (off == buf->point.beg);
+ bool in_range = (off >= buf->point.beg && off < buf->point.end);
+ return (buf->oninsert && (empty_point || in_range));
+}
+
char* buf_fetch(Buf* buf, bool (*isword)(Rune), size_t off)
{
require(buf != NULL);
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, TagsBg, 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)
#include <stdc.h>
#include <utf.h>
#include <edit.h>
+#include <io.h>
#include <sys/socket.h>
#ifdef __linux__
#include <pty.h>
static View* EditView = NULL;
static int Pty_Fd = -1;
+static void putb(int byte)
+{
+ if (byte == '\n')
+ {
+ char* str = buf_getsat(&(EditView->buffer), EditView->buffer.point.beg, EditView->buffer.point.end);
+ EditView->buffer.point.beg = EditView->buffer.point.end;
+ writefd(Pty_Fd, str, strlen(str));
+ free(str);
+ }
+}
+
static void xpty_read(Job* job)
{
char buffer[16385];
{
job->readfn = NULL;
Pty_Fd = -1;
+ EditView->buffer.oninsert = NULL;
EditView = NULL;
}
else if (nread > 0)
{
-// &while [ 1 ]; do sleep 1; echo foo; done
buffer[nread] = '\0';
-// printf("B1 - E: %lu P: %lu-%lu S: %lu-%lu\n",
-// buf_end(&(EditView->buffer)),
-// EditView->buffer.point.beg, EditView->buffer.point.end,
-// EditView->buffer.selection.beg, EditView->buffer.selection.end);
-
+ /* swap the point and selection to perform the insert */
size_t start = EditView->buffer.point.beg;
- Sel sel = EditView->buffer.selection;
+ Sel sel = {
+ .col = EditView->buffer.selection.col,
+ .beg = buf_selbeg(&(EditView->buffer)),
+ .end = buf_selend(&(EditView->buffer))
+ };
EditView->buffer.selection.beg = EditView->buffer.point.beg;
EditView->buffer.selection.end = EditView->buffer.point.beg;
EditView->buffer.point = sel;
-// printf("B2 - E: %lu P: %lu-%lu S: %lu-%lu\n",
-// buf_end(&(EditView->buffer)),
-// EditView->buffer.point.beg, EditView->buffer.point.end,
-// EditView->buffer.selection.beg, EditView->buffer.selection.end);
-
+ /* insert the text */
+ EditView->buffer.oninsert = NULL;
view_putstr(EditView, buffer);
+ EditView->buffer.oninsert = putb;
+ /* adjust the original selection and swap it back */
+ nread = (EditView->buffer.point.end - start);
if (start <= sel.beg)
{
- sel.beg += nread-1;
+ sel.beg += nread;
}
if (start <= sel.end)
{
- sel.end += nread-1;
+ sel.end += nread;
}
Sel point = EditView->buffer.selection;
EditView->buffer.selection = sel;
EditView->buffer.point = point;
-
-// printf("A - E: %lu P: %lu-%lu S: %lu-%lu\n",
-// buf_end(&(EditView->buffer)),
-// EditView->buffer.point.beg, EditView->buffer.point.end,
-// EditView->buffer.selection.beg, EditView->buffer.selection.end);
}
}
EditView = view;
if (view_selsize(view))
{
-// puts("delete");
view_delete(view, LEFT, false);
}
-// printf("S - E: %lu P: %lu-%lu S: %lu-%lu\n",
-// buf_end(&(EditView->buffer)),
-// EditView->buffer.point.beg, EditView->buffer.point.end,
-// EditView->buffer.selection.beg, EditView->buffer.selection.end);
+ view->buffer.oninsert = putb;
+ struct termios tio;
+ tcgetattr(Pty_Fd, &tio);
+ tio.c_lflag &= ~(ECHO | ECHONL);
+ tio.c_cc[ VMIN ] = 1;
+ tio.c_cc[ VTIME ] = 0;
+ tcsetattr(Pty_Fd, TCSANOW, &tio);
job_spawn(Pty_Fd, xpty_read, NULL, NULL);
}
}
return fd;
}
-
-void xpty_send(uint32_t key)
-{
- view_insert(EditView, key);
-// printf("%lu-%lu\n", EditView->buffer.point.beg, EditView->buffer.point.end);
-}
telem_send("KEY(reg: %d, key: 0x%x)\n", Focused, key);
if (key != RUNE_ERR)
{
- if (Focused == EDIT && xpty_active())
- {
- xpty_send(key);
- }
- else
- {
- view_insert(win_view(FOCUSED), key);
- }
+ view_insert(win_view(FOCUSED), key);
}
}