Beefy Boxes and Bandwidth Generously Provided by pair Networks
We don't bite newbies here... much

Center curses output

by mhearse (Chaplain)
on Jul 04, 2013 at 05:58 UTC ( #1042331=perlquestion: print w/replies, xml ) Need Help??
mhearse has asked for the wisdom of the Perl Monks concerning the following question:

I have a curses app which is designed to run on a standard 80x25 console. By that I mean the output has a width of 80 characters and a height of 25 characters. When running this app in a terminal emulator I'm trying to figure out how to center my output. Can someone help me figure out how to calculate the beginning x,y coordinates?

Replies are listed 'Best First'.
Re: Center curses output
by hdb (Prior) on Jul 04, 2013 at 06:27 UTC

    Is this a Perl question? In order to get a useful answer you probably have to provide some details about your app.

    If your question is simply: on a screen of width $w and height $h and a centered window of 80x25, how wide is my left and top margin (or bottom?), the following should be helpful:

    $left = ($w - 80) / 2; $top = ($h - 25) / 2;

    which both might be negative on a small screen.

      Hi hdb,
      ..which both might be negative on a small screen...

      easy maths?! Huh!!!
      I remembered my programming days with V.B 6.0.. Nice one bro..
      hdb, am not undermining your point, am only emphasizing it...

      If you tell me, I'll forget.
      If you show me, I'll remember.
      if you involve me, I'll understand.
      --- Author unknown to me

        As I said, for a useful answer, more details might be needed...

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: perlquestion [id://1042331]
Approved by Corion
and all is quiet...

How do I use this? | Other CB clients
Other Users?
Others chilling in the Monastery: (2)
As of 2016-12-09 06:13 GMT
Find Nodes?
    Voting Booth?
    On a regular basis, I'm most likely to spy upon:

    Results (148 votes). Check out past polls.