Interactive Parsing

version 3 by Jon Ingold

  • Home page
  • Beginning
  • Previous
  • Next



  • Section 3 - Formatted Print Routines

    [ A set of routines for printing in the appropriate styles and places. ]

    Include (-

    [ PrintCharacter char_val col_val;
        glk_set_style(col_val); print (char) char_val;
    ];

    [ PrintCursor x;
        glk_set_window( (+ key-window +).ref_number);
        glk_window_move_cursor( (+ key-window +).ref_number, x + 1, 0);
        PrintCharacter('_', NORMAL);
        print " ";
    ];

    [ PrintPromptInWindow;
        glk_set_window( (+ key-window +).ref_number);
        glk_window_move_cursor( (+ key-window +).ref_number, 0, 0);
        PrintCharacter(62, CURSOR_STYLE);
        glk_window_move_cursor( (+ key-window +).ref_number, 0, 2);
        print " ";

    ];


    [ PrintTypedCommand
        print_buffer length cursor_character
        i wordnum
        ;

        !if (length > 0)
        !{
            glk_set_window( (+ key-window +).ref_number);
            glk_window_move_cursor( (+ key-window +).ref_number, 1, 0);
        
            for (wordnum = 0 , i = WORDSIZE : i < WORDSIZE + length : i++)
            {
                if (
                        i == WORDSIZE
                    || (print_buffer->(i-1) == 32 or '.' or ',' or '"' && ~~(print_buffer->i == 32 or '.' or ',' or '"'))
                    || (print_buffer->i == ',' or '.')
                 )
                    wordnum ++;

                if (i == cursor_character + WORDSIZE)
                {
                    if (print_buffer->i == ' ') PrintCharacter('_', CURSOR_STYLE);
                    else PrintCharacter(print_buffer -> i, CURSOR_STYLE);
                }
                else
                    PrintCharacter(print_buffer -> i, word_colours -> wordnum);

            }

            print " ";
            
            if (cursor_character >= length)
                PrintCursor(cursor_character);
        !}
    ];

    [ PrintPressReturn val i;
        glk_set_window( (+ key-window +).ref_number);
    ! glk_window_get_size((+ key-window +).ref_number, i, j);
        
        glk_window_move_cursor( (+ key-window +).ref_number, 55, 0);
        
        glk_set_style(RETURN_STYLE);
        if (val)
            print "Press Return";
        else
            print " ";

    ];


    [ PrintSuggestion word_to_print
        x
        i
        ;
        glk_set_window( (+ key-window +).ref_number);
        glk_window_move_cursor( (+ key-window +).ref_number, 0, 1);
        for (i = 0: i<x: i++) print " ";

        PrintCharacter('(', TIP);
        
        Glulx_PrintAnything( RetrieveLongerVersionOf(word_to_print) );
        
        PrintCharacter(')', TIP);

        for (i = 0 : i < 30: i++) print " ";
        
    ];

    [ BlankSuggestion i;
        glk_set_window( (+ key-window +).ref_number);
        glk_window_move_cursor( (+ key-window +).ref_number, 0, 1);
        for (i = 0 : i < 40: i++) print " ";

    ];

    [ ClearPromptWindow;
        glk_window_clear ( (+key-window+).ref_number);
    ];

    [ CorrectlyPositionCursor;
        ! this is unnecessary, but without it Quixe collapses because it tries to position the input cursor off-screen
        glk_set_window( (+ key-window +).ref_number);
        glk_window_move_cursor( (+ key-window +).ref_number, cursor_position + 1, 0);
    ];

    -).