separate (Help_Utility)
-------------------------PROLOGUE---------------------------------------
--                                                                    -*
-- Unit name    :  PRINT_CURRENT_PROMPT
-- Date created :  28 January 1985
-- Last update  :
--                                                                    -*
------------------------------------------------------------------------
--                                                                    -*
-- Abstract     :  This procedure determines the prompt and outputs it.
--                                                                    -*
------------------------------------------------------------------------
--
-- Mnemonic     :
-- Name         :
-- Release date :
------------------ Revision history ------------------------------------
--
-- DATE  AUTHOR   HISTORY
--
--
--


--------------------END-PROLOGUE----------------------------------------
procedure Print_Current_Prompt (Node : in Help_Utility.Help_Link) is

    Temp_Node : Help_Utility.Help_Link := null;
    Prompt_End : Integer := 1; -- number of allowable characters for prompt
    Save_Current_Level : Integer := 0;  -- used in reverse tree traversal
    Prompt_Name : Help_Info_Support.Help_Info_Text_Line :=
       Help_Utility.Blank_Line;
    Blank_Line_Length : constant Positive := 1;

begin

    -- there are two types of prompts:
    -- 1) "topic? "
    -- 2) "subtopic? "

    -- "topic? " is output when at the highest level (at the top node)

    if Node = Help_Utility.Top_Node then
        Help_Info_Support.Append_To_Display
           (Help_Utility.Blank_Line, Blank_Line_Length);
        Help_Info_Support.Append_To_Display
           (Help_Utility.Topic_Line, Help_Utility.Topic_Line'Length);

    else

        -- when at a lower level output the topic name(s) followed by "subtopic? "

        Temp_Node := Node;
        Save_Current_Level := Node.Level;

        -- put the prompt "subtopic? " in the buffer

        Prompt_Name (1 .. Help_Utility.Subtopic_Line'Length) :=
           Help_Utility.Subtopic_Line;
        Prompt_End := Help_Info_Support.Max_Line_Length -
                         Help_Utility.Subtopic_Line'Length - 1;

        -- now put the name of the current node in the buffer before the prompt

        Prompt_Name (1 .. Temp_Node.Name_Length +
                             Help_Info_Support.Max_Line_Length -
                             Prompt_End + 1) :=
           Temp_Node.Name (1 .. Temp_Node.Name_Length) & ' ' &
              Prompt_Name (1 .. Help_Info_Support.Max_Line_Length - Prompt_End);

        Prompt_End := Prompt_End - Temp_Node.Name_Length - 1;

        -- do a reverse tree traversal starting at the current node. if a level
        --  changes, put that node's name in the output string

        while Temp_Node.Level > 0 loop
            if Save_Current_Level /= Temp_Node.Level then
                Save_Current_Level := Temp_Node.Level;

                if Save_Current_Level > 0 then

                    --      if the name will not fit then exit and go with what we have

                    if Temp_Node.Name_Length + 1 > Prompt_End then
                        exit;
                    end if;

                    Prompt_Name (1 .. Temp_Node.Name_Length +
                                         Help_Info_Support.Max_Line_Length -
                                         Prompt_End + 1) :=
                       Temp_Node.Name (1 .. Temp_Node.Name_Length) & ' ' &
                          Prompt_Name (1 .. Help_Info_Support.Max_Line_Length -
                                               Prompt_End);

                    Prompt_End := Prompt_End - Temp_Node.Name_Length - 1;
                end if;
            end if;

            Temp_Node := Temp_Node.Parent;
        end loop;

        Help_Info_Support.Append_To_Display
           (Help_Utility.Blank_Line, Blank_Line_Length);
        Help_Info_Support.Append_To_Display
           (Prompt_Name, Help_Info_Support.Max_Line_Length - Prompt_End - 1);

    end if;

exception
    when others =>
        raise;

end Print_Current_Prompt;