comp.lang.ada
 help / color / mirror / Atom feed
From: Emile8 <pocchiola.yves@gmail.com>
Subject: Re: ACCESS TO SYSTEM VARIABLES
Date: Wed, 9 Mar 2011 10:59:53 -0800 (PST)
Date: 2011-03-09T10:59:53-08:00	[thread overview]
Message-ID: <9ec28b3e-5e9b-48a3-a893-285512f59ff7@r19g2000prm.googlegroups.com> (raw)
In-Reply-To: 3b341a26-9317-4dbe-bf5b-c0312a3d914e@z27g2000prz.googlegroups.com

On 8 mar, 18:13, Emile8 <pocchiola.y...@gmail.com> wrote:
> On 7 mar, 22:32, "Peter C. Chapin" <PCha...@vtc.vsc.edu> wrote:
>
> > On Mon, 7 Mar 2011, Emile8 wrote:
> > > It is not a very elegant solution and I should look also at how the
> > > Ada version of ncurses manages to get the same informations.
>
> > When the terminal is resized the programs running in it receive a Unix
> > signal (SIGWINCH?). By default that signal is ignored. However, one can
> > install a signal handler for it and then presumably call into the system
> > (some terminal API) to ask for the new sizes.
>
> > I could probably figure out how to do this in C, but I'm not familiar with
> > how Ada on Unix deals with Unix signals.
>
> > Peter
>
> You are right, the approach by a user handler attached to the relevant
> UNIX signal is certainly the good approach to cope with terminal
> modifications. I am looking at some documentation to understand how to
> proceed with these handles in Ada (Rosetta Code ans Big Online Book of
> Linux Ada to begin).
>
> Thank you.

Your suggestion to use a handler on SIGWINCH works fine with the
following Ada package which has simply to be imported by the
application which uses a terminal. The Ansi_Tty_Control package
provides :
   -The N_Columns and N_Lines variables which keep trace of the
terminal size.
   -The Dim_Terminal procedure which reads the terminal sizes

Window resizing and terminal police size change are well detected and
new columns and lines number well reported.

Great !


--SPECIFICATION
with Ada.Interrupts.Names; use Ada.Interrupts, Ada.Interrupts.Names;
package Sigwinchhandler is
   protected Signalhandler is
      procedure Handlewindowresizing;
      pragma Attach_Handler (Handlewindowresizing, SIGWINCH);
      --      SIGWINCH (window resizing) intercepted by
      --      Handlewindowresizing
   end Signalhandler;
end Sigwinchhandler;

-- BODY
with Ada.Text_IO;      use Ada.Text_IO;
with Ansi_Tty_Control; use Ansi_Tty_Control;
package body Sigwinchhandler is
   -- Package to handle SIGWINCH Linux signals
   protected body Signalhandler is
      -- This protected type contains the signal handlers for the
applications
      procedure Handlewindowresizing is
      -- window dimensions handler
      begin
         -- Acquisition of terminal LINES and COLUMNS by bash
command :
         -- stty size > TermSize.txt (waiting for something else more
direct ...)
         Dim_Terminal;
         Put_Line ("Columns : " & Positive'Image (N_Columns));-- Here
the PROOF that it works !
         Put_Line ("Lines   : " & Positive'Image (N_Lines));
      end Handlewindowresizing;
   end Signalhandler;
end Sigwinchhandler;



  reply	other threads:[~2011-03-09 18:59 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2011-03-07  9:34 ACCESS TO SYSTEM VARIABLES Emile8
2011-03-07 11:47 ` Georg Bauhaus
2011-03-07 15:32   ` Adam Beneschan
2011-03-07 20:14   ` Emile8
2011-03-07 21:32     ` Peter C. Chapin
2011-03-08 17:13       ` Emile8
2011-03-09 18:59         ` Emile8 [this message]
2011-03-07 22:51 ` Keith Thompson
replies disabled

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox