--  Ada.Wide_Text_IO and Ada.Wide_Wide_Text_IO: a file of characters beyond Latin-1 written
--  and read back (UTF-8 in the file, a column per character), Get, Look_Ahead, Get_Line in
--  both forms, numbers and enumeration values to and from wide strings, and Status_Error and
--  Mode_Error as Text_IO's.
with Ada.Wide_Text_IO;
with Ada.Wide_Wide_Text_IO;

procedure Main is
   use Ada.Wide_Text_IO;
   package Int_IO is new Integer_IO (Integer);
   type Colour is (Red, Green, Blue);
   package Colour_IO is new Enumeration_IO (Colour);
   package WW renames Ada.Wide_Wide_Text_IO;

   F : File_Type;
   G : WW.File_Type;
   Line : Wide_String (1 .. 40);
   Last : Natural;
   C : Wide_Character;
   EOL : Boolean;
   N : Integer;
   Image : Wide_String (1 .. 6);
   Hue : Colour;
begin
   Create (F, Out_File, "");
   Put (F, "Grüße, " & Wide_Character'Val (16#03BB#));
   Put_Line (F, " =" & Integer'Wide_Image (Integer (Col (F))));
   Int_IO.Put (F, 42, Width => 4);
   New_Line (F);
   Reset (F, In_File);
   Look_Ahead (F, C, EOL);
   Put_Line ("ahead: " & C);
   Get (F, C);
   Get_Line (F, Line, Last);
   Put_Line (C & "|" & Line (1 .. Last) & "|");
   Int_IO.Get (F, N);
   Put_Line ("number:" & Integer'Wide_Image (N) & ", column" & Count'Wide_Image (Col (F)));
   Close (F);

   Int_IO.Put (Image, -17);
   Put_Line ("[" & Image & "]");
   Colour_IO.Get ("  Green!", Hue, Last);
   Colour_IO.Put (Image, Hue, Set => Lower_Case);
   Put_Line ("[" & Image & "]" & Natural'Wide_Image (Last));

   WW.Create (G, WW.Out_File, "");
   WW.Put_Line (G, "smile " & Wide_Wide_Character'Val (16#1F600#));
   WW.Reset (G, WW.In_File);
   declare
      L : constant Wide_Wide_String := WW.Get_Line (G);
   begin
      WW.Put_Line (L & " (" & Integer'Wide_Wide_Image (L'Length) & " characters)");
   end;
   WW.Close (G);

   begin
      Put (F, 'x');
   exception
      when Status_Error => Put_Line ("Status_Error");
   end;
   Create (F, Out_File, "");
   begin
      Get (F, C);
   exception
      when Mode_Error => Put_Line ("Mode_Error");
   end;
   Delete (F);
end Main;
