@@ -639,10 +639,116 @@ async def test_parallel(api):
639639 await api .print ('Test finished successfully' )
640640
641641
642+ async def term_step (api , text ):
643+ for color in api .colors :
644+ r , g , b = await api .term .nativePaletteColor (color )
645+ await api .term .setPaletteColor (color , r , g , b )
646+ await api .term .setBackgroundColor (api .colors .black )
647+ await api .term .setTextColor (api .colors .white )
648+ await api .term .clear ()
649+ await api .term .setCursorPos (1 , 1 )
650+ await api .term .setCursorBlink (True )
651+ await step (api , text )
652+
653+
642654async def test_term_api (api ):
643- from pprint import pprint
655+ from computercraft .subapis .mixins import TermMixin
656+
644657 tbl = await get_object_table (api , 'term' )
645658
646- pprint (tbl )
659+ # not defined in TermMixin
660+ del tbl ['function' ]['redirect' ]
661+ del tbl ['function' ]['current' ]
662+ del tbl ['function' ]['native' ]
663+
664+ # remove British method names to make API lighter
665+ del tbl ['function' ]['getBackgroundColour' ]
666+ del tbl ['function' ]['getPaletteColour' ]
667+ del tbl ['function' ]['getTextColour' ]
668+ del tbl ['function' ]['isColour' ]
669+ del tbl ['function' ]['nativePaletteColour' ]
670+ del tbl ['function' ]['setBackgroundColour' ]
671+ del tbl ['function' ]['setPaletteColour' ]
672+ del tbl ['function' ]['setTextColour' ]
673+
674+ assert get_class_table (TermMixin ) == tbl
675+
676+ await step (api , 'Detach all monitors\n Use advanced computer for colors\n Screen will be cleared' )
677+
678+ assert await api .term .getSize () == (51 , 19 )
679+ assert await api .term .isColor () is True
680+ assert await api .term .clear () is None
681+ assert await api .term .setCursorPos (1 , 1 ) is None
682+ assert await api .term .getCursorPos () == (1 , 1 )
683+ assert await api .term .write ('Alpha' ) is None
684+ assert await api .term .getCursorPos () == (6 , 1 )
685+ assert await api .term .setCursorBlink (False ) is None
686+ assert await api .term .getCursorBlink () is False
687+ assert await api .term .setCursorBlink (True ) is None
688+ assert await api .term .getCursorBlink () is True
689+ await asyncio .sleep (2 )
690+
691+ await term_step (api , 'You must have seen word Alpha with blinking cursor' )
692+
693+ assert await api .term .clear () is None
694+ for offs , (tc , bc ) in enumerate ((
695+ (api .colors .lime , api .colors .green ),
696+ (api .colors .yellow , api .colors .brown ),
697+ (api .colors .red , api .colors .orange ),
698+ ), start = 1 ):
699+ assert await api .term .setTextColor (tc ) is None
700+ assert await api .term .getTextColor () == tc
701+ assert await api .term .setBackgroundColor (bc ) is None
702+ assert await api .term .getBackgroundColor () == bc
703+ assert await api .term .setCursorPos (offs * 2 , offs ) is None
704+ assert await api .term .getCursorPos () == (offs * 2 , offs )
705+ assert await api .term .write ('text with colors' ) is None
706+ assert await api .term .setBackgroundColor (api .colors .black ) is None
707+ await asyncio .sleep (1 )
708+ for i in range (3 ):
709+ assert await api .term .scroll (- 2 ) is None
710+ await asyncio .sleep (0.5 )
711+ for i in range (6 ):
712+ assert await api .term .scroll (1 ) is None
713+ await asyncio .sleep (0.25 )
714+
715+ await term_step (api , 'You must have seen three texts with different colors scrolling' )
716+
717+ assert await api .term .clear () is None
718+ for i in range (1 , 10 ):
719+ assert await api .term .setCursorPos (1 , i ) is None
720+ assert await api .term .write ((str (i ) + ' ' ) * 10 ) is None
721+ await asyncio .sleep (2 )
722+ for i in range (2 , 10 , 2 ):
723+ assert await api .term .setCursorPos (1 , i ) is None
724+ assert await api .term .clearLine () is None
725+ await asyncio .sleep (2 )
726+
727+ await term_step (api , 'You must have seen some lines disappearing' )
728+
729+ assert await api .term .clear () is None
730+ assert await api .term .setCursorPos (1 , 1 ) is None
731+ assert await api .term .blit (
732+ 'rainbowrainbow' ,
733+ 'e14d3ba0000000' ,
734+ 'fffffffe14d3ba' ,
735+ ) is None
736+ await asyncio .sleep (3 )
737+
738+ await term_step (api , 'You must have seen per-letter colored text' )
739+
740+ assert await api .term .setBackgroundColor (api .colors .white ) is None
741+ assert await api .term .clear () is None
742+ assert await api .term .setCursorPos (1 , 1 ) is None
743+ for i , color in enumerate (api .colors ):
744+ await api .term .setPaletteColor (color , i / 15 , 0 , 0 )
745+ assert await api .term .blit (
746+ ' redtextappears!' ,
747+ '0123456789abcdef' ,
748+ '0000000000000000' ,
749+ ) is None
750+ await asyncio .sleep (3 )
751+
752+ await term_step (api , 'You must have seen different shades of red made using palettes' )
647753
648754 await api .print ('Test finished successfully' )
0 commit comments