ref: d0df10c1ad637b550cea8e7dfd538d1f02e9fc0a
parent: e508450a625b0841b0825387b57be011ab89e1c5
author: sirjofri <[email protected]>
date: Thu Jul 4 11:48:27 EDT 2024
adds error output, better dirty tracking, allow to save files without preamble
--- a/README
+++ b/README
@@ -38,6 +38,10 @@
## GUI mode
+### Mouse control
+
+- RMB click on a cell to edit it
+
### Keyboard control
- Use the arrow keys (←↑↓→) to scroll
@@ -59,10 +63,6 @@
- To enter a string/text, don't start the line with an `=` sign.
Simple as that.
-
-### TODO
-
-- click to edit. Click on a cell to open the edit dialog.
## CLI mode
--- a/engine.c
+++ b/engine.c
@@ -425,7 +425,8 @@
}
}
- Bprint(bout, "%s", preamble);
+ if (preamble)
+ Bprint(bout, "%s", preamble);
Bprint(bout, "%%%%%%\n");
foreachcell(writecell, bout);
--- a/spread.c
+++ b/spread.c
@@ -13,6 +13,9 @@
exits("usage");
}
+char Ebadcmd[] = "bad command";
+char Ebadaddr[] = "bad address";
+
typedef struct Colors Colors;
struct Colors {
Image *bg;
@@ -80,18 +83,29 @@
Event ev;
char *file = nil;
int dirty = 0;
+char *error = nil;
void
-drawfile(void)
+drawtopline(void)
{
char filebuf[25];
char *f;
+ Point p;
+ int w;
f = strrchr(file, '/');
f = f ? f+1 : file;
snprint(filebuf, sizeof(filebuf), "%s%s", f, dirty ? "*" : "");
- string(screen, addpt(screen->r.min, Pt(4, 4)), display->black, ZP, font, filebuf);
+ p = addpt(screen->r.min, Pt(4, 4));
+ string(screen, p, display->black, ZP, font, filebuf);
+
+ if (!error)
+ return;
+
+ w = stringwidth(font, error);
+ p.x = screen->r.max.x - w - 4;
+ string(screen, p, colors.err, ZP, font, error);
}
void
@@ -110,7 +124,7 @@
draw(screen, screen->r, colors.bg, nil, ZP);
- drawfile();
+ drawtopline();
dstate.r = insetrect(screen->r, 4);
dstate.r.min.y += font->height * 2;
@@ -194,6 +208,7 @@
{
int type;
char *s;
+ Cell *c;
type = STRING;
s = value;
@@ -202,6 +217,14 @@
s += 1;
}
+ if (c = getcell(p)) {
+ if (c->type == type && strcmp(c->value, s) == 0)
+ return;
+ }
+
+ if (!s[0])
+ return;
+
addcell(p, s, type);
updatecells();
dirty = 1;
@@ -259,14 +282,12 @@
break;
}
if (n != 2) {
- /* TODO: error, bad command */
- fprint(2, "error: bad command\n");
+ error = Ebadcmd;
break;
}
p = atop(args[1]);
if (p.x < 1) {
- /* TODO: error, bad address */
- fprint(2, "error: bad address\n");
+ error = Ebadaddr;
break;
}
go(p);
@@ -273,14 +294,12 @@
break;
case 's': /* set command */
if (n != 2) {
- /* TODO: error: bad command */
- fprint(2, "error: bad command\n");
+ error = Ebadcmd;
break;
}
p = atop(args[1]);
if (p.x < 1) {
- /* TODO: error, bad address */
- fprint(2, "error: bad address\n");
+ error = Ebadaddr;
break;
}
edit(p);
@@ -297,8 +316,7 @@
dirty = 0;
break;
}
- /* TODO: error, bad command */
- fprint(2, "error: bad command\n");
+ error = Ebadcmd;
break;
}
}
@@ -410,8 +428,6 @@
if (argc != 1)
usage();
-
- fprint(2, "pid=%d\n", getpid());
file = *argv;