How to use the curtsies.FSArray function in curtsies

To help you get started, we’ve selected a few curtsies examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github ianmiell / autotrace / autotrace / autotrace.py View on Github external
def quit_autotrace(self, msg='All done.'):
		self.screen_arr = curtsies.FSArray(self.wheight, self.wwidth)
		self.window.render_to_terminal(self.screen_arr)
		print(msg + self.get_state_for_user())
		sys.exit(0)
github bpython / bpython / bpython / curtsiesfrontend / repl.py View on Github external
# because we're going to tack the status bar on at the end, shoot
            # for an array one less than the height of the screen
            min_height -= 1

        current_line_start_row = len(self.lines_for_display) - max(
            0, self.scroll_offset
        )
        # TODO how is the situation of self.scroll_offset < 0 possible?
        # or show_status_bar and about_to_exit ?
        if self.request_paint_to_clear_screen:
            self.request_paint_to_clear_screen = False
            arr = FSArray(min_height + current_line_start_row, width)
        elif self.request_paint_to_pad_bottom:
            # min_height - 1 for startup banner with python version
            height = min(self.request_paint_to_pad_bottom, min_height - 1)
            arr = FSArray(height, width)
            self.request_paint_to_pad_bottom = 0
        else:
            arr = FSArray(0, width)
        # TODO test case of current line filling up the whole screen (there
        # aren't enough rows to show it)

        current_line = paint.paint_current_line(
            min_height, width, self.current_cursor_line
        )
        # needs to happen before we calculate contents of history because
        # calculating self.current_cursor_line has the side effect of
        # unhighlighting parens in buffer

        def move_screen_up(current_line_start_row):
            # move screen back up a screen minus a line
            while current_line_start_row < 0:
github bpython / curtsies / examples / quickstart.py View on Github external
from __future__ import unicode_literals # convenient for Python 2
import random

from curtsies import FullscreenWindow, Input, FSArray
from curtsies.fmtfuncs import red, bold, green, on_blue, yellow

print(yellow('this prints normally, not to the alternate screen'))
with FullscreenWindow() as window:
    with Input() as input_generator:
        msg = red(on_blue(bold('Press escape to exit')))
        a = FSArray(window.height, window.width)
        a[0:1, 0:msg.width] = [msg]
        window.render_to_terminal(a)
        for c in input_generator:
            if c == '':
                break
            elif c == '':
                a = FSArray(window.height, window.width)
            else:
                s = repr(c)
                row = random.choice(range(window.height))
                column = random.choice(range(window.width-len(s)))
                color = random.choice([red, green, on_blue, yellow])
                a[row, column:column+len(s)] = [color(s)]
            window.render_to_terminal(a)
