prompt-toolkit / prompt-toolkit/python-prompt-toolkit

Customizable prompt with various tokens

Open
#718 4 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
Python
Stars
10.6k
Forks
815
PR merge metrics
No merged PRs in 30d

Description

The request is to create beautiful prompts to have an ability to customize prompt string with extendable list of parameters and coloring.

For some programs like iPython or ptpython users usually don't require something very specific like time or database or path, but users for other applications like mycli or pgcli usually require some parameters specified in the prompt.

It's fine when you able to specify coloring for whole line if it's short or isn't informative. But if you in mycli/pgcli add date, user, host and a database, I'd like to have whole line be colored as I do it in my shell.

Simplified version of my PS1 setup in my .zshrc (without custom VCS calls) looks like on picture and a script below (database is a plain string).

I'd like to have the the same simple mechanism to specify variables and custom colors for them. This library able to color complex syntax while input and it seems to be capable to handle such prompt configuration as well.

This includes rprompt parameter too, but for me the priority is the prompt string itself.

zrzut ekranu 2018-09-06 o 14 55 12

autoload colors
colors

export PS1="[%{%F{165}%}%D %{%F{226}%}%*%{$reset_color%}] %{%F{214}%}%U%n%u%{$reset_color%}@%{%F{46}%}%M%{$reset_color%} (%{${fg_bold[yellow]}%}database%{$reset_color%})> "

Short info on format script above:

  • %F is color from a table
  • %D is a date in format yy-mm-dd (18-09-06)
  • %D{%C-%D} with custom specify strftime format if I'm not satisfied with defaults
  • %* is time in usual format 14:41:14
  • %n is user
  • %M is hostname
  • database is mycli/pgcli specific token and written here as a plain word
  • %{...%} keeps shell sane in terms and used for prompt length calculations

Contributor guide

No contributing guide indexed for this repository

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start by locating the library's prompt and rprompt configuration entry points. Compare the requested date, time, user, host, database, token, and per-token coloring behavior with the existing prompt API, then define tests that demonstrate configurable values, colors, and prompt-length handling.

Written by the indexing model from the issue text.

Assessment

Tech stack
python, zsh
Domain
cli
Issue type
Feature
Difficulty
5/5
Estimated time
Over a week
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
25/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.