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
curses_variables(3NCURSES)												curses_variables(3NCURSES)

NAME
COLORS, COLOR_PAIRS, COLS, ESCDELAY, LINES, TABSIZE, curscr, newscr, stdscr - curses global variables SYNOPSIS
#include <curses.h> int COLOR_PAIRS; int COLORS; int COLS; int ESCDELAY; int LINES; int TABSIZE; WINDOW * curscr; WINDOW * newscr; WINDOW * stdscr; DESCRIPTION
This page summarizes variables provided by the curses library. A more complete description is given in the curses(3X) manual page. Depending on the configuration, these may be actual variables, or macros (see threads(3NCURSES)) which provide read-only access to curses's state. In either case, applications should treat them as read-only to avoid confusing the library. COLOR_PAIRS After initializing curses, this variable contains the number of color pairs which the terminal can support. Usually the number of color pairs will be the product COLORS*COLORS, however this is not always true: o a few terminals use HLS colors, which do not follow this rule o terminals supporting a large number of colors are limited by the number of color pairs that can be represented in a signed short value. COLORS After initializing curses, this variable contains the number of colors which the terminal can support. COLS After initializing curses, this variable contains the width of the screen, i.e., the number of columns. ESCDELAY This variable holds the number of milliseconds to wait after reading an escape character, to distinguish between an individual escape char- acter entered on the keyboard from escape sequences sent by cursor- and function-keys (see curses(3X). LINES After initializing curses, this variable contains the height of the screen, i.e., the number of lines. TABSIZE This variable holds the number of columns used by the curses library when converting a tab character to spaces as it adds the tab to a win- dow (see curs_addch(3X). The Current Screen This implementation of curses uses a special window curscr to record its updates to the terminal screen. The New Screen This implementation of curses uses a special window newscr to hold updates to the terminal screen before applying them to curscr. The Standard Screen Upon initializing curses, a default window called stdscr, which is the size of the terminal screen, is created. Many curses functions use this window. NOTES
The curses library is initialized using either initscr(3X), or newterm(3X). If curses is configured to use separate curses/terminfo libraries, most of these variables reside in the curses library. PORTABILITY
ESCDELAY and TABSIZE are extensions, not provided in most other implementations of curses. SEE ALSO
ncurses(3NCURSES), threads(3NCURSES), terminfo_variables(3NCURSES), terminfo(3X), terminfo(5). curses_variables(3NCURSES)
All times are GMT -4. The time now is 02:58 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy