yokmp

bluescreen.py

Feb 5th, 2012
293
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 4.65 KB | None | 0 0
  1. #!/usr/bin/python
  2. # -*- coding: iso-8859-1 -*-
  3.  
  4. import sys,os
  5.  
  6. hist=[]
  7.  
  8. def actually_write():
  9.     global hist
  10.     sys.stdout.write("\x1b[%sm"%(";".join(hist)))
  11.  
  12. def o(msg):
  13.     global hist
  14.     msg="%02i"%msg
  15.     hist.append(msg)
  16.     actually_write()
  17.  
  18. def undo():
  19.     global hist
  20.     hist.pop()
  21.     actually_write()
  22.  
  23. def reset():
  24.     global hist
  25.     hist=[]
  26.     sys.stdout.write("\x1bc\x1b[!p\x1b[?3;4l\x1b[4l\x1b>")
  27.     default()
  28.  
  29. def default():
  30.     o(10) # manchmal auch o(12) bei einem Fehler
  31.     o(0)
  32.  
  33. def clear():
  34.     sys.stdout.write("\x1b[H\x1b[2J")
  35.  
  36. def move(y,x):
  37.     sys.stdout.write("\x1b[%i;%iH"%(y+1,x+1))
  38.  
  39. def up():
  40.     sys.stdout.write("\x1b[A")
  41.  
  42. def down():
  43.     sys.stdout.write("\x1b[B")
  44.  
  45. def right():
  46.     sys.stdout.write("\x1b[C")
  47.  
  48. def left():
  49.     sys.stdout.write("\x1b[D")
  50.  
  51. def endline():
  52.     sys.stdout.write("\x1b[K")
  53.  
  54. def cursorinvisible():
  55.     sys.stdout.write("\x1b[?25l")
  56.  
  57. def cursornormal():
  58.     sys.stdout.write("\x1b[?12l\x1b[?25h")
  59.  
  60. def cursorveryvisible():
  61.     sys.stdout.write("\x1b[?12;25h")
  62.  
  63. def deletelines(lines=1):
  64.     sys.stdout.write("'\x1b[%iM"%lines)
  65.  
  66. def scrolldown():
  67.     sys.stdout.write("\x1bM")
  68.  
  69. def cols():
  70.     return int(os.popen("tput cols").read().strip())
  71.  
  72. def lines():
  73.     return int(os.popen("tput lines").read().strip())
  74.  
  75. def savecursor():
  76.     sys.stdout.write("\x1b7")
  77.  
  78. def restorecursor():
  79.     sys.stdout.write("\x1b8")
  80.  
  81. def bold():
  82.     o(1)
  83.  
  84. def hidden():
  85.     o(2)
  86.  
  87. def underline():
  88.     o(4)
  89.  
  90. def blink():
  91.     o(5)
  92.  
  93. def reverse():
  94.     o(7)
  95.  
  96. def formatting():
  97.     o(12)
  98.  
  99. def black():
  100.     o(30)
  101.  
  102. def red():
  103.     o(31)
  104.  
  105. def green():
  106.     o(32)
  107.  
  108. def orange():
  109.     o(33)
  110.  
  111. def blue():
  112.     o(34)
  113.  
  114. def magenta():
  115.     o(35)
  116.  
  117. def cyan():
  118.     o(36)
  119.  
  120. def white():
  121.     o(37)
  122.  
  123. def bgred():
  124.     o(41)
  125.  
  126. def bggreen():
  127.     o(42)
  128.  
  129. def bgorange():
  130.     o(43)
  131.  
  132. def bgblue():
  133.     o(44)
  134.  
  135. def bgmagenta():
  136.     o(45)
  137.  
  138. def bgcyan():
  139.     o(46)
  140.  
  141. def bgwhite():
  142.     o(47)
  143.  
  144. def put(line,indent,msg):
  145.     move(line,indent)
  146.     sys.stdout.write(msg)
  147.  
  148. def center(line,msg):
  149.     columns=cols()
  150.     indent=(columns-len(msg))/2
  151.     put(line,indent,msg)
  152.     return line,indent+len(msg)
  153.  
  154. def wrap(*args):
  155.     "wrap(line, [[lmargin,] rmargin,] msg)"
  156.     if len(args)==4:
  157.         line,lmargin,rmargin,msg=args
  158.     elif len(args)==3:
  159.         line,rmargin,msg=args
  160.         lmargin=0
  161.     elif len(args)==2:
  162.         line,msg=args
  163.         lmargin,rmargin=0,0
  164.     elif len(args)<2:
  165.         raise TypeError,"wrap() braucht mindestens 2 Argumente"
  166.     else:
  167.         raise TypeError,"wrap() braucht mindestens 4 Argumente"
  168.     line_length=cols()-lmargin-rmargin
  169.     msg=list(msg)
  170.     curr_indent=0
  171.     curr_line=line
  172.     char=msg.pop(0)
  173.     while 1:
  174.         if line_length-curr_indent<1:
  175.             put(curr_line,lmargin+curr_indent,'\n')
  176.             curr_line+=1
  177.             curr_indent=0
  178.             put(curr_line,lmargin,char)
  179.         else:
  180.             put(curr_line,lmargin+curr_indent,char)
  181.             curr_indent+=1
  182.             if len(msg)==0:
  183.                 break
  184.             char=msg.pop(0)
  185.     return curr_line,lmargin+curr_indent
  186.  
  187. def wordwrap(*args):
  188.     "wordwrap(line, [[lmargin,] rmargin,] msg)"
  189.     if len(args)==4:
  190.         line,lmargin,rmargin,msg=args
  191.     elif len(args)==3:
  192.         line,rmargin,msg=args
  193.         lmargin=0
  194.     elif len(args)==2:
  195.         line,msg=args
  196.         lmargin,rmargin=0,0
  197.     elif len(args)<2:
  198.         raise TypeError,"wordwrap() braucht mindestens 2 Argumente"
  199.     else:
  200.         raise TypeError,"wordwrap() braucht mindestens 4 Argumente"
  201.     line_length=cols()-lmargin-rmargin
  202.     msg=msg.split()
  203.     curr_indent=0
  204.     curr_line=line
  205.     word=msg.pop(0)
  206.     while 1:
  207.         if line_length<len(word): # Wort ist länger als erlaubt
  208.             put(curr_line,lmargin,word[:line_length]) # einpacken der Buchstaben
  209.             word=word[line_length:]
  210.             put(curr_line,lmargin+curr_indent,'\n')
  211.             curr_line+=1
  212.             curr_indent=0
  213.         elif line_length-curr_indent<len(word): # Wort passt nicht auf Rest
  214.             put(curr_line,lmargin+curr_indent,'\n') # der Zeile -- einpacken der Wörter
  215.             curr_line+=1
  216.             curr_indent=0
  217.             put(curr_line,lmargin,word)
  218.         else: # Wort passt (juhu)
  219.             put(curr_line,lmargin+curr_indent,word)
  220.             curr_indent+=len(word)+1
  221.             if len(msg)==0:
  222.                 break
  223.             word=msg.pop(0)
  224.     return curr_line,lmargin+curr_indent
  225.  
  226. def main():
  227.     reset()
  228.     bgblue()
  229.     white()
  230.     bold()
  231.     clear()
  232.     reverse()
  233.     center(5,' BLUESCREEN ')
  234.     undo()
  235.     line,col=wordwrap(7,7,8,"PAGE_FAULT_IN_NOPAGED_AREA")
  236.     print
  237.     put(line+2,11,"*")
  238.     line,col=wordwrap(line+2,14,8,"A Problem has been detected and Windows should benn thrown away to prevent damage to your brain!")
  239.     put(line+2,11,"*")
  240.     line,col=wordwrap(line+2,14,8,"*** STOP: 0x00000050 (0xFD3094C2,0x00000001,0xFBFE7617,0x00000000)")
  241.     put(line+1,11,"*")
  242.     line,col=wordwrap(line+1,14,8,"***  SPCMDCON.SYS - Adress FBFE7617 base at FBFE5000, DateStamp 3d6dd67c")
  243.     line,col=center(line+3,"Muhaha!")
  244.     move(line,col+1)
  245.     endline()
  246.     raw_input()
  247.     reset()
  248.  
  249. if __name__=="__main__":
  250.     main()
Advertisement
Add Comment
Please, Sign In to add comment