Sponsored Content
Top Forums Programming Curses not updating LINES/COLS Post 302423699 by nwboy74 on Friday 21st of May 2010 06:24:04 PM
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;
}

 

9 More Discussions You Might Find Interesting

1. 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

2. 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

3. 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

4. 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

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

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

7. 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

8. 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

9. 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
curs_addstr(3X) 														   curs_addstr(3X)

NAME
addstr, addnstr, waddstr, waddnstr, mvaddstr, mvaddnstr, mvwaddstr, mvwaddnstr - add a string of characters to a curses window and advance cursor SYNOPSIS
#include <curses.h> int addstr(const char *str); int addnstr(const char *str, int n); int waddstr(WINDOW *win, const char *str); int waddnstr(WINDOW *win, const char *str, int n); int mvaddstr(int y, int x, const char *str); int mvaddnstr(int y, int x, const char *str, int n); int mvwaddstr(WINDOW *win, int y, int x, const char *str); int mvwaddnstr(WINDOW *win, int y, int x, const char *str, int n); DESCRIPTION
These functions write the (null-terminated) character string str on the given window. It is similar to calling waddch once for each char- acter in the string. The mv functions perform cursor movement once, before writing any characters. Thereafter, the cursor is advanced as a side-effect of writ- ing to the window. The four functions with n as the last argument write at most n characters, or until a terminating null is reached. If n is -1, then the entire string will be added. RETURN VALUE
All functions return the integer ERR upon failure and OK on success. X/Open does not define any error conditions. This implementation returns an error o if the window pointer is null or o if the string pointer is null or o if the corresponding calls to waddch return an error. Functions with a "mv" prefix first perform a cursor movement using wmove, and return an error if the position is outside the window, or if the window pointer is null. NOTES
All of these functions except waddnstr may be macros. PORTABILITY
These functions are described in the XSI Curses standard, Issue 4. SEE ALSO
curses(3X), curs_addch(3X). curs_addstr(3X)
All times are GMT -4. The time now is 01:18 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy