Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
option('default_width', 20, 'default column width', replay=True) # TODO: make not replay and remove from markdown saver
option('textwrap_cells', True, 'wordwrap text for multiline rows')
option('cmd_after_edit', 'go-down', 'command longname to execute after successful edit')
option('quitguard', False, 'confirm before quitting last sheet')
option('debug', False, 'exit on error and display stacktrace')
option('skip', 0, 'skip N rows before header', replay=True)
option('header', 1, 'parse first N rows as column names', replay=True)
theme('force_256_colors', False, 'use 256 colors even if curses reports fewer')
theme('use_default_colors', False, 'curses use default terminal colors')
theme('disp_note_none', '⌀', 'visible contents of a cell whose value is None')
theme('disp_truncator', '…', 'indicator that the contents are only partially visible')
theme('disp_oddspace', '\u00b7', 'displayable character for odd whitespace')
theme('disp_more_left', '<', 'header note indicating more columns to the left')
theme('disp_more_right', '>', 'header note indicating more columns to the right')
theme('disp_error_val', '', 'displayed contents for computation exception')
theme('disp_ambig_width', 1, 'width to use for unicode chars marked ambiguous')
theme('color_keystrokes', 'white', 'color of input keystrokes on status line')
theme('disp_pending', '', 'string to display in pending cells')
theme('note_pending', '⌛', 'note to display for pending cells')
theme('note_format_exc', '?', 'cell note for an exception during formatting')
theme('note_getter_exc', '!', 'cell note for an exception during computation')
theme('note_type_exc', '!', 'cell note for an exception during type conversion')
theme('color_note_pending', 'bold magenta', 'color of note in pending cells')
theme('color_note_type', '226 yellow', 'cell note for numeric types in anytype columns')
theme('scroll_incr', 3, 'amount to scroll with scrollwheel')
theme('disp_column_sep', '╵', 'separator between columns')
theme('disp_keycol_sep', '║', 'separator between key columns and rest of columns')
theme('disp_rowtop_sep', '│', '') # ╷│┬╽⌜⌐▇
theme('disp_rowmid_sep', '│', '') # ┃┊│█
theme('disp_rowbot_sep', '╵', '') # ┊┴╿⌞█⍿╵⎢┴⌊
theme('disp_rowend_sep', '║', '') # ┊┴╿⌞█⍿╵⎢┴⌊
theme('disp_keytop_sep', '║', '') # ╽╿┃╖╟
theme('disp_keymid_sep', '║', '') # ╽╿┃
theme('disp_keybot_sep', '║', '') # ╽╿┃╜‖
theme('disp_endtop_sep', '║', '') # ╽╿┃╖╢
theme('disp_endmid_sep', '║', '') # ╽╿┃
theme('disp_endbot_sep', '║', '') # ╽╿┃╜‖
theme('disp_selected_note', '•', '') #
theme('color_default', 'normal', 'the default color')
theme('color_default_hdr', 'bold', 'color of the column headers')
theme('color_bottom_hdr', 'underline', 'color of the bottom header row')
theme('color_current_row', 'reverse', 'color of the cursor row')
theme('color_current_col', 'bold', 'color of the cursor column')
theme('color_current_hdr', 'bold reverse', 'color of the header for the cursor column')
theme('color_column_sep', '246 blue', 'color of column separators')
theme('color_key_col', '81 cyan', 'color of key columns')
theme('color_hidden_col', '8', 'color of hidden columns on metasheets')
theme('color_selected_row', '215 yellow', 'color of selected rows')
def splitcell(s, width=0):
if width <= 0 or not options.textwrap_cells:
return [s]
ret = []
for L in s.splitlines():
theme('color_keystrokes', 'white', 'color of input keystrokes on status line')
theme('disp_pending', '', 'string to display in pending cells')
theme('note_pending', '⌛', 'note to display for pending cells')
theme('note_format_exc', '?', 'cell note for an exception during formatting')
theme('note_getter_exc', '!', 'cell note for an exception during computation')
theme('note_type_exc', '!', 'cell note for an exception during type conversion')
theme('color_note_pending', 'bold magenta', 'color of note in pending cells')
theme('color_note_type', '226 yellow', 'cell note for numeric types in anytype columns')
theme('scroll_incr', 3, 'amount to scroll with scrollwheel')
theme('disp_column_sep', '╵', 'separator between columns')
theme('disp_keycol_sep', '║', 'separator between key columns and rest of columns')
theme('disp_rowtop_sep', '│', '') # ╷│┬╽⌜⌐▇
theme('disp_rowmid_sep', '│', '') # ┃┊│█
theme('disp_rowbot_sep', '╵', '') # ┊┴╿⌞█⍿╵⎢┴⌊
theme('disp_rowend_sep', '║', '') # ┊┴╿⌞█⍿╵⎢┴⌊
theme('disp_keytop_sep', '║', '') # ╽╿┃╖╟
theme('disp_keymid_sep', '║', '') # ╽╿┃
theme('disp_keybot_sep', '║', '') # ╽╿┃╜‖
theme('disp_endtop_sep', '║', '') # ╽╿┃╖╢
theme('disp_endmid_sep', '║', '') # ╽╿┃
theme('disp_endbot_sep', '║', '') # ╽╿┃╜‖
theme('disp_selected_note', '•', '') #
theme('color_default', 'normal', 'the default color')
theme('color_default_hdr', 'bold', 'color of the column headers')
theme('color_bottom_hdr', 'underline', 'color of the bottom header row')
theme('color_current_row', 'reverse', 'color of the cursor row')
theme('color_current_col', 'bold', 'color of the cursor column')
theme('color_current_hdr', 'bold reverse', 'color of the header for the cursor column')
theme('disp_rowtop_sep', '│', '') # ╷│┬╽⌜⌐▇
theme('disp_rowmid_sep', '│', '') # ┃┊│█
theme('disp_rowbot_sep', '╵', '') # ┊┴╿⌞█⍿╵⎢┴⌊
theme('disp_rowend_sep', '║', '') # ┊┴╿⌞█⍿╵⎢┴⌊
theme('disp_keytop_sep', '║', '') # ╽╿┃╖╟
theme('disp_keymid_sep', '║', '') # ╽╿┃
theme('disp_keybot_sep', '║', '') # ╽╿┃╜‖
theme('disp_endtop_sep', '║', '') # ╽╿┃╖╢
theme('disp_endmid_sep', '║', '') # ╽╿┃
theme('disp_endbot_sep', '║', '') # ╽╿┃╜‖
theme('disp_selected_note', '•', '') #
theme('color_default', 'normal', 'the default color')
theme('color_default_hdr', 'bold', 'color of the column headers')
theme('color_bottom_hdr', 'underline', 'color of the bottom header row')
theme('color_current_row', 'reverse', 'color of the cursor row')
theme('color_current_col', 'bold', 'color of the cursor column')
theme('color_current_hdr', 'bold reverse', 'color of the header for the cursor column')
theme('color_column_sep', '246 blue', 'color of column separators')
theme('color_key_col', '81 cyan', 'color of key columns')
theme('color_hidden_col', '8', 'color of hidden columns on metasheets')
theme('color_selected_row', '215 yellow', 'color of selected rows')
def splitcell(s, width=0):
if width <= 0 or not options.textwrap_cells:
return [s]
ret = []
for L in s.splitlines():
ret.extend(textwrap.wrap(L, width=width, break_long_words=False, replace_whitespace=False))
return ret
option('default_width', 20, 'default column width', replay=True) # TODO: make not replay and remove from markdown saver
option('textwrap_cells', True, 'wordwrap text for multiline rows')
option('cmd_after_edit', 'go-down', 'command longname to execute after successful edit')
option('quitguard', False, 'confirm before quitting last sheet')
option('debug', False, 'exit on error and display stacktrace')
option('skip', 0, 'skip N rows before header', replay=True)
option('header', 1, 'parse first N rows as column names', replay=True)
theme('force_256_colors', False, 'use 256 colors even if curses reports fewer')
theme('use_default_colors', False, 'curses use default terminal colors')
theme('disp_note_none', '⌀', 'visible contents of a cell whose value is None')
theme('disp_truncator', '…', 'indicator that the contents are only partially visible')
theme('disp_oddspace', '\u00b7', 'displayable character for odd whitespace')
theme('disp_more_left', '<', 'header note indicating more columns to the left')
theme('disp_more_right', '>', 'header note indicating more columns to the right')
theme('disp_error_val', '', 'displayed contents for computation exception')
theme('disp_ambig_width', 1, 'width to use for unicode chars marked ambiguous')
theme('color_keystrokes', 'white', 'color of input keystrokes on status line')
theme('disp_pending', '', 'string to display in pending cells')
theme('note_pending', '⌛', 'note to display for pending cells')
theme('note_format_exc', '?', 'cell note for an exception during formatting')
theme('note_getter_exc', '!', 'cell note for an exception during computation')
theme('note_type_exc', '!', 'cell note for an exception during type conversion')
theme('color_note_pending', 'bold magenta', 'color of note in pending cells')
theme('color_note_type', '226 yellow', 'cell note for numeric types in anytype columns')
theme('scroll_incr', 3, 'amount to scroll with scrollwheel')
theme('disp_column_sep', '╵', 'separator between columns')
theme('disp_keycol_sep', '║', 'separator between key columns and rest of columns')
__all__ = [ 'RowColorizer', 'CellColorizer', 'ColumnColorizer', 'Sheet' ]
disp_column_fill = ' ' # pad chars after column value
# higher precedence color overrides lower; all non-color attributes combine
# coloropt is the color option name (like 'color_error')
# func(sheet,col,row,value) should return a true value if coloropt should be applied
# if coloropt is None, func() should return a coloropt (or None) instead
RowColorizer = collections.namedtuple('RowColorizer', 'precedence coloropt func')
CellColorizer = collections.namedtuple('CellColorizer', 'precedence coloropt func')
ColumnColorizer = collections.namedtuple('ColumnColorizer', 'precedence coloropt func')
theme('color_default', 'normal', 'the default color')
theme('color_default_hdr', 'bold', 'color of the column headers')
theme('color_bottom_hdr', 'underline', 'color of the bottom header row')
theme('color_current_row', 'reverse', 'color of the cursor row')
theme('color_current_col', 'bold', 'color of the cursor column')
theme('color_current_hdr', 'bold reverse', 'color of the header for the cursor column')
theme('color_column_sep', '246 blue', 'color of column separators')
theme('color_key_col', '81 cyan', 'color of key columns')
theme('color_hidden_col', '8', 'color of hidden columns on metasheets')
theme('color_selected_row', '215 yellow', 'color of selected rows')
UNLOADED = object() # sentinel for a sheet not yet loaded for the first time
class Sheet(BaseSheet):
'Base class for all tabular sheets.'
_rowtype = lambda: collections.defaultdict(lambda: None)
rowtype = 'rows'
theme('disp_pending', '', 'string to display in pending cells')
theme('note_pending', '⌛', 'note to display for pending cells')
theme('note_format_exc', '?', 'cell note for an exception during formatting')
theme('note_getter_exc', '!', 'cell note for an exception during computation')
theme('note_type_exc', '!', 'cell note for an exception during type conversion')
theme('color_note_pending', 'bold magenta', 'color of note in pending cells')
theme('color_note_type', '226 yellow', 'cell note for numeric types in anytype columns')
theme('scroll_incr', 3, 'amount to scroll with scrollwheel')
theme('disp_column_sep', '╵', 'separator between columns')
theme('disp_keycol_sep', '║', 'separator between key columns and rest of columns')
theme('disp_rowtop_sep', '│', '') # ╷│┬╽⌜⌐▇
theme('disp_rowmid_sep', '│', '') # ┃┊│█
theme('disp_rowbot_sep', '╵', '') # ┊┴╿⌞█⍿╵⎢┴⌊
theme('disp_rowend_sep', '║', '') # ┊┴╿⌞█⍿╵⎢┴⌊
theme('disp_keytop_sep', '║', '') # ╽╿┃╖╟
theme('disp_keymid_sep', '║', '') # ╽╿┃
theme('disp_keybot_sep', '║', '') # ╽╿┃╜‖
theme('disp_endtop_sep', '║', '') # ╽╿┃╖╢
theme('disp_endmid_sep', '║', '') # ╽╿┃
theme('disp_endbot_sep', '║', '') # ╽╿┃╜‖
theme('disp_selected_note', '•', '') #
theme('color_default', 'normal', 'the default color')
theme('color_default_hdr', 'bold', 'color of the column headers')
theme('color_bottom_hdr', 'underline', 'color of the bottom header row')
theme('color_current_row', 'reverse', 'color of the cursor row')
theme('color_current_col', 'bold', 'color of the cursor column')
theme('color_current_hdr', 'bold reverse', 'color of the header for the cursor column')
theme('color_column_sep', '246 blue', 'color of column separators')
theme('color_key_col', '81 cyan', 'color of key columns')
theme('disp_more_right', '>', 'header note indicating more columns to the right')
theme('disp_error_val', '', 'displayed contents for computation exception')
theme('disp_ambig_width', 1, 'width to use for unicode chars marked ambiguous')
theme('color_keystrokes', 'white', 'color of input keystrokes on status line')
theme('disp_pending', '', 'string to display in pending cells')
theme('note_pending', '⌛', 'note to display for pending cells')
theme('note_format_exc', '?', 'cell note for an exception during formatting')
theme('note_getter_exc', '!', 'cell note for an exception during computation')
theme('note_type_exc', '!', 'cell note for an exception during type conversion')
theme('color_note_pending', 'bold magenta', 'color of note in pending cells')
theme('color_note_type', '226 yellow', 'cell note for numeric types in anytype columns')
theme('scroll_incr', 3, 'amount to scroll with scrollwheel')
theme('disp_column_sep', '╵', 'separator between columns')
theme('disp_keycol_sep', '║', 'separator between key columns and rest of columns')
theme('disp_rowtop_sep', '│', '') # ╷│┬╽⌜⌐▇
theme('disp_rowmid_sep', '│', '') # ┃┊│█
theme('disp_rowbot_sep', '╵', '') # ┊┴╿⌞█⍿╵⎢┴⌊
theme('disp_rowend_sep', '║', '') # ┊┴╿⌞█⍿╵⎢┴⌊
theme('disp_keytop_sep', '║', '') # ╽╿┃╖╟
theme('disp_keymid_sep', '║', '') # ╽╿┃
theme('disp_keybot_sep', '║', '') # ╽╿┃╜‖
theme('disp_endtop_sep', '║', '') # ╽╿┃╖╢
theme('disp_endmid_sep', '║', '') # ╽╿┃
theme('disp_endbot_sep', '║', '') # ╽╿┃╜‖
theme('disp_selected_note', '•', '') #
theme('color_default', 'normal', 'the default color')
theme('color_default_hdr', 'bold', 'color of the column headers')
theme('color_bottom_hdr', 'underline', 'color of the bottom header row')
theme('note_pending', '⌛', 'note to display for pending cells')
theme('note_format_exc', '?', 'cell note for an exception during formatting')
theme('note_getter_exc', '!', 'cell note for an exception during computation')
theme('note_type_exc', '!', 'cell note for an exception during type conversion')
theme('color_note_pending', 'bold magenta', 'color of note in pending cells')
theme('color_note_type', '226 yellow', 'cell note for numeric types in anytype columns')
theme('scroll_incr', 3, 'amount to scroll with scrollwheel')
theme('disp_column_sep', '╵', 'separator between columns')
theme('disp_keycol_sep', '║', 'separator between key columns and rest of columns')
theme('disp_rowtop_sep', '│', '') # ╷│┬╽⌜⌐▇
theme('disp_rowmid_sep', '│', '') # ┃┊│█
theme('disp_rowbot_sep', '╵', '') # ┊┴╿⌞█⍿╵⎢┴⌊
theme('disp_rowend_sep', '║', '') # ┊┴╿⌞█⍿╵⎢┴⌊
theme('disp_keytop_sep', '║', '') # ╽╿┃╖╟
theme('disp_keymid_sep', '║', '') # ╽╿┃
theme('disp_keybot_sep', '║', '') # ╽╿┃╜‖
theme('disp_endtop_sep', '║', '') # ╽╿┃╖╢
theme('disp_endmid_sep', '║', '') # ╽╿┃
theme('disp_endbot_sep', '║', '') # ╽╿┃╜‖
theme('disp_selected_note', '•', '') #
theme('color_default', 'normal', 'the default color')
theme('color_default_hdr', 'bold', 'color of the column headers')
theme('color_bottom_hdr', 'underline', 'color of the bottom header row')
theme('color_current_row', 'reverse', 'color of the cursor row')
theme('color_current_col', 'bold', 'color of the cursor column')
theme('color_current_hdr', 'bold reverse', 'color of the header for the cursor column')
theme('color_column_sep', '246 blue', 'color of column separators')
theme('color_key_col', '81 cyan', 'color of key columns')
theme('color_hidden_col', '8', 'color of hidden columns on metasheets')
theme('color_selected_row', '215 yellow', 'color of selected rows')
theme('disp_more_left', '<', 'header note indicating more columns to the left')
theme('disp_more_right', '>', 'header note indicating more columns to the right')
theme('disp_error_val', '', 'displayed contents for computation exception')
theme('disp_ambig_width', 1, 'width to use for unicode chars marked ambiguous')
theme('color_keystrokes', 'white', 'color of input keystrokes on status line')
theme('disp_pending', '', 'string to display in pending cells')
theme('note_pending', '⌛', 'note to display for pending cells')
theme('note_format_exc', '?', 'cell note for an exception during formatting')
theme('note_getter_exc', '!', 'cell note for an exception during computation')
theme('note_type_exc', '!', 'cell note for an exception during type conversion')
theme('color_note_pending', 'bold magenta', 'color of note in pending cells')
theme('color_note_type', '226 yellow', 'cell note for numeric types in anytype columns')
theme('scroll_incr', 3, 'amount to scroll with scrollwheel')
theme('disp_column_sep', '╵', 'separator between columns')
theme('disp_keycol_sep', '║', 'separator between key columns and rest of columns')
theme('disp_rowtop_sep', '│', '') # ╷│┬╽⌜⌐▇
theme('disp_rowmid_sep', '│', '') # ┃┊│█
theme('disp_rowbot_sep', '╵', '') # ┊┴╿⌞█⍿╵⎢┴⌊
theme('disp_rowend_sep', '║', '') # ┊┴╿⌞█⍿╵⎢┴⌊
theme('disp_keytop_sep', '║', '') # ╽╿┃╖╟
theme('disp_keymid_sep', '║', '') # ╽╿┃
theme('disp_keybot_sep', '║', '') # ╽╿┃╜‖
theme('disp_endtop_sep', '║', '') # ╽╿┃╖╢
theme('disp_endmid_sep', '║', '') # ╽╿┃
theme('disp_endbot_sep', '║', '') # ╽╿┃╜‖
theme('disp_selected_note', '•', '') #
theme('color_default', 'normal', 'the default color')
theme('color_default_hdr', 'bold', 'color of the column headers')