import time
import sys

class Tt:
    def Xt(self,msg=''):
        sys.exit()

    def Wt(self,s=1):
        time.sleep(s)

    def Pt(self,msg=''):
        print(msg,end='')

    def Bk(self):
        print('',end='\r')

    def Qu(self,msg='',cur=0):
        self.Bk()
        print(msg,end='\r')
        return input(msg[0:cur])

    def Co(self,fn=lambda _ : null):
        while fn:
            fn = fn(self)



if __name__ == '__main__':
    s = Tt()
    def An(self,msgLst=[],t=0.05):
        for msg in msgLst:
            self.Wt(t)
            self.Bk()
            self.Pt(msg)

   
    def InTheCoffin(data=None):
        An(s,['cant see',
            'can barely move, your are surrouded by walls',
            'like if if you were lying in a  ...  coffins'],0.6)
        return ChoiceInTheCoffin
    def ChoiceInTheCoffin(data=None):
        s.Pt('Maybe i can [P]ush the top or [S]cream for help')
        s.Bk()
        s.Wt()
        choice = s.Qu('     : type [P]ush the top of the coffin, or type [S]cream for help')
        if len(choice) == 0:
            return MessingInTheCoffin
        elif choice[0].lower() == 's':
            return ScreamingInTheCoffin
        elif choice[0].lower() == 'p':
            return OpenTheCoffin
        return ChoiceInTheCoffin
    def ScreamingInTheCoffin(data=None):
        s.Bk()
        s.Wt(3)
        s.Pt('atfer screaming for hour, you pushed the door                    ')
        return OpenTheCoffin
    def MessingInTheCoffin(data=None):
        s.Bk()
        s.Wt(5)
        s.Pt('after hour of doing nothing you pushed the door     ')
        return OpenTheCoffin
    def OpenTheCoffin(data=None):
        s.Bk()
        s.Wt(0.5)
        s.Pt('You are free ....                               What the fuck ?')
        s.Wt(1)
        s.Bk()
        s.Xt()
    print('begin')
    s.Co(InTheCoffin)
    print('    the end')

