From 50fdfb036b4dee5d77aff13b95f0666189e23961 Mon Sep 17 00:00:00 2001 From: cylgom Date: Sat, 30 Jun 2018 10:45:03 +0200 Subject: [PATCH] added arrows around desktop field --- src/main.c | 20 +++++++++--------- src/ncui.c | 59 ++++++++++++++++++++++++++++++++++++++---------------- src/ncui.h | 2 +- 3 files changed, 53 insertions(+), 28 deletions(-) diff --git a/src/main.c b/src/main.c index 5ce9f0c..03ce1c1 100644 --- a/src/main.c +++ b/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); diff --git a/src/ncui.c b/src/ncui.c index 568d7a1..14bd4a7 100644 --- a/src/ncui.c +++ b/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]); } diff --git a/src/ncui.h b/src/ncui.h index e72810a..974985f 100644 --- a/src/ncui.h +++ b/src/ncui.h @@ -16,7 +16,7 @@ struct ncwin struct ncform { FORM* form; - FIELD* fields[6]; + FIELD* fields[8]; FIELD* active; int height; int width;