prompt.anubis 961 Bytes

read bool.anubis
   
   *** (14) Prompting and reading from standard input. 

      *** (14.1) Reading a line from the standard input. 
   
public define String
  read_line_from_stdin
    (
      List(Word8) so_far
    ) =
  if *stdin is 
    {
      failure then implode(reverse(so_far)), 
      success(c) then 
        //println("read line read char ["+c+"|"+implode([c])+"]");
        if c = '\n' | c='\r' then
          implode(reverse(so_far))
        else 
          print(implode[c]);
          read_line_from_stdin([c . so_far])
    }. 
   
   
   
      *** (14.2) Printing a prompt and reading the answer. 
   
public define String
  prompt
    (
      String header
    ) =
  print(header); 
  read_line_from_stdin([]). 
   

   
      *** (14.3) The same one for a password:
   
public define String
   prompt_for_password
     (
       String header
     ) =
   print(header);
   get_password.        // see 'predefined.anubis'