khard.formatter
===============

.. py:module:: khard.formatter

.. autoapi-nested-parse::

   Formatting and sorting of contacts



Classes
-------

.. autoapisummary::

   khard.formatter.Formatter


Module Contents
---------------

.. py:class:: Formatter(display: str, preferred_email: list[str], preferred_phone: list[str], show_nicknames: bool, parsable: bool)

   A formatter for Contact.

   It receives some settings on initialisation which influence the formatting
   of the contact.


   .. py:attribute:: FIRST
      :value: 'first_name'



   .. py:attribute:: LAST
      :value: 'last_name'



   .. py:attribute:: FORMAT
      :value: 'formatted_name'



   .. py:attribute:: _display


   .. py:attribute:: _preferred_email


   .. py:attribute:: _preferred_phone


   .. py:attribute:: _show_nicknames


   .. py:attribute:: _parsable


   .. py:method:: format_labeled_field(field: dict[str, list[str]], preferred: list[str]) -> str
      :staticmethod:


      Format a labeled field from a vCard for display, the first entry
      under the preferred label will be returned

      :param field: the labeled field, this must not be empty!
      :param preferred: the order of preferred labels
      :returns: the formatted field entry



   .. py:method:: get_special_field(vcard: khard.contacts.Contact, field: str) -> str

      Returns certain fields with specific formatting options
      (for support of some list command options).



   .. py:method:: get_nested_field(vcard: khard.contacts.Contact, field: str) -> str
      :staticmethod:


      Returns the value of a nested field from a string

      get_nested_field(vcard,'emails.home.1') is equivalent to
      vcard.emails['home'][1].

      :param vcard: the contact from which to get the field
      :param field: a field specification
      :returns: the nested field, or the empty string if it didn't exist



