1#!/usr/bin/env python 2##===-- sandbox.py -------------------------------------------*- Python -*-===## 3## 4# Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. 5# See https://llvm.org/LICENSE.txt for license information. 6# SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception 7## 8##===----------------------------------------------------------------------===## 9 10 11import curses 12 13import os 14import signal 15import sys 16 17try: 18 import queue 19except ImportError: 20 import Queue as queue 21 22import cui 23 24event_queue = None 25 26 27class SandboxUI(cui.CursesUI): 28 def __init__(self, screen, event_queue): 29 super(SandboxUI, self).__init__(screen, event_queue) 30 31 height, width = self.screen.getmaxyx() 32 w2 = width / 2 33 h2 = height / 2 34 35 self.wins = [] 36 # self.wins.append(cui.TitledWin(w2, h2, w2, h2, "Test Window 4")) 37 list_win = cui.ListWin(w2, h2, w2, h2) 38 for i in range(0, 40): 39 list_win.addItem("Item %s" % i) 40 self.wins.append(list_win) 41 self.wins.append(cui.TitledWin(0, 0, w2, h2, "Test Window 1")) 42 self.wins.append(cui.TitledWin(w2, 0, w2, h2, "Test Window 2")) 43 self.wins.append(cui.TitledWin(0, h2, w2, h2, "Test Window 3")) 44 45 # def callback(s, content): 46 # self.wins[0].win.scroll(1) 47 # self.wins[0].win.addstr(10, 0, '%s: %s' % (s, content)) 48 # self.wins[0].win.scroll(1) 49 # self.el.showPrompt(10, 0) 50 51 # self.wins[0].win.scrollok(1) 52 # self.el = cui.CursesEditLine(self.wins[0].win, None, 53 # lambda c: callback('got', c), lambda c: callback('tab', c)) 54 # self.el.prompt = '>>> ' 55 # self.el.showPrompt(10, 0) 56 57 def handleEvent(self, event): 58 if isinstance(event, int): 59 if event == ord("q"): 60 sys.exit(0) 61 # self.el.handleEvent(event) 62 super(SandboxUI, self).handleEvent(event) 63 64 65def main(screen): 66 global event_queue 67 event_queue = queue.Queue() 68 69 sandbox = SandboxUI(screen, event_queue) 70 sandbox.eventLoop() 71 72 73if __name__ == "__main__": 74 try: 75 curses.wrapper(main) 76 except KeyboardInterrupt: 77 exit() 78