def get_input(self, field, oldvalue, new): """Gets a value from command line input. :param field: The fieldname of the edited field :param oldvalue: The old value of the field :param new: Whether the entry is new""" if new: prompt = '%s: ' % phonebook.translate_field(field) else: prompt = '%s [%s]: ' prompt = prompt % (phonebook.translate_field(field), oldvalue) prompt = prompt.encode(tel.CONFIG.STDOUT_ENCODING) return raw_input(prompt)
def get_input(self, field, oldvalue, new): """Gets a value from command line input. :param field: The fieldname of the edited field :param oldvalue: The old value of the field :param new: Whether the entry is new""" if not new: self.oldvalue = oldvalue else: self.oldvalue = None prompt = '%s: ' % phonebook.translate_field(field) prompt = prompt.encode(_STDOUT_ENCODING) return raw_input(prompt)
def get_fields(self): """Return a table of field names""" items = [(phonebook.translate_field(field), field) for field in phonebook.FIELDS] headline = [_('Field'), _('Internal name')] column_widths = map(len, headline) for item in items: column_widths = map(max, map(len, item), column_widths) headline = ' - '.join(map(lambda item, width: item.center(width), headline, column_widths)) separator = '-' * (column_widths[0] + column_widths[1] + 5) table = [' '+headline, separator] for item in items: item = ' - '.join(map(lambda item,width: item.ljust(width), item, column_widths)) table.append(' '+item) return '\n'.join(table)
def enc_tr_field(field): """Returns translation for `field` in appropriate encoding for console output. Should only be used, where absolutly necessary.""" return phonebook.translate_field(field).encode(tel.CONFIG.STDOUT_ENCODING)