From mboxrd@z Thu Jan 1 00:00:00 1970 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on polar.synack.me X-Spam-Level: X-Spam-Status: No, score=-0.4 required=5.0 tests=BAYES_00,FORGED_GMAIL_RCVD, FREEMAIL_FROM,SUBJ_ALL_CAPS autolearn=no autolearn_force=no version=3.4.4 X-Google-Thread: 103376,f9642664cfbe6417 X-Google-NewGroupId: yes X-Google-Attributes: gida07f3367d7,domainid0,public,usenet X-Google-Language: ENGLISH,ASCII-7-bit Path: g2news2.google.com!postnews.google.com!r19g2000prm.googlegroups.com!not-for-mail From: Emile8 Newsgroups: comp.lang.ada Subject: Re: ACCESS TO SYSTEM VARIABLES Date: Wed, 9 Mar 2011 10:59:53 -0800 (PST) Organization: http://groups.google.com Message-ID: <9ec28b3e-5e9b-48a3-a893-285512f59ff7@r19g2000prm.googlegroups.com> References: <31c9ef20-db49-4d3e-bafb-0d2a5dca7866@e9g2000vbk.googlegroups.com> <4d74c5c3$0$6878$9b4e6d93@newsspool2.arcor-online.net> <6ea98f8c-33eb-4f20-a696-eb59a519b80d@n18g2000vbq.googlegroups.com> <3b341a26-9317-4dbe-bf5b-c0312a3d914e@z27g2000prz.googlegroups.com> NNTP-Posting-Host: 90.27.116.165 Mime-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-1 X-Trace: posting.google.com 1299697197 23954 127.0.0.1 (9 Mar 2011 18:59:57 GMT) X-Complaints-To: groups-abuse@google.com NNTP-Posting-Date: Wed, 9 Mar 2011 18:59:57 +0000 (UTC) Complaints-To: groups-abuse@google.com Injection-Info: r19g2000prm.googlegroups.com; posting-host=90.27.116.165; posting-account=u9P-fgoAAAB1qVhsrmxVpcdi-eIb_an8 User-Agent: G2/1.0 X-HTTP-UserAgent: Mozilla/5.0 (X11; U; Linux x86_64; fr; rv:1.9.2.15) Gecko/20110303 Ubuntu/10.10 (maverick) Firefox/3.6.15,gzip(gfe) Xref: g2news2.google.com comp.lang.ada:18973 Date: 2011-03-09T10:59:53-08:00 List-Id: On 8 mar, 18:13, Emile8 wrote: > On 7 mar, 22:32, "Peter C. Chapin" 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;