How to use the visidata.option function in visidata

To help you get started, we’ve selected a few visidata 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 saulpw / visidata / visidata / saving.py View on Github external
from visidata import BaseSheet, Sheet, Column, fail, confirm, CellColorizer, RowColorizer, asyncthread, options, saveSheets, inputPath, getDefaultSaveName, warning, status, Path, copy, Progress, option


option('color_add_pending', 'green', 'color for rows pending add')
option('color_change_pending', 'reverse yellow', 'color for cells pending modification')
option('color_delete_pending', 'red', 'color for rows pending delete')


# deferred cached
Sheet.init('_deferredAdds', dict) # [s.rowid(row)] -> row
Sheet.init('_deferredMods', dict) # [s.rowid(row)] -> (row, { [col] -> val })
Sheet.init('_deferredDels', dict) # [s.rowid(row)] -> row

Sheet.colorizers += [
        CellColorizer(8, 'color_change_pending', lambda s,c,r,v: s.changed(c, r)),
        RowColorizer(9, 'color_delete_pending', lambda s,c,r,v: s.rowid(r) in s._deferredDels),
        RowColorizer(9, 'color_add_pending', lambda s,c,r,v: s.rowid(r) in s._deferredAdds),
    ]


@Sheet.api
github saulpw / visidata / visidata / sheets.py View on Github external
from visidata import VisiData, Extensible, globalCommand, ColumnAttr, ColumnItem, vd, ENTER, EscapeException, drawcache, drawcache_property, LazyChainMap, asyncthread, ExpectedException
from visidata import (Command, bindkeys, commands, options, theme, isNullFunc, isNumeric, Column, option, namedlist,
TypedExceptionWrapper, getGlobals, BaseSheet, UNLOADED,
vd, exceptionCaught, getType, clipdraw, ColorAttr, update_attr, colors, undoAttrFunc)


__all__ = ['RowColorizer', 'CellColorizer', 'ColumnColorizer', 'Sheet', 'IndexSheet', 'SheetsSheet', 'LazyComputeRow', 'SequenceSheet']


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')
github saulpw / visidata / visidata / main.py View on Github external
#
# Usage: $0 [] [<input> ...]
#        $0 [] --play  [--batch] [-w ] [-o <output>] [field=value ...]

__version__ = '2.-3dev'
__version_info__ = 'saul.pw/VisiData v' + __version__

import os
import io
import sys
import locale

from visidata import vd, option, options, status, run, Sheet
from visidata import Path, openSource, saveSheets, setDiffSheet, domotd

option('config', '~/.visidatarc', 'config file to exec in Python')
option('preplay', '', 'longnames to preplay before replay')

# for --play
def eval_vd(logpath, *args, **kwargs):
    'Instantiate logpath with args/kwargs replaced and replay all commands.'
    log = logpath.read_text()
    if args or kwargs:
        log = log.format(*args, **kwargs)

    src = Path(logpath.given, fp=io.StringIO(log), filesize=len(log))
    vs = openSource(src, filetype='vd')
    vs.name += '_vd'
    vd.push(vs)
    vs.vd = vd
    return vs
</output>
github saulpw / visidata / visidata / loaders / json.py View on Github external
import json

from visidata import options, option, status, date, deduceType
from visidata import PythonSheet, ColumnItem, stacktrace, asyncthread, Progress
from visidata import wrapply, TypedExceptionWrapper, TypedWrapper


option('json_indent', None, 'indent to use when saving json')


def open_json(p):
    return JSONSheet(p.name, source=p, jsonlines=False)

def open_jsonl(p):
    return JSONSheet(p.name, source=p, jsonlines=True)


class JSONSheet(PythonSheet):
    @asyncthread
    def reload(self):
        self.colnames = {}  # [colname] -> Column
        self.columns.clear()

        if not self.jsonlines:
github saulpw / visidata / visidata / textsheet.py View on Github external
import textwrap

from visidata import vd, option, options, Sheet, ColumnItem, asyncthread
from visidata import globalCommand, error, stacktrace, VisiData

__all__ = ['TextSheet', 'ErrorSheet']


option('wrap', False, 'wrap text to fit window width on TextSheet')
option('save_filetype', 'tsv', 'specify default file type to save as', replay=True)


## text viewer
# rowdef: (linenum, str)
class TextSheet(Sheet):
    'Displays any iterable source, with linewrap if wrap set in init kwargs or options.'
    rowtype = 'lines'
    filetype = 'txt'
    columns = [
        ColumnItem('linenum', 0, type=int, width=0),
        ColumnItem('text', 1),
    ]

    def iterload(self):
        winWidth = min(self.columns[1].width or 78, self.windowWidth-2)
github saulpw / visidata / visidata / sheets.py View on Github external
import collections
import itertools
from copy import copy
import textwrap

