stew

a monorepo of some sort
Log | Files | Refs

commit b365d0f4a6832b9e4a34fe5e5c6a3f1281a9bd6c
parent 4527308533b5f09c3a0c383177be6a93312471df
Author: Renev Pavel <an2qzavok@gmail.com>
Date:   Sat,  3 Dec 2022 20:40:25 +0000

tabul: sync

Diffstat:
Msrc/tabul/tabul.c | 47++++++++++++++++++++++++++++++++++-------------
1 file changed, 34 insertions(+), 13 deletions(-)

diff --git a/src/tabul/tabul.c b/src/tabul/tabul.c @@ -46,6 +46,7 @@ void resizeview(Rectangle r); void clearview(void); void setview(Point xy, char *s); char ** getview(Point xy); +void _cell(Image *screen, Rectangle r, Image *brd, Image *bg, Image *fg, int t, Font *font, char *text); void loadfile(char *newfile) @@ -80,30 +81,46 @@ savefile(char *newfile) fprint(2, "savefile: %r\n"); return; } + Biobuf *b = Bfdopen(fd, OWRITE); free(file); file = newfile; int x, y; for (y = view.r.min.y; y < view.r.max.y; y++) { for (x = view.r.min.x; x < view.r.max.x; x++) { char **v = getview(Pt(x, y)); - if (x != view.r.min.x) fprint(fd, "\t"); - if ((v != nil) && (*v != nil)) fprint(fd, "%s", *v); + if (x != view.r.min.x) Bprint(b, "\t"); + if ((v != nil) && (*v != nil)) Bprint(b, "%s", *v); } - fprint(fd, "\n"); + Bprint(b, "\n"); } - close(fd); + Bterm(b); +} + +void +_cell(Image *screen, Rectangle r, Image *brd, Image *bg, Image *fg, int t, Font *font, char *text) +{ + Rectangle r2 = insetrect(r, t); + int n = strlen(text); + while (stringnwidth(font, text, n) > Dx(r2)) n--; + draw(screen, r, brd, nil, ZP); + draw(screen, r2, bg, nil, ZP); + stringn(screen, addpt(r2.min, Pt(1,(Dy(r2) - font->height)/2)), fg, ZP, font, text, n); } void drawcell(Point xy) { Image *cellbg = bg; - if (eqpt(xy, cur) != 0) cellbg = curbg; + char *s = ""; + int t = 1; + if (eqpt(xy, cur) != 0) { + t = 2; + cellbg = curbg; + } Rectangle r = rectaddpt(cell, addpt(Pt(xy.x * cell.max.x, xy.y * cell.max.y), cells.min)); - draw(screen, r, bord, nil, ZP); - draw(screen, insetrect(r, 1), cellbg, nil, ZP); char **v = getview(xy); - if ((v != nil) && (*v != nil)) stringn(screen, addpt(r.min, Pt(3, 3)), text, ZP, font, *v, 8); + if ((v != nil) && (*v != nil)) s = *v; + _cell(screen, r, bord, cellbg, text, t, font, s); } void @@ -136,7 +153,7 @@ colors(void) bord = display->black; text = display->black; bg = display->white; - curbg = allocimage(display, Rect(0,0,1,1), XRGB32, 1, 0xffffaaff); + curbg = allocimage(display, Rect(0,0,1,1), XRGB32, 1, 0xddddddff); } void @@ -192,7 +209,11 @@ kbd(Rune r) threadexitsall(nil); case 0x0a: /* newline */ flushedit(); + cur.y++; + setedit(); + drawedit(); drawcell(cur); + drawcell(subpt(cur, Pt(0,1))); flushimage(display, 1); break; case 0x09: /* tab */ @@ -201,7 +222,7 @@ kbd(Rune r) setedit(); drawedit(); drawcell(cur); - drawcell(subpt(cur, Pt(1,1))); + drawcell(subpt(cur, Pt(1,0))); flushimage(display, 1); break; case 0x08: /* backspace */ @@ -298,12 +319,12 @@ drawedit(void) { char buf[256]; snprint(buf, 16, "[%d %d] ", cur.x, cur.y); - draw(screen, edit.r, curbg, nil, ZP); - Point p = edit.r.min; if (edit.str != nil) { strncat(buf, s_to_c(edit.str), 256 - strlen(buf)); } - string(screen, p, text, ZP, font, buf); + _cell(screen, edit.r, bord, bg, text, 1, font, buf); + //draw(screen, edit.r, curbg, nil, ZP); + //string(screen, p, text, ZP, font, buf); } void