diff options
-rw-r--r-- | main.c | 37 | ||||
-rw-r--r-- | readline.c | 19 | ||||
-rw-r--r-- | readline.h | 2 |
3 files changed, 51 insertions, 7 deletions
@@ -11,6 +11,7 @@ #include <unistd.h> #include <term.h> +#include <wordexp.h> #include "wind.h" @@ -240,7 +241,7 @@ int main(int argc, char* argv[]){ if( !tabed ) { contact* found = NULL; move(LINES-1,0); - readline_n(); + readline_n("> ", ""); int r = findContactFromName(msg_win_str, &found); if( r == 0 ) { @@ -263,6 +264,40 @@ int main(int argc, char* argv[]){ resize(); } break; + case 'e': + if( tabed ) { + contact* selected = getContactSelected(); + readline_n("Edit contact | Name : ", selected->name); + strcpy(selected->name, msg_win_str); + readline_n("Edit contact | Display name : ", selected->display_name); + strcpy(selected->display_name, msg_win_str); + writeContactList(config.CONTACT_FILENAME); + showContactListW(); + } + break; + case 'a': + if( !tabed ) { + contact newContact = {"", "", "", 0, NULL}; + readline_n("New contact | Name : ", ""); + strcpy(newContact.name, msg_win_str); + readline_n("New contact | Display name : ", ""); + strcpy(newContact.display_name, msg_win_str); + readline_n("New contact | Number : ", ""); + strcpy(newContact.number, msg_win_str); + + addContact(&newContact); + + if( *config.CONTACT_FILENAME == '\0' ) { + wordexp_t p; + r = wordexp("~/.mesms_contacts.csv", &p, 0); + if( r == 0 && p.we_wordc > 0 ) { + strcpy(config.CONTACT_FILENAME, p.we_wordv[0]); + } + } + writeContactList(config.CONTACT_FILENAME); + showContactListW(); + } + break; case 'i': case 's': { char* number = NULL; @@ -103,6 +103,7 @@ static void msg_win_redisplay(bool for_resize) } static void got_command(char *line) { + fprintf(stderr, "got_command\n"); if( line ) if (*line != '\0') add_history(line); @@ -172,9 +173,19 @@ void init_readline(void) } -void readline_n(void) { +void readline_n(const char* info, const char* str) { curs_set(2); resize(); + + if( info ) { + rl_callback_handler_install(info, got_command); + } + + for( ; *str ; str++ ) { + if( *str != '\n' && *str != '\f' && *str != KEY_RESIZE ) { + forward_to_readline(*str); + } + } while (!should_exit) { // Using getch() here instead would refresh stdscr, overwriting the // initial contents of the other windows on startup @@ -183,13 +194,13 @@ void readline_n(void) { if( c == '\n') should_exit = 1; if (c == KEY_RESIZE) - ;//resize(); + resize(); else if (c == '\f') { // Ctrl-L -- redraw screen. // Makes the next refresh repaint the screen from scratch CHECK(clearok, curscr, TRUE); // Resize and reposition windows in case that got messed up // somehow - //resize(); + resize(); } else forward_to_readline(c); @@ -197,5 +208,3 @@ void readline_n(void) { should_exit = 0; } - - @@ -15,7 +15,7 @@ -void readline_n(void); +void readline_n(const char*, const char*); void init_readline(void); |