terminal Width/height change


 
Thread Tools Search this Thread
Top Forums Programming terminal Width/height change
# 1  
Old 02-20-2009
Bug terminal Width/height change

Hi,
i am very new to unix/linux programming. for one of the application i have to change the Terminal width and height. i did try this

if (ioctl (fd, TIOCGWINSZ, &win))
return;
if (y && y >24)
win.ws_row = y;
else
win.ws_row = 24;
if (x && x>80)
win.ws_col = x;
else
win.ws_col = 80;
ioctl (fd, TIOCSWINSZ, &win);


I don't see any change the terminal width and height change.

Could some please help in this regards.. or please forward the links where i can find some info/sample code for this

Regards,
Sunil
# 2  
Old 02-23-2009
If you think you will see the terminal resize itself then no that won' happen. That's because every time the terminal window is resized (by moving it in/out with the mouse) the new values of the struct winsize members are stored by the kernel and a SIGWINCH is generated to all the curently running processes so that they can redraw their interface. The vi editor is a good example of a program that redraws itself when such a signal is received.
# 3  
Old 02-23-2009
You can exercise those ioctl's from the command line with the stty command. "stty -a" will display the current values. Then something like "stty rows 50 cols 132" will set new values. You can confirm that the new value were set by doing another "stty -a".

And that is all it does. It stores that values in a place where any process that needs them can access them. Typically a program like vi will read them once at start up. Then if vi gets a SIGWINCH, it would reread them.

The values are typically set by another program like xterm that is managing a text window. If the user asks xterm to change the window size, xterm will do that, set those values, and send the SIGWINCH.

You are trying to reverse the process. Depending on what program is actually controlling that window, there may be some support for that. xterm has escape sequences that can be sent to it for various things like that. Most people are familiar with the escape sequence to change the window title. Some versions of xterm do indeed have an escape sequence to requesta different window size. If xterm grants the request, you process would recieve the SIGWINCH and should then read the new values. But be aware that the user can override this request. And even if it works, the user may simply resize the window back the way he wants it.
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. IP Networking

How do I change my IP via terminal?

Hi, guys, I was using an online utility to check wheather or not an email existed, and they gave me three tries. I thought clearing temp and cookies would work, but it looks like they grabbed a hold of my IP. :mad: Now, I'd like to make a shell script that changes my IP. Not bad...yet. I'm using... (7 Replies)
Discussion started by: Ihatewindows
7 Replies

2. Programming

get terminal width and height

I was reading Advanced Programming in the Unix Environment and it says to use ioctl() to get the terminal's width and height. I wrote this program: // print width and height #include <stdio.h> #include <unistd.h> #include <sys/ioctl.h> #include <termios.h> int main( int argc, char... (3 Replies)
Discussion started by: Ultrix
3 Replies

3. Shell Programming and Scripting

Change color on another terminal

i already have a running and working script for remote connection. is there a way to change the terminal color everytime I ssh remotely to another server? this is to avoid confusion since I will be using only one server to remotely access around 50 servers (solaris, linux,. etc) (2 Replies)
Discussion started by: lhareigh890
2 Replies

4. Shell Programming and Scripting

Set terminal width inside a shell script

Hi all, I have a shell script which uses "mailx -H" to get the subject of a email in a Linux system. However, the subject is truncated, and I think it has something to do with the terminal width because it only returns the first 80 characters of each line. I have tried "stty columns"... (7 Replies)
Discussion started by: mezzo
7 Replies

5. OS X (Apple)

Change Long User Name THrough The Terminal

Hello, I was wondering how to change a user's Long Name through the terminal. I am writing a shell script to change some settings back to the default, and could not find how to do this (or even if you can do this). I do not want to use applescript. (2 Replies)
Discussion started by: The Reepr
2 Replies

6. Programming

get terminal width and cursor position

I want to get the screen width and cursor positions. When I used curses, all the screen content was cleared. So Can I use curses to get the screen size without clearing anything in the window? Or is there any other alternative??? I can use only C or C++. (0 Replies)
Discussion started by: Sreejesh.S
0 Replies

7. Solaris

How to change the system prompt and BG of terminal?

Hi all, I was wondering how to change the PS1 to my liking? I tried changing it using PS1='my choice' it worked but the subsequent terminals i open will not have it as the default PS1 ,how do i change it? also i am running as super user, and i need to exec bash, to get the bash environment...... (4 Replies)
Discussion started by: wrapster
4 Replies

8. UNIX for Dummies Questions & Answers

How can I change the behavior of the mouse in Terminal?

Hi, I hope I'm posting in the correct forum, so here goes. I would like for the mouse right/left click to work in Terminal (OSX) as it does in Putty. For instance, when I double click 'log' in file.log.gz, only the log part is highlighted (in Terminal), while in Putty the entire file name is... (0 Replies)
Discussion started by: TheChemist
0 Replies

9. Solaris

Change Terminal Title

Is it possible to change the title of a Terminal window on Solaris? For example, for a MS Windows command window, one can simply type "title NameofWindow" to change the title for a command window. I was looking for similar functionality for terminal windows. Thanks. (8 Replies)
Discussion started by: here2learn
8 Replies

10. UNIX for Advanced & Expert Users

return image height and width

Hi all. I need to be able to get image (gif/jpg) height and widths from the server so I can size pop-up windows to fit the images. Is there a built in utility that accomplishes this on Unix or Linux? (1 Reply)
Discussion started by: Jabba
1 Replies
Login or Register to Ask a Question