History

plan9: load/save and display the filename

Sigrid Haflínudóttir committed 6 years ago

Commit c98d73f1 parent 46544df1 file · +26 −9Browse files

Unified · Split

plan9.c+26−9
@@ -31,6 +31,7 @@ static int charw, charh; · 30 unmodified lines
31static Field field;31static Field field;
32static Mbuf_reusable mbuf;32static Mbuf_reusable mbuf;
33static Oevent_list events;33static Oevent_list events;
34static char filename[256];
34 35
35static char *menu3i[] = {36static char *menu3i[] = {
36 "load",37 "load",
@@ -242,6 +243,10 @@ redraw(void) · 205 unmodified lines
242 runesprint(linebuf, "%d", bpm);243 runesprint(linebuf, "%d", bpm);
243 runestring(screen, p, display->white, ZP, font, linebuf);244 runestring(screen, p, display->white, ZP, font, linebuf);
244 245
246 /* filename */
247 p.y += font->height;
248 string(screen, p, display->white, ZP, font, filename);
249
245 /* cursor bg */250 /* cursor bg */
246 p = top;251 p = top;
247 p.x += curx*stringwidth(font, " ");252 p.x += curx*stringwidth(font, " ");
@@ -266,6 +271,18 @@ fieldload(char *path) · 18 unmodified lines
266 return 0;271 return 0;
267}272}
268 273
274static int
275fieldsave(char *path)
276{
277 FILE *f;
278
279 if ((f = fopen(path, "w")) == nil)
280 return -1;
281 field_fput(&field, f);
282 fclose(f);
283 return 0;
284}
285
269static void286static void
270fieldset(Rune key)287fieldset(Rune key)
271{288{
@@ -295,7 +312,7 @@ threadmain(int argc, char **argv) · 23 unmodified lines
295 Rune key;312 Rune key;
296 Mouse m;313 Mouse m;
297 char tmp[256];314 char tmp[256];
298 int oldw, oldh, w, h;315 int oldw, oldh, w, h, n;
299 Alt a[] = {316 Alt a[] = {
300 { nil, &m, CHANRCV },317 { nil, &m, CHANRCV },
301 { nil, nil, CHANRCV },318 { nil, nil, CHANRCV },
@@ -351,18 +368,18 @@ threadmain(int argc, char **argv) · 49 unmodified lines
351 case 2:368 case 2:
352 break;369 break;
353 case 4:370 case 4:
354 switch (menuhit(3, mctl, &menu3, nil)) {371 n = menuhit(3, mctl, &menu3, nil);
355 case 0:372 if (n == 0 || n == 1) {
356 tmp[0] = 0;373 strncpy(tmp, filename, sizeof(tmp));
357 if (enter("load file:", tmp, sizeof(tmp), mctl, kctl, nil) > 0) {374 if (enter("file path:", tmp, sizeof(tmp), mctl, kctl, nil) > 0) {
358 if (fieldload(tmp) == 0) {375 if (n == 0 && fieldload(tmp) == 0) {
359 w = field.width;376 w = field.width;
360 h = field.height;377 h = field.height;
361 } else {378 strncpy(filename, tmp, sizeof(filename));
362 /* FIXME display the error */379 } else if (n == 1 && fieldsave(tmp) == 0) {
380 strncpy(filename, tmp, sizeof(filename));
363 }381 }
364 }382 }
365 break;
366 }383 }
367 break;384 break;
368 }385 }

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t