Curses not updating LINES/COLS


 
Thread Tools Search this Thread
Top Forums Programming Curses not updating LINES/COLS
# 1  
Old 05-21-2010
Curses not updating LINES/COLS

I'm working with an extremely outdated and old system at work. We do not have ncurses, but we do have curses. I need to make a user interface for users connecting with xterm. One issue I've encountered is if the user resizes the window, I'd like to provide functionality to redraw the screen with the new dimensions, however, the LINES and COLS external variables never get updated with the newly stretched; they remain the same as the initial state when the program is started.

Code:
#include <curses.h>
void putch(WINDOW *scr, int x, int y, char c, attr_t a) {
        mvwaddch(scr, y, x, c | a);
}
void putstr(WINDOW *scr, int x, int y, const char *c, int len, attr_t a) {
        wmove(scr, y, x);
        int index;
        for (int index = 0; index < len; index++) {
                char curc = c[index];
                waddch(scr, curc | a);
        }
}
void drawscr(WINDOW *scr) {
        werase(scr);
        int y = 1;
        int x;
        for (x = 1; x < (COLS - 1); x++) {
                putch(scr, x, y, ' ', A_REVERSE);
        }
        x--;
        for (y = y + 1; y < (LINES - 1); y++) {
                putch(scr, x, y, ' ', A_REVERSE);
        }
        y--;
        for (x = x - 1; x > 0; x--) {
                putch(scr, x, y, ' ', A_REVERSE);
        }
        x++;
        for (y = y - 1; y > 0; y--) {
                putch(scr, x, y, ' ', A_REVERSE);
        }
        char str[] = "This is a string!";
        putstr(scr, 10, 4, str, 17, A_BOLD);
        putstr(scr, 10, 6, str, 17, A_REVERSE);
        putstr(scr, 10, 8, str, 17, A_UNDERLINE);
        mvwaddstr(scr, 10, 10, str);
        putstr(scr, 10, 12, str, 17, A_REVERSE | A_BOLD);
        putstr(scr, 10, 14, str, 17, A_BOLD | A_UNDERLINE);
}
int main() {
        WINDOW *mainscr = initscr();
        cbreak();
        noecho();
        keypad(mainscr, TRUE);
        drawscr(mainscr);
        refresh();
        int in = ' ';
        char buf[30];
        while (in != 'q') {
                in = wgetch(mainscr);
                if (in == 126) {  // ~ key (can't seem to get fn keys to work)
                        sprintf(buf, "%d x %d", COLS, LINES);
                        drawscr(mainscr);
                        mvwaddstr(mainscr, LINES-1, 0, buf);
                }
                refresh();
        }
        endwin();
        return 0;
}

# 2  
Old 05-22-2010
That is the expected behavior for ocurses. You could always backport some of the ncurses functionality to support what you want. For example, look at ncurses resizeterm().
# 3  
Old 05-24-2010
Thanks. I'm looking at resizeterm. It appears it is being called with the new width and height of the window, but I'm not sure what is providing that information. Is there a way to query for that information somehow?
# 4  
Old 05-25-2010
Check out SIGWINCH
# 5  
Old 05-26-2010
I understand that a SIGWINCH signal is generated when you resize the window, but SIGWINCH doesn't impart the new width and height of the window, does it? I'm beating my head against the wall with this and getting nowhere. Looking at ncurses, it appears that they're looking up the environment variables for LINES and COLUMNS, but that does me no good; LINES and COLUMNS never change, they stay the same as the initial state of the window when the program is run. I can trap the signal and I am indeed receiving a SIGWINCH signal when I resize the window. Smilie Now what? SOMETHING has to know what the new dimensions are.

---------- Post updated 05-26-10 at 09:59 AM ---------- Previous update was 05-25-10 at 12:19 PM ----------

I finally tracked down what I need.
Code:
winsize ws;
ioctl(0, TIOCGWINSZ, &ws);

Then I can grab the columns and rows.
Login or Register to Ask a Question

Previous Thread | Next Thread

9 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Getting cut to ignore cols in middle of records

I recently had to remove a number of columns from a sorted copy of a file, but couldn't get the cut command to take fields out, just what to keep. This is the only thing I could find as an example, but could it be simplified? tstamp=`date +%H%M%S` grep -v "T$" filename |egrep -v "^$" |sort... (3 Replies)
Discussion started by: wbport
3 Replies

2. Shell Programming and Scripting

Bitwise comparison of cols

Hello, I want to compute the bitwise number of matches in pairwise fashion for all columns. The problem is I have 18486955 rows and 750 columns. Please help with code, I believe this will take a lot of time, is there a way of tracking progress? Input Org1 Org2 Org3 A A T A ... (9 Replies)
Discussion started by: ritakadm
9 Replies

3. Shell Programming and Scripting

how to Insert values in multiple lines(records) within a pipe delimited text file in specific cols

this is Korn shell unix. The scenario is I have a pipe delimited text file which needs to be customized. say for example,I have a pipe delimited text file with 15 columns(| delimited) and 200 rows. currently the 11th and 12th column has null values for all the records(there are other null columns... (4 Replies)
Discussion started by: vasan2815
4 Replies

4. Shell Programming and Scripting

awk -- print combinations for 2 cols

Dear all, could you please help me with awk please? I have such input: Input: a d b e c f The number of lines is unknown before reading the file. I need to print possible combination between the two columns like this: Output: a d b d c d a e b e c e a f (2 Replies)
Discussion started by: irrevocabile
2 Replies

5. Shell Programming and Scripting

sort and split file by 2 cols (1 col after the other)

Dear All, I am a newbie to shell scripting so this one is really over my head. I have a text file with five fields as below: 76576.867188 6232.454102 2.008904 55.000000 3 76576.867188 6232.454102 3.607231 55.000000 4 76576.867188 6232.454102 1.555146 65.000000 3 76576.867188 6232.454102... (19 Replies)
Discussion started by: Ghetz
19 Replies

6. Shell Programming and Scripting

How to find number of Cols in a file ?

Hi I have a requirement wherein the file is comma separated. Each records seems to have different number of columns, how I can detect like a row index wise, how many columns are present ? Thanks in advance. (2 Replies)
Discussion started by: videsh77
2 Replies

7. Shell Programming and Scripting

awk updating one file with another, comparing, updating

Hello, I read and search through this wonderful forum and tried different approaches but it seems I lack some knowledge and neurones ^^ Here is what I'm trying to achieve : file1: test filea 3495; test fileb 4578; test filec 7689; test filey 9978; test filez 12300; file2: test filea... (11 Replies)
Discussion started by: mecano
11 Replies

8. Shell Programming and Scripting

Grouping matches by cols

Dear all I have a large file w. ~ 10 million lines. The first two cols have matching partners. For example: A A A B B B or A A B A B B The matches may be separated by an unknown number of lines. My intention is to group them and add a "group" value in the last col. For... (12 Replies)
Discussion started by: gbalsu
12 Replies

9. Shell Programming and Scripting

awk - print formatted without knowing no of cols

Hi, i want to print(f) the content of a file, but i don't know how many columns it has (i.e. it changes from each time my script is run). The number of columns is constant throughout the file. Any suggestions? (8 Replies)
Discussion started by: bistru
8 Replies
Login or Register to Ask a Question