Deriving a new class is possible but the OP's question is easier to solve with a callback. That's what callbacks are designed for. Modified example code follows:
#include <FL/Fl.H>
#include <FL/Fl_Window.H>
#include <FL/Fl_Text_Buffer.H>
#include <FL/Fl_Text_Display.H>
#include <FL/Fl_Input.H>
// input callback (called when ENTER is pressed)
void input_cb(Fl_Widget *w, void *v) {
Fl_Input *inp = (Fl_Input *)w;
Fl_Text_Display *ted = (Fl_Text_Display *)v;
Fl_Text_Buffer *tbuf = ted->buffer();
tbuf->append(inp->value());
tbuf->append("\n"); // append newline (optional)
ted->insert_position(tbuf->length());
ted->show_insert_position();
inp->value("");
inp->take_focus();
}
int main(int argc, char **argv) {
Fl_Window win(320, 240, "BIC");
Fl_Text_Buffer txtbuf;
win.begin();
Fl_Text_Display ted(2, 2, 320 - 2, 240 - 2 - 32 - 2);
Fl_Input inp(2, 240 - 2 - 32, 320 - 2, 32);
win.end();
inp.callback(input_cb, (void *)&ted); // set callback
inp.when(FL_WHEN_ENTER_KEY); // when ENTER is pressed
ted.buffer(txtbuf);
txtbuf.append("first line\n");
win.resizable(ted);
win.show();
return Fl::run();
}
There's a little more code involved to position to the end of the buffer to display new text when entered and to set the input focus back to the input widget, but I tried to make the example complete. There's no error handling though.