How to use the visidata.options.get 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 / loaders / tsv.py View on Github external
def reload_sync(self):
        'Perform synchronous loading of TSV file, discarding header lines.'
        header_lines = options.get('header', self)
        delim = options.get('delimiter', self)

        with self.source.open_text() as fp:
            # get one line anyway to determine number of columns
            lines = list(getlines(fp, int(header_lines) or 1))
            headers = [L.split(delim) for L in lines]

            if header_lines <= 0:
                self.columns = [ColumnItem('', i) for i in range(len(headers[0]))]
            else:
                self.columns = [
                    ColumnItem('\\n'.join(x), i)
                        for i, x in enumerate(zip(*headers[:header_lines]))
                    ]

            lines = lines[header_lines:]  # in case of header_lines == 0
github saulpw / visidata / visidata / loaders / tsv.py View on Github external
def reload_sync(self):
        'Perform synchronous loading of TSV file, discarding header lines.'
        header_lines = options.get('header', self)
        delim = options.get('delimiter', self)

        with self.source.open_text() as fp:
            # get one line anyway to determine number of columns
            lines = list(getlines(fp, int(header_lines) or 1))
            headers = [L.split(delim) for L in lines]

            if header_lines <= 0:
                self.columns = [ColumnItem('', i) for i in range(len(headers[0]))]
            else:
                self.columns = [
                    ColumnItem('\\n'.join(x), i)
                        for i, x in enumerate(zip(*headers[:header_lines]))
                    ]

            lines = lines[header_lines:]  # in case of header_lines == 0
            self._rowtype = namedlist('tsvobj', [c.name for c in self.columns])
github saulpw / visidata / visidata / sheets.py View on Github external
def optlines(self, it, optname):
        'Generate next options. elements from iterator with exceptions wrapped.'
        for i in range(options.get(optname, self)):
            try:
                yield next(it)
            except StopIteration:
                break
github saulpw / visidata / visidata / loaders / tsv.py View on Github external
def save_tsv(p, vs):
    'Write sheet to file `fn` as TSV.'
    delim = options.get('delimiter', vs)
    trdict = tsv_trdict(vs)

    save_tsv_header(p, vs)

    with p.open_text(mode='a') as fp:
        for dispvals in genAllValues(vs.rows, vs.visibleCols, trdict, format=True):
            fp.write(delim.join(dispvals))
            fp.write('\n')

    status('%s save finished' % p)
github saulpw / visidata / visidata / loaders / tsv.py View on Github external
def tsv_trdict(vs):
    'returns string.translate dictionary for replacing tabs and newlines'
    if options.safety_first:
        delim = options.get('delimiter', vs)
        return {ord(delim): options.get('tsv_safe_tab', vs), # \t
            10: options.get('tsv_safe_newline', vs),  # \n
            13: options.get('tsv_safe_newline', vs),  # \r
            }
    return {}
github saulpw / visidata / visidata / loaders / tsv.py View on Github external
def tsv_trdict(vs):
    'returns string.translate dictionary for replacing tabs and newlines'
    if options.safety_first:
        delim = options.get('delimiter', vs)
        return {ord(delim): options.get('tsv_safe_tab', vs), # \t
            10: options.get('tsv_safe_newline', vs),  # \n
            13: options.get('tsv_safe_newline', vs),  # \r
            }
    return {}
github saulpw / visidata / visidata / loaders / tsv.py View on Github external
def tsv_trdict(vs):
    'returns string.translate dictionary for replacing tabs and newlines'
    if options.safety_first:
        delim = options.get('delimiter', vs)
        return {ord(delim): options.get('tsv_safe_tab', vs), # \t
            10: options.get('tsv_safe_newline', vs),  # \n
            13: options.get('tsv_safe_newline', vs),  # \r
            }
    return {}
github saulpw / visidata / visidata / man / parse_options.py View on Github external
widestoptwidth, widestopt = sorted((len(opt.name)+len(str(opt.value)), opt.name) for opt in optvalues)[-1]
        print('widest option+default is "%s", width %d' % (widestopt, widestoptwidth))
        widestoptwidth = 35
        menuOut.write('.Bl -tag -width %s -compact\n' % ('X'*(widestoptwidth+3)))

#        cliwidth = max(padding+len(str(opt.value)) for opt in optvalues)
        cliwidth = 43
        print('using width for cli options of %d' % cliwidth)
        cliOut.write('.Bl -tag -width %s -compact\n' % ('X'*(cliwidth+3)))

        for opt in optvalues:
            if opt.name[:5] in ['color', 'disp_']:
                options_menu = options_menu_skel.format(optname=opt.name,
                                                        type=type(opt.value).__name__,
                                                        default=visidata.options.get(opt.name, 'global'),
                                                        description=opt.helpstr)
                menuOut.write(options_menu)
            else:
                cli_optname=opt.name.replace('_', '-')
                cli_type=type(opt.value).__name__
                optlen = len(cli_optname)+len(cli_type)+1
                cliOut.write(options_cli_skel.format(cli_optname=cli_optname,
                                                optname = opt.name,
                                                type=cli_type+" "*(padding-optlen),
                                                default=visidata.options.get(opt.name, 'global'),
                                                 description=opt.helpstr))

        menuOut.write('.El')
        cliOut.write('.El')