added arrows around desktop field

This commit is contained in:
cylgom 2018-06-30 10:45:03 +02:00
parent fe6fb1d84f
commit 50fdfb036b
3 changed files with 53 additions and 28 deletions

View File

@ -83,7 +83,7 @@ int main(void)
/* enables insertion mode */ /* enables insertion mode */
form_driver(form.form, REQ_INS_MODE); form_driver(form.form, REQ_INS_MODE);
/* makes the password field active by default */ /* makes the password field active by default */
set_current_field(form.form, form.fields[4]); set_current_field(form.form, form.fields[6]);
form_driver(form.form, REQ_END_LINE); form_driver(form.form, REQ_END_LINE);
while((input_key = wgetch(win.win))) while((input_key = wgetch(win.win)))
@ -93,7 +93,7 @@ int main(void)
switch(input_key) switch(input_key)
{ {
case KEY_ENTER_ASCII: case KEY_ENTER_ASCII:
if(form.active == form.fields[4]) if(form.active == form.fields[6])
{ {
/* checks for buffer errors */ /* checks for buffer errors */
if(form_driver(form.form, REQ_VALIDATION) != E_OK) if(form_driver(form.form, REQ_VALIDATION) != E_OK)
@ -103,8 +103,8 @@ int main(void)
} }
/* stores the user inputs in processing buffers */ /* stores the user inputs in processing buffers */
username = trim(field_buffer(form.fields[2], 0)); username = trim(field_buffer(form.fields[4], 0));
password = trim(field_buffer(form.fields[4], 0)); password = trim(field_buffer(form.fields[6], 0));
cmd = de_props[de_id].cmd; cmd = de_props[de_id].cmd;
type = de_props[de_id].type; type = de_props[de_id].type;
@ -119,7 +119,7 @@ int main(void)
/* logs in and suspends ncurses mode if successful */ /* logs in and suspends ncurses mode if successful */
fail = start_env(username, password, cmd, type); fail = start_env(username, password, cmd, type);
/* clears the password */ /* clears the password */
set_field_buffer(form.fields[4], 0, ""); set_field_buffer(form.fields[6], 0, "");
if(fail) if(fail)
{ {
@ -133,14 +133,14 @@ int main(void)
else if(LY_CFG_CLR_USR) else if(LY_CFG_CLR_USR)
{ {
/* clears the username */ /* clears the username */
set_field_buffer(form.fields[2], 0, ""); set_field_buffer(form.fields[4], 0, "");
/* sets cursor to the login field */ /* sets cursor to the login field */
set_current_field(form.form, form.fields[2]); set_current_field(form.form, form.fields[4]);
break; break;
} }
/* sets cursor to the password field */ /* sets cursor to the password field */
set_current_field(form.form, form.fields[4]); set_current_field(form.form, form.fields[6]);
break; break;
} }
@ -157,7 +157,7 @@ int main(void)
break; break;
case KEY_RIGHT: case KEY_RIGHT:
if(form.active == form.fields[0]) if(form.active == form.fields[1])
{ {
de_id = ((de_id + 1) == de_count) ? 0 : de_id + 1; de_id = ((de_id + 1) == de_count) ? 0 : de_id + 1;
form_driver(form.form, REQ_NEXT_CHOICE); form_driver(form.form, REQ_NEXT_CHOICE);
@ -170,7 +170,7 @@ int main(void)
break; break;
case KEY_LEFT: case KEY_LEFT:
if(form.active == form.fields[0]) if(form.active == form.fields[1])
{ {
de_id = (de_id == 0) ? (de_count - 1) : de_id - 1; de_id = (de_id == 0) ? (de_count - 1) : de_id - 1;
form_driver(form.form, REQ_PREV_CHOICE); form_driver(form.form, REQ_PREV_CHOICE);

View File

@ -39,7 +39,10 @@ void init_form(struct ncform* form, char** list, int max_de, int* de_id)
FILE* file; FILE* file;
char line[LY_LIM_LINE_FILE]; char line[LY_LIM_LINE_FILE];
char user[LY_LIM_LINE_FILE]; char user[LY_LIM_LINE_FILE];
char* arrow_left;
char arrow_right[3] = " >";
int de; int de;
int i;
/* opens the file */ /* opens the file */
file = fopen(LY_CFG_SAVE, "rb"); file = fopen(LY_CFG_SAVE, "rb");
@ -63,46 +66,66 @@ void init_form(struct ncform* form, char** list, int max_de, int* de_id)
fclose(file); fclose(file);
/* computes input padding from labels text */ /* computes input padding from labels text */
form->label_pad = max(strlen(LY_LANG_LOGIN), strlen(LY_LANG_PASSWORD)); form->label_pad = max(strlen(LY_LANG_LOGIN), strlen(LY_LANG_PASSWORD));
arrow_left = malloc((form->label_pad + 1) * (sizeof (char)));
/* adds the left arrow */
i = 0;
form->fields[i] = new_field(1, form->label_pad, 0, 0, 0, 0);
memset(arrow_left, ' ', form->label_pad);
arrow_left[form->label_pad - 2] = '<';
arrow_left[form->label_pad] = '\0';
set_field_buffer(form->fields[i], 0, arrow_left);
set_field_opts(form->fields[i], O_VISIBLE | O_PUBLIC | O_AUTOSKIP);
/* DE list */ /* DE list */
form->fields[0] = new_field(1, 32, 0, form->label_pad, 0, 0); ++i;
set_field_type(form->fields[0], TYPE_ENUM, list); form->fields[i] = new_field(1, 32, 0, form->label_pad, 0, 0);
set_field_type(form->fields[i], TYPE_ENUM, list);
if(de < max_de) if(de < max_de)
{ {
set_field_buffer(form->fields[0], 0, list[de]); set_field_buffer(form->fields[i], 0, list[de]);
*de_id = de; *de_id = de;
} }
else else
{ {
set_field_buffer(form->fields[0], 0, list[0]); set_field_buffer(form->fields[i], 0, list[0]);
*de_id = 0; *de_id = 0;
} }
set_field_opts(form->fields[0], set_field_opts(form->fields[i],
O_VISIBLE | O_PUBLIC | O_EDIT | O_ACTIVE); O_VISIBLE | O_PUBLIC | O_EDIT | O_ACTIVE);
/* adds the right arrow */
++i;
form->fields[i] = new_field(1, 2, 0, form->label_pad + 32, 0, 0);
set_field_buffer(form->fields[i], 0, arrow_right);
set_field_opts(form->fields[i], O_VISIBLE | O_PUBLIC | O_AUTOSKIP);
/* login label */ /* login label */
form->fields[1] = new_field(1, form->label_pad, 2, 0, 0, 0); ++i;
set_field_buffer(form->fields[1], 0, LY_LANG_LOGIN); form->fields[i] = new_field(1, form->label_pad, 2, 0, 0, 0);
set_field_opts(form->fields[1], O_VISIBLE | O_PUBLIC | O_AUTOSKIP); set_field_buffer(form->fields[i], 0, LY_LANG_LOGIN);
set_field_opts(form->fields[i], O_VISIBLE | O_PUBLIC | O_AUTOSKIP);
/* login field */ /* login field */
form->fields[2] = new_field(1, 32, 2, form->label_pad, 0, 0); ++i;
form->fields[i] = new_field(1, 32, 2, form->label_pad, 0, 0);
if(*user) if(*user)
{ {
set_field_buffer(form->fields[2], 0, user); set_field_buffer(form->fields[i], 0, user);
} }
set_field_opts(form->fields[2], set_field_opts(form->fields[i],
O_VISIBLE | O_PUBLIC | O_EDIT | O_ACTIVE); O_VISIBLE | O_PUBLIC | O_EDIT | O_ACTIVE);
/* password label */ /* password label */
form->fields[3] = new_field(1, form->label_pad, 4, 0, 0, 0); ++i;
set_field_buffer(form->fields[3], 0, LY_LANG_PASSWORD); form->fields[i] = new_field(1, form->label_pad, 4, 0, 0, 0);
set_field_opts(form->fields[3], O_VISIBLE | O_PUBLIC | O_AUTOSKIP); set_field_buffer(form->fields[i], 0, LY_LANG_PASSWORD);
set_field_opts(form->fields[i], O_VISIBLE | O_PUBLIC | O_AUTOSKIP);
/* password field */ /* password field */
form->fields[4] = new_field(1, 32, 4, form->label_pad, 0, 0); ++i;
set_field_opts(form->fields[4], O_VISIBLE | O_EDIT | O_ACTIVE); form->fields[i] = new_field(1, 32, 4, form->label_pad, 0, 0);
set_field_opts(form->fields[i], O_VISIBLE | O_EDIT | O_ACTIVE);
/* bound */ /* bound */
form->fields[5] = NULL; ++i;
form->fields[i] = NULL;
/* generates the form */ /* generates the form */
form->form = new_form(form->fields); form->form = new_form(form->fields);
form_opts_off(form->form, O_BS_OVERLOAD); form_opts_off(form->form, O_BS_OVERLOAD);
@ -162,4 +185,6 @@ void end_form(struct ncform* form)
free_field(form->fields[2]); free_field(form->fields[2]);
free_field(form->fields[3]); free_field(form->fields[3]);
free_field(form->fields[4]); free_field(form->fields[4]);
free_field(form->fields[5]);
free_field(form->fields[6]);
} }

View File

@ -16,7 +16,7 @@ struct ncwin
struct ncform struct ncform
{ {
FORM* form; FORM* form;
FIELD* fields[6]; FIELD* fields[8];
FIELD* active; FIELD* active;
int height; int height;
int width; int width;