LinuxQuestions.org
Download your favorite Linux distribution at LQ ISO.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 07-18-2011, 12:32 AM   #1
somlinux
LQ Newbie
 
Registered: Aug 2008
Distribution: fedora & ubuntu
Posts: 18

Rep: Reputation: 0
how to get number of rows and columns support in screen in linux


In linux terminal; how can we get the number of rows ad columns from linux kernel? I tried from environment variables(LINES,COLUMNS) but, I could not retrieve them as my editor program is a child process to linux terminal process.
 
Old 07-18-2011, 01:39 AM   #2
b0uncer
LQ Guru
 
Registered: Aug 2003
Distribution: CentOS, OS X
Posts: 5,131

Rep: Reputation: Disabled
Well, in general obtaining the number of rows and columns of a terminal is not a straightforward task. If you want to play safe, use the "traditional" size 25x80. If you insist, see this, this and this. Put short, the solution depends on what you're exactly working with (are you just using basic things, working with some helper libraries, working on some specific kind of terminal, ...)
 
Old 07-18-2011, 03:18 AM   #3
somlinux
LQ Newbie
 
Registered: Aug 2008
Distribution: fedora & ubuntu
Posts: 18

Original Poster
Rep: Reputation: 0
Quote:
Originally Posted by b0uncer View Post
Well, in general obtaining the number of rows and columns of a terminal is not a straightforward task. If you want to play safe, use the "traditional" size 25x80. If you insist, see this, this and this. Put short, the solution depends on what you're exactly working with (are you just using basic things, working with some helper libraries, working on some specific kind of terminal, ...)
Thanks for the useful links. (I am implementing an small text editor (academic project) )
 
Old 07-18-2011, 03:51 AM   #4
David the H.
Bash Guru
 
Registered: Jun 2004
Location: Osaka, Japan
Distribution: Arch + Xfce
Posts: 6,852

Rep: Reputation: 2037Reputation: 2037Reputation: 2037Reputation: 2037Reputation: 2037Reputation: 2037Reputation: 2037Reputation: 2037Reputation: 2037Reputation: 2037Reputation: 2037
tput can tell you.

Code:
tput rows
tput cols
The bash shell also sets LINES and COLUMNS environmental variables, if the shopt option checkwinsize is enabled. But you'll have to manually export them if you want them to be visible to child processes

Code:
shopt -s checkwinsize
export LINES COLUMNS
 
Old 07-18-2011, 09:09 AM   #5
ta0kira
Senior Member
 
Registered: Sep 2004
Distribution: FreeBSD 9.1, Kubuntu 12.10
Posts: 3,078

Rep: Reputation: Disabled
Quote:
Originally Posted by somlinux View Post
Thanks for the useful links. (I am implementing an small text editor (academic project) )
Is this in C? You should look at man tty_ioctl to make sure you're using accurate and current ioctl information.
Kevin Barry
 
1 members found this post helpful.
Old 07-18-2011, 03:23 PM   #6
ntubski
Senior Member
 
Registered: Nov 2005
Distribution: Debian, Arch
Posts: 3,780

Rep: Reputation: 2081Reputation: 2081Reputation: 2081Reputation: 2081Reputation: 2081Reputation: 2081Reputation: 2081Reputation: 2081Reputation: 2081Reputation: 2081Reputation: 2081
Wouldn't ncurses be the more obvious choice for a text editor?
 
Old 07-18-2011, 11:13 PM   #7
somlinux
LQ Newbie
 
Registered: Aug 2008
Distribution: fedora & ubuntu
Posts: 18

Original Poster
Rep: Reputation: 0
Can we export some variable using c system call??

Quote:
Originally Posted by David the H. View Post
tput can tell you.

Code:
tput rows
tput cols
The bash shell also sets LINES and COLUMNS environmental variables, if the shopt option checkwinsize is enabled. But you'll have to manually export them if you want them to be visible to child processes

Code:
shopt -s checkwinsize
export LINES COLUMNS
 
Old 07-18-2011, 11:20 PM   #8
somlinux
LQ Newbie
 
Registered: Aug 2008
Distribution: fedora & ubuntu
Posts: 18

Original Poster
Rep: Reputation: 0
thanks, it is a good choice
Quote:
Originally Posted by ntubski View Post
Wouldn't ncurses be the more obvious choice for a text editor?
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Formatting rows and columns kdelover Programming 4 08-31-2010 02:56 AM
a2ps - How to get 80 rows by 130 columns packer_fan Linux - Software 1 08-28-2010 11:06 AM
[SOLVED] How do you change the rows and columns in screen when you press ctrl-alt-f1? kike_coello Programming 3 07-13-2009 08:22 PM
columns & rows Ammad Linux - General 1 08-08-2005 04:02 AM
rows and columns digitalgravy Linux - General 2 03-16-2004 06:47 PM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 08:54 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration