* ncurses help
@ 2003-09-10 12:23 Matthew Harrison
0 siblings, 0 replies; 4+ messages in thread
From: Matthew Harrison @ 2003-09-10 12:23 UTC (permalink / raw)
To: linux-c-programming
[-- Attachment #1: Type: text/plain, Size: 599 bytes --]
Hi,
I am a sorta ok c programmer after becoming a bit of a wizz at perl/php, but
C is a very different language to learn and here I go:
I have been trying to get my first ncurses program working after following all
the examples on www.tldp.org, but now it just either gives me a blank window
(getstr functions still work and the app exits normally) or it just segfaults.
Please can someone glance at the sources (main source is
inventory-0.1/src/inventory.c in the attached tarball)
TIA
--
Mat Harrison
Technical Developer
3d Computer Systems Ltd.
matth@3d-computers.co.uk
[-- Attachment #2: Type: application/pgp-signature, Size: 187 bytes --]
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: ncurses help
@ 2003-09-10 12:25 Matthew Harrison
2003-09-10 15:32 ` William N. Zanatta
0 siblings, 1 reply; 4+ messages in thread
From: Matthew Harrison @ 2003-09-10 12:25 UTC (permalink / raw)
To: linux-c-programming
[-- Attachment #1.1: Type: text/plain, Size: 146 bytes --]
of course it often helps if you attach the file :)
--
Mat Harrison
Technical Developer
3d Computer Systems Ltd.
matth@3d-computers.co.uk
[-- Attachment #1.2: inventory-0.1.tar.gz --]
[-- Type: application/x-tar-gz, Size: 50521 bytes --]
[-- Attachment #2: Type: application/pgp-signature, Size: 187 bytes --]
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: ncurses help
2003-09-10 12:25 Matthew Harrison
@ 2003-09-10 15:32 ` William N. Zanatta
2003-09-11 8:06 ` Matthew Harrison
0 siblings, 1 reply; 4+ messages in thread
From: William N. Zanatta @ 2003-09-10 15:32 UTC (permalink / raw)
To: Matthew Harrison; +Cc: linux-c-programming
Try changing getstr() to wgetstr(). When doing window manipulation you
must use the functions with support to WINDOW pointers. If you don't,
you'll get the results you're experiencing, because getstr() comes into
action when it is reached while wgetstr() only comes into action after the
wrefresh().
Also, it showed some problems with placement of the stuff.
You have set login_window to (login_win.startx, login_win.starty) from
0,0 of the mainscreen. But, when you write stuff into that new window, you
must set the (x,y) from the login_window. iE, here I had:
login_win.starty -> 7
login_win.startx -> 25
thus, after creating the window, (25,7)-terminal turns to
(0,0)-login_window.
That's it you're working with absolute values when you should work with
relative.
After all your code turned to...
<inventory.c>
was
attron(COLOR_PAIR(1));
mvwprintw(login_window, ..., ..., "Username: ");
mvwprintw(login_window, ..., ..., "Password: ");
attroff(COLOR_PAIR(1));
changed to
wattron(login_window, COLOR_PAIR(1));
mvwprintw(login_window, 1, 1, "Username: ");
mvwprintw(login_window, 2, 1, "Password: ");
wattroff(login_window, COLOR_PAIR(1));
--------
was
echo();
wmove(login_window, ..., ...);
getstr(username);
wmove(login_window, ..., ...);
getstr(password);
noecho();
changed to
echo();
wmove(login_window, 1, 11);
wgetstr(login_window,username);
wmove(login_window, 2, 11);
wgetstr(login_window,password);
noecho();
</inventory.c>
Hope I've helped... =]
Just a note, you should use wgetnstr() to limit the length of input
data.
william
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: ncurses help
2003-09-10 15:32 ` William N. Zanatta
@ 2003-09-11 8:06 ` Matthew Harrison
0 siblings, 0 replies; 4+ messages in thread
From: Matthew Harrison @ 2003-09-11 8:06 UTC (permalink / raw)
To: William N. Zanatta; +Cc: linux-c-programming
[-- Attachment #1: Type: text/plain, Size: 2383 bytes --]
thanks William,
That has solved the problem totally. I know that it seems quite
simple, but I'm finding ncurses quite hard to learn the basics of because
i've never programmed any sort of gui before.
it's taking some hard work.
thanks again, I'm on my way.
On Wed, Sep 10, 2003 at 12:32:11PM -0300, William N. Zanatta wrote:
>
> Try changing getstr() to wgetstr(). When doing window manipulation you
> must use the functions with support to WINDOW pointers. If you don't,
> you'll get the results you're experiencing, because getstr() comes into
> action when it is reached while wgetstr() only comes into action after the
> wrefresh().
>
> Also, it showed some problems with placement of the stuff.
>
> You have set login_window to (login_win.startx, login_win.starty) from
> 0,0 of the mainscreen. But, when you write stuff into that new window, you
> must set the (x,y) from the login_window. iE, here I had:
>
> login_win.starty -> 7
> login_win.startx -> 25
>
> thus, after creating the window, (25,7)-terminal turns to
> (0,0)-login_window.
>
> That's it you're working with absolute values when you should work with
> relative.
>
> After all your code turned to...
>
> <inventory.c>
> was
> attron(COLOR_PAIR(1));
> mvwprintw(login_window, ..., ..., "Username: ");
> mvwprintw(login_window, ..., ..., "Password: ");
> attroff(COLOR_PAIR(1));
>
> changed to
>
> wattron(login_window, COLOR_PAIR(1));
> mvwprintw(login_window, 1, 1, "Username: ");
> mvwprintw(login_window, 2, 1, "Password: ");
> wattroff(login_window, COLOR_PAIR(1));
>
> --------
>
> was
> echo();
> wmove(login_window, ..., ...);
> getstr(username);
> wmove(login_window, ..., ...);
> getstr(password);
> noecho();
>
> changed to
>
> echo();
> wmove(login_window, 1, 11);
> wgetstr(login_window,username);
> wmove(login_window, 2, 11);
> wgetstr(login_window,password);
> noecho();
>
> </inventory.c>
>
> Hope I've helped... =]
>
> Just a note, you should use wgetnstr() to limit the length of input
> data.
>
> william
--
Mat Harrison
Technical Developer
3d Computer Systems Ltd.
matth@3d-computers.co.uk
[-- Attachment #2: Type: application/pgp-signature, Size: 187 bytes --]
^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2003-09-11 8:06 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2003-09-10 12:23 ncurses help Matthew Harrison
-- strict thread matches above, loose matches on Subject: below --
2003-09-10 12:25 Matthew Harrison
2003-09-10 15:32 ` William N. Zanatta
2003-09-11 8:06 ` Matthew Harrison
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).