from visidata import VisiData, Extensible, globalCommand, ColumnAttr, ColumnItem, vd, ENTER, EscapeException, drawcache, drawcache_property, LazyChainMap, asyncthread, ExpectedException
from visidata import (Command, bindkeys, commands, options, theme, isNullFunc, isNumeric, Column, option, namedlist,
TypedExceptionWrapper, getGlobals, BaseSheet, UNLOADED,
vd, exceptionCaught, getType, clipdraw, ColorAttr, update_attr, colors, undoAttrFunc)


__all__ = ['RowColorizer', 'CellColorizer', 'ColumnColorizer', 'Sheet', 'IndexSheet', 'SheetsSheet', 'LazyComputeRow', 'SequenceSheet']


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', '&lt;', 'header note indicating more columns to the left')
theme('disp_more_right', '&gt;', 'header note indicating more columns to the right')
theme('disp_error_val', '', 'displayed contents for computation exception')
github saulpw / visidata / visidata / loaders.py View on Github external
return load_pyobj(p.name, json.loads(getTextContents(p)))

#### external addons
def open_py(p):
    contents = getTextContents(p)
    exec(contents, vdglobals())
    status('executed %s' % p)

## csv/tsv

option('csv_dialect', 'excel', 'dialect passed to csv.reader')
option('csv_delimiter', ',', 'delimiter passed to csv.reader')
option('csv_quotechar', '"', 'quotechar passed to csv.reader')
option('csv_headerlines', '0', 'parse first row of CSV as column names')

option('encoding', 'utf-8', 'as passed to codecs.open')
option('encoding_errors', 'surrogateescape', 'as passed to codecs.open')

def open_csv(p):
    vs = Sheet(p.name, p)
    vs.contents = getTextContents(p)
    vs.loader = lambda vs=vs: load_csv(vs)
    return vs

def load_csv(vs):
    header_lines = int(options.csv_headerlines or 0)
    if options.csv_dialect == 'sniff':
        headers = self.contents[:1024]
        dialect = csv.Sniffer().sniff(headers)
        status('sniffed csv_dialect as %s' % dialect)
    else:
        dialect = options.csv_dialect
github saulpw / visidata / plugins / vmailcap.py View on Github external
mimetype can be given explicity with `mimetype` option; will be guessed by filename otherwise.

Usage:
   1. copy to plugins dir
   2. add `import plugins.vmailcap` to .visidatarc or .vlsrc
   3. press Ctrl+V or g-Ctrl+V to view file(s) as desired.
'''

__name__ = 'vmailcap'
__author__ = 'Saul Pwanson '
__version__ = '0.9'

import os
from visidata import DirSheet, option, options, SuspendCurses, fail

option('mimetype', '', 'mimetype to be used with mailcap')

@DirSheet.api
def run_mailcap(sheet, p, key):
    import mailcap
    import mimetypes

    mimetype = options.mimetype
    if not mimetype:
        mimetype, encoding = mimetypes.guess_type(str(p))

    if not mimetype:
        fail('no mimetype given and no guess')

    caps = mailcap.getcaps()

    cmdline, mcap_entry = mailcap.findmatch(caps, mimetype, key=key, filename=str(p))
github saulpw / visidata / visidata / wrappers.py View on Github external
'value wrappers for nulls and errors'

from copy import copy
import functools

from visidata import options, stacktrace, option

__all__ = ['isNullFunc', 'forward', 'wrmap', 'wrapply', 'TypedWrapper', 'TypedExceptionWrapper']

option('null_value', None, 'a value to be counted as null', replay=True)

def isNullFunc():
    return lambda v,nulls=set([None, options.null_value]): v in nulls or isinstance(v, TypedWrapper)


@functools.total_ordering
class TypedWrapper:
    def __init__(self, func, *args):
        self.type = func
        self.args = args
        self.val = args[0] if args else ''

    def __bool__(self):
        return False

    def __str__(self):
github saulpw / visidata / visidata / sheets.py View on Github external
import textwrap

from visidata import VisiData, Extensible, globalCommand, ColumnAttr, ColumnItem, vd, ENTER, EscapeException, drawcache, drawcache_property, LazyChainMap, asyncthread, ExpectedException
from visidata import (Command, bindkeys, commands, options, theme, isNullFunc, isNumeric, Column, option, namedlist,
TypedExceptionWrapper, getGlobals, BaseSheet, UNLOADED,
vd, exceptionCaught, getType, clipdraw, ColorAttr, update_attr, colors, undoAttrFunc)


__all__ = ['RowColorizer', 'CellColorizer', 'ColumnColorizer', 'Sheet', 'IndexSheet', 'SheetsSheet', 'LazyComputeRow', 'SequenceSheet']


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', '&lt;', 'header note indicating more columns to the left')
theme('disp_more_right', '&gt;', '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')