Python curses.raw() Examples
The following are 10
code examples of curses.raw().
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example.
You may also want to check out all available functions/classes of the module
curses
, or try the search function
.
Example #1
Source File: screen.py From babi with MIT License | 6 votes |
def _init_screen() -> 'curses._CursesWindow': # set the escape delay so curses does not pause waiting for sequences if sys.version_info >= (3, 9): # pragma: no cover curses.set_escdelay(25) else: # pragma: no cover os.environ.setdefault('ESCDELAY', '25') stdscr = curses.initscr() curses.noecho() curses.cbreak() # <enter> is not transformed into '\n' so it can be differentiated from ^J curses.nonl() # ^S / ^Q / ^Z / ^\ are passed through curses.raw() stdscr.keypad(True) with contextlib.suppress(curses.error): curses.start_color() curses.use_default_colors() return stdscr
Example #2
Source File: client_shell.py From PenguinDome with Apache License 2.0 | 5 votes |
def interact(stdscr, broker): curses.raw() broker.interact()
Example #3
Source File: ui.py From suplemon with MIT License | 5 votes |
def load(self, *args): """Setup curses.""" # Log the terminal type termname = curses.termname().decode("utf-8") self.logger.debug("Loading UI for terminal: {0}".format(termname)) self.screen = curses.initscr() self.setup_colors() curses.raw() curses.noecho() try: # Hide the default cursor # Might fail on vt100 terminal emulators curses.curs_set(0) except: self.logger.warning("curses.curs_set(0) failed!") if "get_wch" not in dir(self.screen): self.logger.warning("Using old curses! Some keys and special characters might not work.") self.screen.keypad(1) self.current_yx = self.screen.getmaxyx() # For checking resize self.setup_mouse() self.setup_windows()
Example #4
Source File: menu_screen.py From botany with ISC License | 5 votes |
def __init__(self, this_plant, this_data): '''Initialization''' self.initialized = False self.screen = curses.initscr() curses.noecho() curses.raw() if curses.has_colors(): curses.start_color() try: curses.curs_set(0) except curses.error: # Not all terminals support this functionality. # When the error is ignored the screen will look a little uglier, but that's not terrible # So in order to keep botany as accesible as possible to everyone, it should be safe to ignore the error. pass self.screen.keypad(1) self.plant = this_plant self.visited_plant = None self.user_data = this_data self.plant_string = self.plant.parse_plant() self.plant_ticks = str(int(self.plant.ticks)) self.exit = False self.infotoggle = 0 self.maxy, self.maxx = self.screen.getmaxyx() # Highlighted and Normal line definitions if curses.has_colors(): self.define_colors() self.highlighted = curses.color_pair(1) else: self.highlighted = curses.A_REVERSE self.normal = curses.A_NORMAL # Threaded screen update for live changes screen_thread = threading.Thread(target=self.update_plant_live, args=()) screen_thread.daemon = True screen_thread.start() # Recusive lock to prevent both threads from drawing at the same time self.screen_lock = threading.RLock() self.screen.clear() self.show(["water","look","garden","visit", "instructions"], title=' botany ', subtitle='options')
Example #5
Source File: wgwidget.py From apple_bleee with GNU General Public License v3.0 | 4 votes |
def get_and_use_key_press(self): global TEST_SETTINGS if (TEST_SETTINGS['TEST_INPUT'] is None) and (TEST_SETTINGS['INPUT_GENERATOR'] is None): curses.raw() curses.cbreak() curses.meta(1) self.parent.curses_pad.keypad(1) if self.parent.keypress_timeout: curses.halfdelay(self.parent.keypress_timeout) ch = self._get_ch() if ch == -1: return self.try_while_waiting() else: self.parent.curses_pad.timeout(-1) ch = self._get_ch() # handle escape-prefixed rubbish. if ch == curses.ascii.ESC: #self.parent.curses_pad.timeout(1) self.parent.curses_pad.nodelay(1) ch2 = self.parent.curses_pad.getch() if ch2 != -1: ch = curses.ascii.alt(ch2) self.parent.curses_pad.timeout(-1) # back to blocking mode #curses.flushinp() elif (TEST_SETTINGS['INPUT_GENERATOR']): self._last_get_ch_was_unicode = True try: ch = next(TEST_SETTINGS['INPUT_GENERATOR']) except StopIteration: if TEST_SETTINGS['CONTINUE_AFTER_TEST_INPUT']: TEST_SETTINGS['INPUT_GENERATOR'] = None return else: raise ExhaustedTestInput else: self._last_get_ch_was_unicode = True try: ch = TEST_SETTINGS['TEST_INPUT'].pop(0) TEST_SETTINGS['TEST_INPUT_LOG'].append(ch) except IndexError: if TEST_SETTINGS['CONTINUE_AFTER_TEST_INPUT']: TEST_SETTINGS['TEST_INPUT'] = None return else: raise ExhaustedTestInput self.handle_input(ch) if self.check_value_change: self.when_check_value_changed() if self.check_cursor_move: self.when_check_cursor_moved() self.try_adjust_widgets()
Example #6
Source File: ui.py From ice with GNU General Public License v3.0 | 4 votes |
def start(self, element_layouts): self.minor_frame_layout = MinorFrameLayout("raw", self) self.element_layout_key_shortcuts['`'] = self.minor_frame_layout self.subcom_layout = SubcomLayout("subcom", self) self.element_layout_key_shortcuts['~'] = self.subcom_layout print "Building history layout..." history_length = 40 self.history_layout = HistoryLayout(name="history", ui=self, width=24, elements=[ ('hps_1_temp_supercom', history_length), ('hps_2_temp_supercom', history_length), ('hps_1_tc', history_length), #('hps_1_tcX', history_length), ('hps_2_tc', history_length), #('hps_2_tcX', history_length), ('accelerometer', history_length), ]) # MAGIC self.element_layout_key_shortcuts['h'] = self.history_layout print "Building layouts..." for element_layout in element_layouts: name = element_layout[0] shortcut = name[0] if len(element_layout) >= 3: shortcut = element_layout[2] elements = [] for element_name in element_layout[1]: element = self.engine.get_element(element_name, safe=False) if element is None: print "The element '%s' was not found for layout '%s'" % (element_name, name) element = self.engine.get_element(element_name) elements += [element] layout = ElementsLayout(elements, name=name, ui=self) self.element_layouts += [layout] if shortcut not in self.element_layout_key_shortcuts.keys(): self.element_layout_key_shortcuts[shortcut] = layout else: print "ElementLayout '%s' already has shortcut key '%s'" % (self.element_layout_key_shortcuts[shortcut].name, shortcut) self.scr = curses.initscr() #curses.start_color() # FIXME self.scr.timeout(self.timeout) # -1 for blocking self.scr.keypad(1) # Otherwise app will end when pressing arrow keys curses.noecho() #curses.raw() #curses.cbreak() #curses.nl / curses.nonl #self.scr.deleteln() self.switch_layout(self.minor_frame_layout) self.update() #self.scr.refresh() # Done in 'update'
Example #7
Source File: wgwidget.py From HomePWN with GNU General Public License v3.0 | 4 votes |
def get_and_use_key_press(self): global TEST_SETTINGS if (TEST_SETTINGS['TEST_INPUT'] is None) and (TEST_SETTINGS['INPUT_GENERATOR'] is None): curses.raw() curses.cbreak() curses.meta(1) self.parent.curses_pad.keypad(1) if self.parent.keypress_timeout: curses.halfdelay(self.parent.keypress_timeout) ch = self._get_ch() if ch == -1: return self.try_while_waiting() else: self.parent.curses_pad.timeout(-1) ch = self._get_ch() # handle escape-prefixed rubbish. if ch == curses.ascii.ESC: #self.parent.curses_pad.timeout(1) self.parent.curses_pad.nodelay(1) ch2 = self.parent.curses_pad.getch() if ch2 != -1: ch = curses.ascii.alt(ch2) self.parent.curses_pad.timeout(-1) # back to blocking mode #curses.flushinp() elif (TEST_SETTINGS['INPUT_GENERATOR']): self._last_get_ch_was_unicode = True try: ch = next(TEST_SETTINGS['INPUT_GENERATOR']) except StopIteration: if TEST_SETTINGS['CONTINUE_AFTER_TEST_INPUT']: TEST_SETTINGS['INPUT_GENERATOR'] = None return else: raise ExhaustedTestInput else: self._last_get_ch_was_unicode = True try: ch = TEST_SETTINGS['TEST_INPUT'].pop(0) TEST_SETTINGS['TEST_INPUT_LOG'].append(ch) except IndexError: if TEST_SETTINGS['CONTINUE_AFTER_TEST_INPUT']: TEST_SETTINGS['TEST_INPUT'] = None return else: raise ExhaustedTestInput self.handle_input(ch) if self.check_value_change: self.when_check_value_changed() if self.check_cursor_move: self.when_check_cursor_moved() self.try_adjust_widgets()
Example #8
Source File: wgwidget.py From EDCOP with Apache License 2.0 | 4 votes |
def get_and_use_key_press(self): global TEST_SETTINGS if (TEST_SETTINGS['TEST_INPUT'] is None) and (TEST_SETTINGS['INPUT_GENERATOR'] is None): curses.raw() curses.cbreak() curses.meta(1) self.parent.curses_pad.keypad(1) if self.parent.keypress_timeout: curses.halfdelay(self.parent.keypress_timeout) ch = self._get_ch() if ch == -1: return self.try_while_waiting() else: self.parent.curses_pad.timeout(-1) ch = self._get_ch() # handle escape-prefixed rubbish. if ch == curses.ascii.ESC: #self.parent.curses_pad.timeout(1) self.parent.curses_pad.nodelay(1) ch2 = self.parent.curses_pad.getch() if ch2 != -1: ch = curses.ascii.alt(ch2) self.parent.curses_pad.timeout(-1) # back to blocking mode #curses.flushinp() elif (TEST_SETTINGS['INPUT_GENERATOR']): self._last_get_ch_was_unicode = True try: ch = next(TEST_SETTINGS['INPUT_GENERATOR']) except StopIteration: if TEST_SETTINGS['CONTINUE_AFTER_TEST_INPUT']: TEST_SETTINGS['INPUT_GENERATOR'] = None return else: raise ExhaustedTestInput else: self._last_get_ch_was_unicode = True try: ch = TEST_SETTINGS['TEST_INPUT'].pop(0) TEST_SETTINGS['TEST_INPUT_LOG'].append(ch) except IndexError: if TEST_SETTINGS['CONTINUE_AFTER_TEST_INPUT']: TEST_SETTINGS['TEST_INPUT'] = None return else: raise ExhaustedTestInput self.handle_input(ch) if self.check_value_change: self.when_check_value_changed() if self.check_cursor_move: self.when_check_cursor_moved() self.try_adjust_widgets()
Example #9
Source File: ci_program.py From ci_edit with Apache License 2.0 | 4 votes |
def setUpCurses(self, cursesScreen): self.cursesScreen = cursesScreen curses.mousemask(-1) curses.mouseinterval(0) # Enable mouse tracking in xterm. sys.stdout.write('\033[?1002;h') #sys.stdout.write('\033[?1005;h') curses.meta(1) # Access ^c before shell does. curses.raw() # Enable Bracketed Paste Mode. sys.stdout.write('\033[?2004;h') # Push the escape codes out to the terminal. (Whether this is needed # seems to vary by platform). sys.stdout.flush() try: curses.start_color() if not curses.has_colors(): userMessage("This terminal does not support color.") self.quitNow() else: curses.use_default_colors() except curses.error as e: app.log.error(e) app.log.startup(u"curses.COLORS", curses.COLORS) if 0: assert curses.COLORS == 256 assert curses.can_change_color() == 1 assert curses.has_colors() == 1 app.log.detail("color_content:") for i in range(0, curses.COLORS): app.log.detail("color", i, ": ", curses.color_content(i)) for i in range(16, curses.COLORS): curses.init_color(i, 500, 500, i * 787 % 1000) app.log.detail("color_content, after:") for i in range(0, curses.COLORS): app.log.detail("color", i, ": ", curses.color_content(i)) if 1: #rows, cols = self.cursesScreen.getmaxyx() cursesWindow = self.cursesScreen cursesWindow.leaveok(1) # Don't update cursor position. cursesWindow.scrollok(0) cursesWindow.timeout(10) cursesWindow.keypad(1) app.window.mainCursesWindow = cursesWindow
Example #10
Source File: wgwidget.py From TelegramTUI with MIT License | 4 votes |
def get_and_use_key_press(self): global TEST_SETTINGS if (TEST_SETTINGS['TEST_INPUT'] is None) and (TEST_SETTINGS['INPUT_GENERATOR'] is None): curses.raw() curses.cbreak() curses.meta(1) self.parent.curses_pad.keypad(1) if self.parent.keypress_timeout: curses.halfdelay(self.parent.keypress_timeout) ch = self._get_ch() if ch == -1: return self.try_while_waiting() else: self.parent.curses_pad.timeout(-1) ch = self._get_ch() # handle escape-prefixed rubbish. if ch == curses.ascii.ESC: #self.parent.curses_pad.timeout(1) self.parent.curses_pad.nodelay(1) ch2 = self.parent.curses_pad.getch() if ch2 != -1: ch = curses.ascii.alt(ch2) self.parent.curses_pad.timeout(-1) # back to blocking mode #curses.flushinp() elif (TEST_SETTINGS['INPUT_GENERATOR']): self._last_get_ch_was_unicode = True try: ch = next(TEST_SETTINGS['INPUT_GENERATOR']) except StopIteration: if TEST_SETTINGS['CONTINUE_AFTER_TEST_INPUT']: TEST_SETTINGS['INPUT_GENERATOR'] = None return else: raise ExhaustedTestInput else: self._last_get_ch_was_unicode = True try: ch = TEST_SETTINGS['TEST_INPUT'].pop(0) TEST_SETTINGS['TEST_INPUT_LOG'].append(ch) except IndexError: if TEST_SETTINGS['CONTINUE_AFTER_TEST_INPUT']: TEST_SETTINGS['TEST_INPUT'] = None return else: raise ExhaustedTestInput self.handle_input(ch) if self.check_value_change: self.when_check_value_changed() if self.check_cursor_move: self.when_check_cursor_moved() self.try_adjust_widgets()