freebsd-dev/sbin/sysinstall/ourcurses.c
Poul-Henning Kamp 9c354a29e7 Public apology:
I have walked all over Paul Richards code again, and severely lobotomized
some of his stuff, in order to cut some corners for the 2.0-Alpha release.
I belive that we can now manipulate fdisk and disklabel-stuff sufficiently
for the release to actually be produced.
It's not that I don't like Paul and his code, I just need something I
can kick out of the door RSN.

Sysinstall is now under absolute code-freeze, only Jordan has my permission
to commit to this code (stage0 & 5).  I would appreciate if everybody
else would finds problems in sysinstall send patches to me, and I will
commit them. THANKYOU.

The fdisk/disklabel editors are made in pure ncurses, and follow a model
"a`la spreadsheet".

There are some important functions which are missing still, and I would
appreciate if somebody would look at them.
The FDISK part needs a "whole-disk" option, and it needs a "rewrite
MBR-boot code" option.
The DISKLABEL part needs to be able to "import DOS-partition".
Both need a "HELP" function, (display a file "/HELP" using dialog is OK).

It seems to me like the wd.c and sd.c should reread the physical record
when a DIOCGDINFO is made, so that they can pick up changes in the
MBR-data.  Otherwise there will be a couple of weird cases where we
cannot avoid replicating code from the kernel.

If you want to play with this, look at src/release/Makefile.  You may need
to step back to version 1.38 of sys/i386/isa/fd.c to make "rootable"
floppies, it is not clear at this time if that indeed is the problem I
have been having.

Sleep well, my friends, and expect the real Alpha in 24H, if the tree is
still solid.
1994-11-01 10:10:43 +00:00

171 lines
3.0 KiB
C

/* Stopgap, until Paul does the right thing */
#define ESC 27
#define TAB 9
#include <stdlib.h>
#include <limits.h>
#include <sys/types.h>
#include <string.h>
#include <string.h>
#include <dialog.h>
#include "sysinstall.h"
int
edit_line(WINDOW *window, int y, int x, char *field, int width, int maxlen)
{
int len;
int key = 0;
int fpos, dispos, curpos;
int i;
int done = 0;
len = strlen(field);
if (len < width) {
fpos = len;
curpos = len;
dispos = 0;
} else {
fpos = width;
curpos = width;
dispos = len - width;
};
do {
wattrset(window, item_selected_attr);
wmove(window, y, x);
for (i=0; i < width; i++)
if (i < (len - dispos))
waddch(window, field[dispos+i]);
else
waddch(window, ' ');
wmove(window, y, x + curpos);
wrefresh(window);
key = wgetch(window);
switch (key) {
case TAB:
case KEY_BTAB:
case KEY_UP:
case KEY_DOWN:
case ESC:
case '\n':
case '\r':
done = 1;
break;
case KEY_HOME:
if (len < width) {
fpos = len;
curpos = len;
dispos = 0;
} else {
fpos = width;
curpos = width;
dispos = len - width;
};
break;
case KEY_END:
if (len < width) {
dispos = 0;
curpos = len - 1;
} else {
dispos = len - width - 1;
curpos = width - 1;
}
fpos = len - 1;
break;
case KEY_LEFT:
if ((!curpos) && (!dispos)) {
beep();
break;
}
if (--curpos < 0) {
curpos = 0;
if (--dispos < 0)
dispos = 0;
}
if (--fpos < 0)
fpos = 0;
break;
case KEY_RIGHT:
if ((curpos + dispos) == len) {
beep();
break;
}
if ((curpos == (width-1)) && (dispos == (maxlen - width -1))) {
beep();
break;
}
if (++curpos >= width) {
curpos = width - 1;
dispos++;
}
if (dispos >= len)
dispos = len - 1;
if (++fpos >= len) {
fpos = len;
}
break;
case KEY_BACKSPACE:
case KEY_DC:
if ((!curpos) && (!dispos)) {
beep();
break;
}
if (fpos > 0) {
memmove(field+fpos-1, field+fpos, len - fpos);
len--;
fpos--;
if (curpos > 0)
--curpos;
if (!curpos)
--dispos;
if (dispos < 0)
dispos = 0;
} else
beep();
break;
default:
if (len < maxlen - 1) {
memmove(field+fpos+1, field+fpos, len - fpos);
field[fpos] = key;
len++;
fpos++;
if (++curpos == width) {
--curpos;
dispos++;
}
if (len == (maxlen - 1)) {
dispos = (maxlen - width - 1);
}
} else
beep();
break;
}
} while (!done);
wattrset(window, dialog_attr);
wmove(window, y, x);
for (i=0; i < width; i++)
if (i < (len - dispos))
waddch(window, field[dispos+i]);
else
waddch(window, ' ');
wmove(window, y, x + curpos);
wrefresh(window);
field[len] = 0;
delwin(window);
refresh();
return (key);
}
int
AskEm(WINDOW *w,char *prompt, char *answer, int len)
{
int x,y;
mvwprintw(w,23,0,prompt);
wclrtoeol(w);
getyx(w,y,x);
return edit_line(w,y,x,answer,len,len+1);
}