xonsh.prompt.base#
Base prompt, provides PROMPT_FIELDS and prompt related functions
- class xonsh.prompt.base.BasePromptField(**kwargs)[source]#
- Parameters
- kwargs
attributes of the class will be set from this
- update(ctx: xonsh.prompt.base.PromptFields) None [source]#
will be called from PromptFields getter for each new prompt
- property name: str#
will be set during load.
Notes
fields with names such as
gitstatus.branch
mean they are defined in a module namedgitstatus
and are most likely a subfield used bygitstatus
- updator: tp.Callable[[FieldType, PromptFields], None] | None = None#
this is a callable that needs to update the value or any of the attribute of the field
- value = ''#
This field should hold the bare value of the field without any color/format strings
- class xonsh.prompt.base.MultiPromptField(*fragments: str, **kwargs)[source]#
Facilitate combining other PromptFields
- Parameters
- kwargs
attributes of the class will be set from this
- update(ctx: xonsh.prompt.base.PromptFields)[source]#
will be called from PromptFields getter for each new prompt
- classmethod wrap(**kwargs) tp.Callable[..., FieldType] #
decorator to set the updator
- fragments: tuple[str, ...] = ()#
name of the fields or the literals to combine. If the framgment name startswith
.
then they are resolved to include the name of this field.
- property name: str#
will be set during load.
Notes
fields with names such as
gitstatus.branch
mean they are defined in a module namedgitstatus
and are most likely a subfield used bygitstatus
- separator = ''#
in case this combines values from other prompt fields
- updator: tp.Callable[[FieldType, PromptFields], None] | None = None#
this is a callable that needs to update the value or any of the attribute of the field
- value = ''#
This field should hold the bare value of the field without any color/format strings
- class xonsh.prompt.base.ParsedTokens(tokens, template)[source]#
Create new instance of ParsedTokens(tokens, template)
- count(value, /)#
Return number of occurrences of value.
- index(value, start=0, stop=sys.maxsize, /)#
Return first index of value.
Raises ValueError if the value is not present.
- process() str [source]#
Wrapper that gets formatter-function from environment and returns final prompt.
- update(idx: int, val: Optional[str], spec: Optional[str], conv: Optional[str]) None [source]#
Update tokens list in-place
- template: Union[str, Callable]#
Alias for field number 1
- tokens: List[xonsh.prompt.base._ParsedToken]#
Alias for field number 0
- class xonsh.prompt.base.PromptField(**kwargs)[source]#
Any new non-private attributes set by the sub-classes are considered a way to configure the format
- Parameters
- kwargs
attributes of the class will be set from this
- update(ctx: xonsh.prompt.base.PromptFields) None #
will be called from PromptFields getter for each new prompt
- classmethod wrap(**kwargs) tp.Callable[..., FieldType] #
decorator to set the updator
- property name: str#
will be set during load.
Notes
fields with names such as
gitstatus.branch
mean they are defined in a module namedgitstatus
and are most likely a subfield used bygitstatus
- prefix = ''#
- suffix = ''#
- updator: tp.Callable[[FieldType, PromptFields], None] | None = None#
this is a callable that needs to update the value or any of the attribute of the field
- value = ''#
This field should hold the bare value of the field without any color/format strings
- class xonsh.prompt.base.PromptFields(xsh: XonshSession, init=True)[source]#
Mapping of functions available for prompt-display.
- clear() None. Remove all items from D. #
- get(k[, d]) D[k] if k in D, else d. d defaults to None. #
- get_fields(module)[source]#
Find and load all instances of PromptField from the given module.
Each module is expected to have a single prompt-field with the same name as the module
- items() a set-like object providing a view on D's items #
- keys() a set-like object providing a view on D's keys #
- pick(key: str | FieldType) str | FieldType | None [source]#
Get the value of the prompt-field
Notes
If it is callable, then the result of the callable is returned. If it is a PromptField then it is updated
- pop(k[, d]) v, remove specified key and return the corresponding value. #
If key is not found, d is returned if given, otherwise KeyError is raised.
- popitem() (k, v), remove and return some (key, value) pair #
as a 2-tuple; but raise KeyError if D is empty.
- setdefault(k[, d]) D.get(k,d), also set D[k]=d if k not in D #
- update([E, ]**F) None. Update D from mapping/iterable E and F. #
If E present and has a .keys() method, does: for k in E: D[k] = E[k] If E present and lacks .keys() method, does: for (k, v) in E: D[k] = v In either case, this is followed by: for k, v in F.items(): D[k] = v
- values() an object providing a view on D's values #
- class xonsh.prompt.base.PromptFormatter[source]#
Class that holds all the related prompt formatting methods, uses the
PROMPT_FIELDS
envvar (no color formatting).
- xonsh.prompt.base.is_template_string(template, PROMPT_FIELDS=None)[source]#
Returns whether or not the string is a valid template.
- xonsh.prompt.base.multiline_prompt(curr='')[source]#
Returns the filler text for the prompt in multiline scenarios.
- xonsh.prompt.base.prompt_tokens_formatter_default(container: xonsh.prompt.base.ParsedTokens) str [source]#
Join the tokens
- Parameters
- container: ParsedTokens
parsed tokens holder
- Returns
- str
process the tokens and finally return the prompt string