ncurses Line Wrapping

This is a discussion on ncurses Line Wrapping within the C Programming forums, part of the General Programming Boards category; I am implementing line wrapping in my text editor, an I noticed that if the line reaches this point about ...

  1. #1
    MTK
    MTK is offline
    Registered User
    Join Date
    Aug 2009
    Posts
    198

    ncurses Line Wrapping

    I am implementing line wrapping in my text editor, an I noticed that if the line reaches this point about 2-4 columns from the right edge, the cursor skips a space ahead of the end of the line! This even happens when I comment out the line-wrapping part.

    I made it so that the arrow keys move around the cursor and again, the cursor just skips over that particular column instead of moving normally.

    Note that this is happening inside an ncurses window instead of stdscr, if that helps.

  2. #2
    MTK
    MTK is offline
    Registered User
    Join Date
    Aug 2009
    Posts
    198
    I found out that if I omit the titlebar and statusbar windows from the program it works fine.

  3. #3
    spurious conceit MK27's Avatar
    Join Date
    Jul 2008
    Location
    segmentation fault
    Posts
    8,300
    Quote Originally Posted by MTK View Post
    I found out that if I omit the titlebar and statusbar windows from the program it works fine.
    ncurses is gonna be frustrating cause IMO API's always contain little oddities that are near impossible to resolve without having someone familiar with the issue fill you in. Since there is no "ncurse forum" on the internet*, what I recommend you do is get into the ncurses mailing list:

    Nabble - Gnu - Ncurses forum & mailing list archive

    which I notice is active on a daily basis. I use mailing lists like that all the time, there is usually a few people (including the developers/maintainers of the API) who monitor the list and are pretty much gurus on the topic. Sometimes they are also helpful

    Good luck.

    * altho nabble is as close to a forum as a mailing list can get
    Last edited by MK27; 09-09-2009 at 07:53 PM.
    C programming resources:
    GNU C Function and Macro Index -- glibc reference manual
    The C Book -- nice online learner guide
    Current ISO draft standard
    CCAN -- new CPAN like open source library repository
    3 (different) GNU debugger tutorials: #1 -- #2 -- #3
    cpwiki -- our wiki on sourceforge

  4. #4
    Captain Crash brewbuck's Avatar
    Join Date
    Mar 2007
    Location
    Portland, OR
    Posts
    7,239
    Can we see compilable code that demonstrates the problem?
    Code:
    //try
    //{
    	if (a) do { f( b); } while(1);
    	else   do { f(!b); } while(1);
    //}

  5. #5
    MTK
    MTK is offline
    Registered User
    Join Date
    Aug 2009
    Posts
    198
    Here it is:

    Code:
    /*
    ncurses Column Skipping Test
    
    Arrow keys to move cursor, q to quit
    
    Compile:
    
    gcc editortest.c -lncurses -o editortest
    */
    
    #include <ncurses.h>
    
    void clear_bar(WINDOW* bar) {
    	wclear(bar);
    	int i;
    	for(i=0;i<COLS;i++) waddch(bar, ' ');
    	wmove(bar, 0, 0);
    }
    
    int main(int argc, char** args)
    {
    	WINDOW* titlebar;
    	WINDOW* statusbar;
    	WINDOW* textarea;
    
    	initscr();
    	raw();
    	refresh();
    
    	titlebar  = newwin(1, COLS, 0, 0);
    	statusbar = newwin(1, COLS, LINES-1, 0);
    	textarea  = newwin(LINES-2, COLS, 1, 0);
    
    	keypad(textarea, TRUE);
    
    	wattron(titlebar, A_REVERSE);
    	wattron(statusbar, A_REVERSE);
    
    	clear_bar(titlebar);
    	clear_bar(statusbar);
    	wclear(textarea);
    
    	wprintw(titlebar, "Titlebar");
    	wprintw(statusbar, "Statusbar");
    	wprintw(textarea, "Test");
    	wmove(textarea, 0, 0);
    
    	wrefresh(statusbar); //The cursor will NOT skip a column near the right edge when you comment out this line (???)
    	wrefresh(titlebar);
    	wrefresh(textarea);
    
    	unsigned long row = 0, col = 0;
    	while(1) {
    		int c = wgetch(textarea);
    
    		if(c == KEY_UP) row--;
    		if(c == KEY_DOWN) row++;
    		if(c == KEY_LEFT) col--;
    		if(c == KEY_RIGHT) col++;
    		if(c == 'q') break;
    
    		wclear(textarea);
    		wprintw(textarea, "Test");
    		wmove(textarea, row, col);
    		wrefresh(textarea);
    	}
    
    	endwin();
    	return 0;
    }
    Attached Files Attached Files

  6. #6
    MTK
    MTK is offline
    Registered User
    Join Date
    Aug 2009
    Posts
    198
    I wrote to the ncurses mailing list, and it turns out to be a bug in GNOME Terminal. It works fine in xterm.

  7. #7
    spurious conceit MK27's Avatar
    Join Date
    Jul 2008
    Location
    segmentation fault
    Posts
    8,300
    Quote Originally Posted by MTK View Post
    I wrote to the ncurses mailing list, and it turns out to be a bug in GNOME Terminal. It works fine in xterm.
    Try XFCE's Terminal, you don't need XFCE to use, if you are running GNOME you can just ignore the dependencies when you install, it should still work. The XFCE Terminal is better than the gnome terminal, aterm, Eterm, xterm, etc.
    Code:
    root~/C/projects/tsuushl] Terminal -v
    Terminal 0.2.8.3 (Xfce 4.4.3)
    
    Copyright (c) 2003-2007
            os-cillation e.K. All rights reserved.
    
    Written by Benedikt Meurer <benny@xfce.org>.
    
    Built with Gtk+-2.14.6, running with Gtk+-2.14.6.
    C programming resources:
    GNU C Function and Macro Index -- glibc reference manual
    The C Book -- nice online learner guide
    Current ISO draft standard
    CCAN -- new CPAN like open source library repository
    3 (different) GNU debugger tutorials: #1 -- #2 -- #3
    cpwiki -- our wiki on sourceforge

  8. #8
    MTK
    MTK is offline
    Registered User
    Join Date
    Aug 2009
    Posts
    198
    It said this in the bottom of the web page, so I typed it into my terminal:

    Code:
    git clone http://git.xfce.org/git/apps/terminal
    A bunch of hex numbers scrolled by, and not a trace of a new program installed.

  9. #9
    spurious conceit MK27's Avatar
    Join Date
    Jul 2008
    Location
    segmentation fault
    Posts
    8,300
    Terminal. I don't use git, so can't help you there.

    I built the one I'm using now from source

    Xfce-Terminal

    which I'm not sure where I pulled it from, maybe a src rpm, but there are at least some binaries on that page.

    I think many distros list Xfce-Terminal in it's own package.
    C programming resources:
    GNU C Function and Macro Index -- glibc reference manual
    The C Book -- nice online learner guide
    Current ISO draft standard
    CCAN -- new CPAN like open source library repository
    3 (different) GNU debugger tutorials: #1 -- #2 -- #3
    cpwiki -- our wiki on sourceforge

  10. #10
    MTK
    MTK is offline
    Registered User
    Join Date
    Aug 2009
    Posts
    198
    I got the source tarball, ran configure, and it said it needs exo-0.3. So I did:

    Code:
    sudo yum install exo
    And configure still says it doesn't exist.

  11. #11
    MTK
    MTK is offline
    Registered User
    Join Date
    Aug 2009
    Posts
    198
    I did:

    Code:
    sudo yum install exo-devel
    Now it says it wants "vde", and yum cannot find it.

  12. #12
    spurious conceit MK27's Avatar
    Join Date
    Jul 2008
    Location
    segmentation fault
    Posts
    8,300
    Quote Originally Posted by MTK View Post
    I did:

    Code:
    sudo yum install exo-devel
    Now it says it wants "vde", and yum cannot find it.
    Yeah, this is part of why the whole "Integrated Desktop Environment" idea is so cruddy (Xfce is a DE like GNOME*); if you want to mix and match components, you need to take a certificate program first

    I would recommend using the source. I still have it in a directory with the other stuff that I must have needed:
    Code:
    [root/usr/local/src/Xfce-Terminal] ls -1
    exo-0.3.4.tar.bz2
    gtk-xfce-engine-2.4.3.tar.bz2
    libxfce4util-4.4.3.tar.bz2
    Terminal-0.2.8.3.tar.bz2
    vte-0.16.13.tar.gz
    xfce4-icon-theme-4.4.3.tar.bz2
    Those all sources too, but I keep dependencies together so it should be all you need (other than the basic gtk stuff, which will be in a bunch of -devel rpm's if you haven't built any gtk yet).

    Nice guy that I am, I tarballed the whole directory and you can download it here:

    Index of /misc

    *nb I don't use either of them, so I'm sure Terminal is stable all by itself.
    Last edited by MK27; 09-12-2009 at 01:47 PM.
    C programming resources:
    GNU C Function and Macro Index -- glibc reference manual
    The C Book -- nice online learner guide
    Current ISO draft standard
    CCAN -- new CPAN like open source library repository
    3 (different) GNU debugger tutorials: #1 -- #2 -- #3
    cpwiki -- our wiki on sourceforge

  13. #13
    MTK
    MTK is offline
    Registered User
    Join Date
    Aug 2009
    Posts
    198
    Quote Originally Posted by MK27 View Post
    *nb I don't use either of them, so I'm sure Terminal is stable all by itself.
    What does that mean?

  14. #14
    spurious conceit MK27's Avatar
    Join Date
    Jul 2008
    Location
    segmentation fault
    Posts
    8,300
    Quote Originally Posted by MTK View Post
    What does that mean?
    Well, that I don't use a DE, I just use a WM!

    The DE's use a minimal "Window Manager" that was intended for them, but most WM's can run in X by themselves. X, by itself, is nothing but a blank screen and a mouse pointer; if you have a /etc/X11/xinit like this:
    Code:
    #!/bin/sh
    
    xterm
    You'll at least have an xterm on the otherwise blank screen so you can start something else.

    That's sort of a minimum. A window manager adds the borders, titlebars, menus, menubars, etc. So I just use "FVWM2", which is totally scripted, and design all that stuff myself. It's kinda ol' skool linux.

    The "new school" DE's take this to "another level" altho the value of that level is debatable IMO.

    So my point was, if I am using the Xfce Terminal, it should work anywhere fine. I've used GNOME and KDE (and Xfce) etc and I choose the terminal I liked the best, which is Terminal, because as I mentioned my fav apps are ncurses apps. Sadly, stand-alones like the Eterm and aterm have fallen pray to the "DE revolution" and are now very outdated seeming (altho still better than the truly vintage xterm). Eterm used to be the tish!
    Last edited by MK27; 09-12-2009 at 02:05 PM.
    C programming resources:
    GNU C Function and Macro Index -- glibc reference manual
    The C Book -- nice online learner guide
    Current ISO draft standard
    CCAN -- new CPAN like open source library repository
    3 (different) GNU debugger tutorials: #1 -- #2 -- #3
    cpwiki -- our wiki on sourceforge

  15. #15
    MTK
    MTK is offline
    Registered User
    Join Date
    Aug 2009
    Posts
    198
    I was reading some about X, WM's, DE's and stuff and it looks pretty interesting, but my Linux knowledge is still not at the level where I can set it up (I completely switched to Linux just a few weeks ago, playing around with it as a Sun VirtualBox VM for a few days before that).

    So am I right that each GUI widget has its own X Window, the Window Manager manages these Widgets and creates the actual "Window"s out of them, and the DE is a collection of programs that provide the titlebars, application launchers, desktop icons, etc?

Page 1 of 2 12 LastLast
Popular pages Recent additions subscribe to a feed

Similar Threads

  1. How to do encryption in C
    By sankarv in forum C Programming
    Replies: 33
    Last Post: 12-28-2010, 10:01 AM
  2. Printing Length of Input and the Limited Input
    By dnguyen1022 in forum C Programming
    Replies: 33
    Last Post: 11-29-2008, 03:13 PM
  3. Finding carriage returns (\c) in a line
    By JizJizJiz in forum C++ Programming
    Replies: 37
    Last Post: 07-19-2006, 05:44 PM
  4. Contest Results - May 27, 2002
    By ygfperson in forum A Brief History of Cprogramming.com
    Replies: 18
    Last Post: 06-18-2002, 01:27 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21