Open neteler opened 4 years ago
I have been experimenting with this, but I reached the conclusion that it is very difficult to find colour combination(s) that would work for every terminal setup. See for example just two examples:
This could only work if it is possible to set the colours and/or opt out of colouring at all.
It is also possible to set this on individual level. This is what I was experimenting with for zsh, before recent changes to prompt were made (so won't work with copy and paste), but for the general idea...
in ~/.grass.zshrc
:
# enable colors
setopt PROMPT_SUBST
autoload colors
colors
PS1_orig=$PS1
z_grass_version() {
g=`echo $PS1_orig | cut -d'(' -f 1`
echo "$g"
}
z_location() {
l=`echo $PS1_orig | cut -d'(' -f 2 | cut -d')' -f 1`
echo "%{$fg[cyan]%}$l%{$reset_color%}"
}
# current time with milliseconds
z_current_time() {
echo "%*"
}
z_return_status() {
echo "%(?..❗️)"
}
PS1='$(z_grass_version)(%B$(z_location)):%1~ > '
RPROMPT='$(grass_prompt) $(z_current_time)$(z_return_status)'
Many command line tools use colors by default now (e.g., Git, Clang, GCC or have color aliases set at least on Ubuntu), so I think should be doable. Are these doing something special in terms of recognizing the available colors, color support, or default colors used in the terminal? What about things like bold? Are there terminals not supporting colors? Putty? Even xterm supports colors.
The example from Markus worked for me well enough in dark and light terminal as well as with green on black.
I could take this on. I started poking at the code and drafted something like this:
I'm thinking of introducing a few flags:
--monochrome
: Disables all colors--mapset-color
: Sets the prompt color of the mapset--location-color
: Sets the prompt color of the location--path-color
: Sets the prompt color of the pathWhat do you think of this plan?
Also I noticed that a lot of the shells end up using different kinds of prompts, do we want to somewhat unify them?
A small update. I decided that I'm going to go for a 2-line prompt that will look the same in most shells, rather than utilizing right-prompts, leaving that for less critical information such as time etc. Here is what it looks like in zsh (and bash)
Personally I like the 2-line prompt more, and by linking them together with the the box drawing characters it gives the the appearance of belonging together. Thoughts? Complaints? PR coming soon (once I tackle tcsh (and possibly ksh).
I don't have a windows nor a mac, so will need some help with testing on those platforms, but it should work as it's using ANSI escape sequences which should just work...
Thoughts on the prompt... :thinking: Should we go with separate location & mapset or a combined project centric one?
I am unsure 2-line prompt is better, I am pretty happy with the current state on bash.
For me at least, having 2 path-like things makes it too easy to mix them up (but then again I'm dyslexic which makes these things harder). Having the prompt take up half the line of the whole terminal is also something I'm trying to avoid, so that you have more space for the actual command to fit on one line.
This works the same on both bash
and zsh
?
Yes! Actually I got it to fully work in bash, zsh and tcsh :grin:
Regarding colourising the prompt, I don't have a very strong opinion, as long as there is a way to opt out. I don't have the possibility at the moment to test out #2527 for Mac Terminal. However, I find it unfortunate to mix in changes for the prompt layout in the same PR. I definitely prefer the current 1-line zsh prompt with location and maps (or alternatively project) on the right hand, as is readily possible for zsh. I'm not too worried if it doesn't look the same for all shells. Two-line prompts add too much noise, especially when reading and/or copying the terminal history.
Is your feature request related to a problem? Please describe.
As a followup to #923 I'd suggest to use colors for the prompt.
Current implementation (bash):
Proposed change (bash):
PS1='\[\e[0;1;38;5;28m\]GRASS\[\e[m\] \[\e[0m\]$_GRASS_DB_PLACE:\[\e[0;96m\]\W\[\e[m\] \[\e[0m\]>\[\e0'
(for testing, simply add to
$HOME/.grass.bashrc
)I have generated this PS1 string easily with:
There are similar ones for other shells, e.g.
Would be cool to see that added somehow.