18.10.2014 Views

Object-oriented Software in Ada 95

Object-oriented Software in Ada 95

Object-oriented Software in Ada 95

SHOW MORE
SHOW LESS

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

332 TUI the implementation<br />

The implementation code for Get_Immediate is shown mapp<strong>in</strong>g the three-character ANSI sequence for the<br />

arrow keys <strong>in</strong>to an <strong>in</strong>ternal s<strong>in</strong>gle character to representation. The actual character (s) generated will depend on<br />

the operat<strong>in</strong>g environment. The arrow key presses are mapped upon <strong>in</strong>put <strong>in</strong>to the character constants C_LEFT,<br />

C_RIGHT, C_UP and C_DOWN so that they can be processed <strong>in</strong> the program <strong>in</strong> a mach<strong>in</strong>e-<strong>in</strong>dependent way.<br />

with Raw_Io, Pack_Constants;<br />

use Raw_Io, Pack_Constants;<br />

package body Pack_Md_Io is<br />

procedure Put( Ch:<strong>in</strong> Character ) is<br />

beg<strong>in</strong><br />

Raw_Io.Put( Ch );<br />

end Put;<br />

procedure Put( Str:<strong>in</strong> Str<strong>in</strong>g ) is<br />

beg<strong>in</strong><br />

Raw_Io.Put( Str );<br />

end Put;<br />

procedure Get_Immediate( Ch:out Character) is<br />

Esc: constant Character := Character'Val(27);<br />

beg<strong>in</strong><br />

Raw_Io.Get_Immediate( Ch );<br />

if Ch = Esc then<br />

--ESC<br />

Raw_Io.Get_Immediate( Ch ); --[<br />

if Ch = '[' then<br />

Raw_Io.Get_Immediate( Ch );<br />

case Ch is<br />

when 'A' => Ch := C_Up; --A - Up arrow<br />

when 'B' => Ch := C_Down; --B - Down arrow<br />

when 'C' => Ch := C_Right; --C - Right arrow<br />

when 'D' => Ch := C_Left; --D - Left arrow<br />

when others => Ch := '?';<br />

end case;<br />

end if;<br />

end if;<br />

end Get_Immediate;<br />

end Pack_Md_Io;<br />

--? - Unknown<br />

Note:<br />

In the implementation of get_immediate the arrow keys are converted <strong>in</strong>to an <strong>in</strong>ternal s<strong>in</strong>gle<br />

character. The implementation for Raw_Io that I used returns three characters when an arrow key is<br />

pressed.<br />

One way of simplify<strong>in</strong>g this procedure is to make the user of the TUI use the follow<strong>in</strong>g control keys for<br />

arrow movements.<br />

Character<br />

^L<br />

^R<br />

^U ^D<br />

Mean<strong>in</strong>g<br />

Same as left arrow key<br />

Same as right arrow key<br />

Same as up arrow / down arrow key<br />

These def<strong>in</strong>itions can, of course, be changed by modify<strong>in</strong>g the def<strong>in</strong>itions of C_Up etc. <strong>in</strong> the package<br />

Pack_Constants.<br />

© M A Smith - May not be reproduced without permission

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!