Home
Developer Resources
QNX RTOS v4
QNX RTOS v4 Knowledge Base

QNX RTOS v4 Knowledge Base

Foundry27
Foundry27
QNX RTOS v4 project
Resources

QNX RTOS v4 Knowledge Base

Title PtTty Widget vs. PtMultiText
Ref. No. QNX.000009842
Category(ies) Development
Issue We are looking for a widget that shows the output of system commands or scripts like the 'make window' in PhAB has,with proper colors, fonts and scrollbar. We tried The PtTty widget and we struggled around.

Do you have any suggestions?

Solution If you know that your system commands do not need keyboard input, use a pipe and a PtMultiText instead of a PtTty. A multitext will handle the scrollbars for you. With PtTty you would have to play with the Pt_ARG_TERM_SCRLBK_... resources and your own scrollbar.
With a multitext, you just need to do something like this:

x09struct pipectrl{
x09x09FILE *fp;
x09x09PtWidget_t *mt;
x09}
x09static int inp(int fd, void *data, unsigned mode) {
x09x09struct pipectrl *p = data;
x09x09char buf[256];
x09x09int n;
x09x09if((n = read(fd, buf,sizeof(buf))) > 0)
x09x09x09PtTextModifyText(p->mt, 0, 0, -1, buf, n);
x09x09else if (n == 0) {
x09x09x09pclose(p->fp);
x09x09x09free(p);
x09x09x09return Pt_END;
x09x09}
x09x09return Pt_CONTINUE;
x09}
x09int mt_popen(PtWidget_t *mt, const char *command) {
x09x09struct pipectrl *p;
x09x09if((p = malloc(sizeof(*p))) != NULL) {
x09x09x09if((p->fp = popen(command, "r")) != NULL) {
x09x09x09x09PtAppAddFd(NULL, fileno(p->fp), Pt_FD_READ, inp, p);
x09x09x09x09p->mt = mt;
x09x09x09x09return 0;
x09x09x09}
x09x09x09free(p);
x09x09}
x09x09return -1;
x09}
x09
x09x09