mirror of https://github.com/fairyglade/ly.git
added arrows around desktop field
This commit is contained in:
parent
fe6fb1d84f
commit
50fdfb036b
20
src/main.c
20
src/main.c
|
@ -83,7 +83,7 @@ int main(void)
|
|||
/* enables insertion mode */
|
||||
form_driver(form.form, REQ_INS_MODE);
|
||||
/* 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);
|
||||
|
||||
while((input_key = wgetch(win.win)))
|
||||
|
@ -93,7 +93,7 @@ int main(void)
|
|||
switch(input_key)
|
||||
{
|
||||
case KEY_ENTER_ASCII:
|
||||
if(form.active == form.fields[4])
|
||||
if(form.active == form.fields[6])
|
||||
{
|
||||
/* checks for buffer errors */
|
||||
if(form_driver(form.form, REQ_VALIDATION) != E_OK)
|
||||
|
@ -103,8 +103,8 @@ int main(void)
|
|||
}
|
||||
|
||||
/* stores the user inputs in processing buffers */
|
||||
username = trim(field_buffer(form.fields[2], 0));
|
||||
password = trim(field_buffer(form.fields[4], 0));
|
||||
username = trim(field_buffer(form.fields[4], 0));
|
||||
password = trim(field_buffer(form.fields[6], 0));
|
||||
cmd = de_props[de_id].cmd;
|
||||
type = de_props[de_id].type;
|
||||
|
||||
|
@ -119,7 +119,7 @@ int main(void)
|
|||
/* logs in and suspends ncurses mode if successful */
|
||||
fail = start_env(username, password, cmd, type);
|
||||
/* clears the password */
|
||||
set_field_buffer(form.fields[4], 0, "");
|
||||
set_field_buffer(form.fields[6], 0, "");
|
||||
|
||||
if(fail)
|
||||
{
|
||||
|
@ -133,14 +133,14 @@ int main(void)
|
|||
else if(LY_CFG_CLR_USR)
|
||||
{
|
||||
/* clears the username */
|
||||
set_field_buffer(form.fields[2], 0, "");
|
||||
set_field_buffer(form.fields[4], 0, "");
|
||||
/* sets cursor to the login field */
|
||||
set_current_field(form.form, form.fields[2]);
|
||||
set_current_field(form.form, form.fields[4]);
|
||||
break;
|
||||
}
|
||||
|
||||
/* sets cursor to the password field */
|
||||
set_current_field(form.form, form.fields[4]);
|
||||
set_current_field(form.form, form.fields[6]);
|
||||
break;
|
||||
}
|
||||
|
||||
|
@ -157,7 +157,7 @@ int main(void)
|
|||
break;
|
||||
|
||||
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;
|
||||
form_driver(form.form, REQ_NEXT_CHOICE);
|
||||
|
@ -170,7 +170,7 @@ int main(void)
|
|||
break;
|
||||
|
||||
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;
|
||||
form_driver(form.form, REQ_PREV_CHOICE);
|
||||
|
|
59
src/ncui.c
59
src/ncui.c
|
@ -39,7 +39,10 @@ void init_form(struct ncform* form, char** list, int max_de, int* de_id)
|
|||
FILE* file;
|
||||
char line[LY_LIM_LINE_FILE];
|
||||
char user[LY_LIM_LINE_FILE];
|
||||
char* arrow_left;
|
||||
char arrow_right[3] = " >";
|
||||
int de;
|
||||
int i;
|
||||
|
||||
/* opens the file */
|
||||
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);
|
||||
/* computes input padding from labels text */
|
||||
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 */
|
||||
form->fields[0] = new_field(1, 32, 0, form->label_pad, 0, 0);
|
||||
set_field_type(form->fields[0], TYPE_ENUM, list);
|
||||
++i;
|
||||
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)
|
||||
{
|
||||
set_field_buffer(form->fields[0], 0, list[de]);
|
||||
set_field_buffer(form->fields[i], 0, list[de]);
|
||||
*de_id = de;
|
||||
}
|
||||
else
|
||||
{
|
||||
set_field_buffer(form->fields[0], 0, list[0]);
|
||||
set_field_buffer(form->fields[i], 0, list[0]);
|
||||
*de_id = 0;
|
||||
}
|
||||
|
||||
set_field_opts(form->fields[0],
|
||||
set_field_opts(form->fields[i],
|
||||
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 */
|
||||
form->fields[1] = new_field(1, form->label_pad, 2, 0, 0, 0);
|
||||
set_field_buffer(form->fields[1], 0, LY_LANG_LOGIN);
|
||||
set_field_opts(form->fields[1], O_VISIBLE | O_PUBLIC | O_AUTOSKIP);
|
||||
++i;
|
||||
form->fields[i] = new_field(1, form->label_pad, 2, 0, 0, 0);
|
||||
set_field_buffer(form->fields[i], 0, LY_LANG_LOGIN);
|
||||
set_field_opts(form->fields[i], O_VISIBLE | O_PUBLIC | O_AUTOSKIP);
|
||||
/* 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)
|
||||
{
|
||||
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);
|
||||
/* password label */
|
||||
form->fields[3] = new_field(1, form->label_pad, 4, 0, 0, 0);
|
||||
set_field_buffer(form->fields[3], 0, LY_LANG_PASSWORD);
|
||||
set_field_opts(form->fields[3], O_VISIBLE | O_PUBLIC | O_AUTOSKIP);
|
||||
++i;
|
||||
form->fields[i] = new_field(1, form->label_pad, 4, 0, 0, 0);
|
||||
set_field_buffer(form->fields[i], 0, LY_LANG_PASSWORD);
|
||||
set_field_opts(form->fields[i], O_VISIBLE | O_PUBLIC | O_AUTOSKIP);
|
||||
/* password field */
|
||||
form->fields[4] = new_field(1, 32, 4, form->label_pad, 0, 0);
|
||||
set_field_opts(form->fields[4], O_VISIBLE | O_EDIT | O_ACTIVE);
|
||||
++i;
|
||||
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 */
|
||||
form->fields[5] = NULL;
|
||||
++i;
|
||||
form->fields[i] = NULL;
|
||||
/* generates the form */
|
||||
form->form = new_form(form->fields);
|
||||
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[3]);
|
||||
free_field(form->fields[4]);
|
||||
free_field(form->fields[5]);
|
||||
free_field(form->fields[6]);
|
||||
}
|
||||
|
|
|
@ -16,7 +16,7 @@ struct ncwin
|
|||
struct ncform
|
||||
{
|
||||
FORM* form;
|
||||
FIELD* fields[6];
|
||||
FIELD* fields[8];
|
||||
FIELD* active;
|
||||
int height;
|
||||
int width;
|
||||
|
|
Loading…
Reference in New Issue