github bpython / bpython / bpython / curtsiesfrontend / repl.py View on Github external
current_line_start_row = len(self.lines_for_display) - max(
            0, self.scroll_offset
        )
        # TODO how is the situation of self.scroll_offset < 0 possible?
        # or show_status_bar and about_to_exit ?
        if self.request_paint_to_clear_screen:
            self.request_paint_to_clear_screen = False
            arr = FSArray(min_height + current_line_start_row, width)
        elif self.request_paint_to_pad_bottom:
            # min_height - 1 for startup banner with python version
            height = min(self.request_paint_to_pad_bottom, min_height - 1)
            arr = FSArray(height, width)
            self.request_paint_to_pad_bottom = 0
        else:
            arr = FSArray(0, width)
        # TODO test case of current line filling up the whole screen (there
        # aren't enough rows to show it)

        current_line = paint.paint_current_line(
            min_height, width, self.current_cursor_line
        )
        # needs to happen before we calculate contents of history because
        # calculating self.current_cursor_line has the side effect of
        # unhighlighting parens in buffer

        def move_screen_up(current_line_start_row):
            # move screen back up a screen minus a line
            while current_line_start_row < 0:
                logger.debug(
                    "scroll_offset was %s, current_line_start_row " "was %s",
                    self.scroll_offset,
github ianmiell / shutit / shutit_global.py View on Github external
def draw_screen(self, draw_type='default', quick_help=None):
		if quick_help is None:
			quick_help = 'Help: (r)otate shutit sessions | re(d)raw screen | (1,2,3,4) zoom pane in/out | (q)uit'
		assert draw_type in ('default','clearscreen','zoomed1','zoomed2','zoomed3','zoomed4')
		# Header
		header_text = u'  <= Shutit'
		self.screen_arr           = curtsies.FSArray(self.wheight, self.wwidth)
		self.screen_arr[0:1,0:len(header_text)] = [blue(header_text)]
		# Footer
		space = (self.wwidth - len(quick_help))*' '
		footer_text = space + quick_help
		if not self.shutit_global.ispy3:
			footer_text = footer_text.decode('utf-8')
		self.screen_arr[self.wheight-1:self.wheight,0:len(footer_text)] = [invert(blue(footer_text))]
		if draw_type in ('default','zoomed3','zoomed4'):
			# get sessions - for each ShutIt object in shutit_global
			sessions = list(get_shutit_pexpect_sessions())
			# reverse sessions as we're more likely to be interested in later ones.
			sessions.reverse()
			# Update the lower_pane_rotate_count so that it doesn't exceed the length of sessions.
			self.shutit_global.lower_pane_rotate_count = self.shutit_global.lower_pane_rotate_count % len(sessions)
			sessions = sessions[-self.shutit_global.lower_pane_rotate_count:] + sessions[:-self.shutit_global.lower_pane_rotate_count]
		# Truncate logstream if it gets too big.
github ianmiell / autotrace / autotrace / autotrace.py View on Github external
def draw_screen(self, draw_type, quick_help):
		assert draw_type in ('sessions','help','clearscreen')
		self.screen_arr = curtsies.FSArray(self.wheight, self.wwidth)
		# Header
		if self.status_message:
			header_text = 'Autotrace state: ' + invert(self.status) + ', ' + self.status_message
		else:
			header_text = 'Autotrace state: ' + invert(self.status)
		if self.colors_on:
			self.screen_arr[0:1,0:len(header_text)] = [blue(header_text)]
		else:
			self.screen_arr[0:1,0:len(header_text)] = [header_text]
		# Footer
		space = (self.wwidth - len(quick_help))*' '
		footer_text = space + quick_help
		if self.colors_on:
			self.screen_arr[self.wheight-1:self.wheight,0:len(footer_text)] = [invert(blue(footer_text))]
		else:
			self.screen_arr[self.wheight-1:self.wheight,0:len(footer_text)] = [invert(footer_text)]
github bpython / curtsies / examples / gameexample.py View on Github external
def get_array(self):
        a = FSArray(self.height, self.width)
        for entity in self.entities:
            a[self.height - 1 - entity.y, entity.x] = entity.display
        return a
github bpython / bpython / bpython / curtsiesfrontend / repl.py View on Github external
bool(self.status_bar.should_show_message)
            or self.status_bar.has_focus
        ) and not self.request_paint_to_pad_bottom
        if show_status_bar:
            # because we're going to tack the status bar on at the end, shoot
            # for an array one less than the height of the screen
            min_height -= 1

        current_line_start_row = len(self.lines_for_display) - max(
            0, self.scroll_offset
        )
        # TODO how is the situation of self.scroll_offset < 0 possible?
        # or show_status_bar and about_to_exit ?
        if self.request_paint_to_clear_screen:
            self.request_paint_to_clear_screen = False
            arr = FSArray(min_height + current_line_start_row, width)
        elif self.request_paint_to_pad_bottom:
            # min_height - 1 for startup banner with python version
            height = min(self.request_paint_to_pad_bottom, min_height - 1)
            arr = FSArray(height, width)
            self.request_paint_to_pad_bottom = 0
        else:
            arr = FSArray(0, width)
        # TODO test case of current line filling up the whole screen (there
        # aren't enough rows to show it)

        current_line = paint.paint_current_line(
            min_height, width, self.current_cursor_line
        )
        # needs to happen before we calculate contents of history because
        # calculating self.current_cursor_line has the side effect of
        # unhighlighting parens in buffer