51
# rbprompt
A golang prompt generator for shells, with a little colour in it. Tons of rainbows.
This is a library version of https://git.sophuwu.com/bashprompt translated to go.
This implementation has a slightly different feature set, but is still very similar.
My master liked my c++ prompt generator, and wanted to include it a golang shell she was writing.
So she asked me to make a go library with a few different features.
This library does not generate a usable PS1. It requires a wrapper to be used in a shell,
as my master didn't want a PS1 variable in her shell.
If you want to use this in a shell, download the c++ program, it works in bash straight out of the box.
## api overview
```go
// PS is the main struct for the prompt. It contains all the information needed to generate the prompt.
// After setting User, HostName, Home, PWD, and Fmt, call Next() to generate the prompt.
// Then call String() to get the prompt string and print it.
type PS struct {
// LineNo is the line number, defaults to 0, then increments by 1 each time Next() is called.
LineNo uint
// if NoColor is true, the prompt will be printed without any colors.
NoColor bool
// Current is the current prompt string, calculated by the last call to Next().
// Same as String().
Current string
// Fmt is the format string for the prompt. It can contain the following:
// %u = username
// %h = hostname
// %i = ip address as colours
// %e = random emote
// %l = line number
// %<n>p = bottom <n> directories in PWD
// %p = entire PWD, short for %0p
// adding #xxxxxx (hex colour) after any argument will set the colour of that argument. e.g. %u#ff0000 will set the username to red.
Fmt string
// Set User to the username of the current user, required if Fmt contains "%u".
User string
// Set Home to the home directory of the current user, required if Fmt contains "%p" or %<n>p.
Home string
// Set HostName to the hostname of the current machine, required if Fmt contains "%h".
HostName string
// Set PWD to the current working directory, required if Fmt contains "%p" or %<n>p.
PWD string
// Set HostIP to the IP address of the current machine, required if Fmt contains "%i".
HostIP [4]byte
// Rainbow is the rainbow struct used to generate the rainbow effect.
Rainbow Rainbow
}
```