After editing text in field I press Enter, I expected to get edited value, but unchanged string was received. I was tried initialize field by non c_string buffer with spaces at free characters, same results. I have no clue why it happens. Similar questions not found.
Latests Cygwin, Debian, equal results.
#include <unistd.h>
#include <cstring>
#include <curses.h>
#include <form.h>
#include <iostream>
using namespace std;
int main()
{
string str = "hello";
initscr();
noecho();
keypad(stdscr, TRUE);
cbreak();
int field_width = 30;
FIELD* fields[] =
{
new_field( /*H*/1, /*W*/field_width, /*Y*/0,/*X*/0, 0, 0),
NULL
};
set_field_back(fields[0], A_UNDERLINE);
field_opts_off(fields[0], O_AUTOSKIP);
FORM* form = new_form( fields );
post_form( form );
refresh();
set_field_buffer( fields[0], 0, str.c_str() );
form_driver(form,REQ_END_LINE);
// Loop through to get user requests
int ch;
while((ch = getch()) != KEY_F(1))
{
switch(ch)
{
default: // paste char
form_driver(form, ch);
break;
case '\n':
case KEY_ENTER:
{
char * field_buff = field_buffer( fields[0], 0 );
// Iknow about spaces at the end of line
str = field_buff;
unpost_form(form);
free_form(form);
free_field(fields[0]);
endwin();
//
cout << "edited string: " << str << endl;
sleep(2);
//
return 0;
}
// end case Enter
}
// end switch
}
// end while
}
// end main