formatters
The community/core/formatters
directory contains the core logic and configuration for text formatting within the Talon system. This system allows users to transform dictated text into various formats, such as camel case, snake case, or quoted strings.
The primary component is formatters.py
, which defines several classes that perform the actual formatting:
Formatter
: An abstract base class for all formatters, defining theformat
andunformat
methods.CustomFormatter
: A formatter that takes format and unformat functions as arguments.CodeFormatter
: A formatter that splits text into words, applies a format to the first word and the rest of the words, and adds delimiters between the words.TitleFormatter
: A formatter that transforms text into title case.CapitalizeFormatter
: A formatter that capitalizes the first word of a text.SentenceFormatter
: A formatter that capitalizes the first word of a text if it's not already capitalized.
The formatters.py
file also defines helper functions for capitalization, lowercasing, and removing code formatting. It includes a list of formatters called formatter_list
that is used to initialize a formatters_dict
. It also defines Talon actions for formatting text and reformatting the last phrase and selection. The most important functions for formatting text are format_phrase
and format_text_without_adding_to_history
, which are used to apply a chain of formatters to a text.
The other files in this directory are Talon lists that are used to define how users will activate each formatter:
word_formatter.talon-list
: Defines a listuser.word_formatter
containing NOOP, TRAILING_SPACE, CAPITALIZE_FIRST_WORD, and TRAILING_SPACE,CAPITALIZE_FIRST_WORD.code_formatter.talon-list
: Defines a listuser.code_formatter
containing words that map to a comma separated list of formatters in formatters.py. For example, the word "camel" will apply thePRIVATE_CAMEL_CASE
formatter. These formatters are typically used for code.prose_formatter.talon-list
: Defines a listuser.prose_formatter
containing words that map to a comma separated list of formatters in formatters.py. For example, the word "sentence" will apply theCAPITALIZE_FIRST_WORD
formatter. These formatters are typically used for prose.reformatter.talon-list
: Defines a listuser.reformatter
containing words that map to a comma separated list of formatters in formatters.py. For example, the word "unformat" will apply theREMOVE_FORMATTING
formatter. These formatters are typically used for reformatting.
These files work together to provide a flexible and extensible system for formatting text in Talon. The Python code defines the logic of the formatters, while the Talon lists allow users to easily apply those formatters to their dictated text.