| 1 | package sessionscip-go gomod github.com/bettercap/bettercap . `github.com/bettercap/bettercap/session`/ |
| 2 | |
| 3 | import ( |
| 4 | "fmtscip-go gomod github.com/golang/go/src go1.16 fmt/" |
| 5 | "stringsscip-go gomod github.com/golang/go/src go1.16 strings/" |
| 6 | |
| 7 | "github.com/evilsocket/islazy/tuiscip-go gomod github.com/evilsocket/islazy v1.11.0 `github.com/evilsocket/islazy/tui`/" |
| 8 | |
| 9 | "github.com/dustin/go-humanizescip-go gomod github.com/dustin/go-humanize v1.0.1 `github.com/dustin/go-humanize`/" |
| 10 | ) |
| 11 | |
| 12 | const ( |
| 13 | PromptVariablescip-go gomod github.com/bettercap/bettercap . `github.com/bettercap/bettercap/session`/PromptVariable. = "$" |
| 14 | DefaultPromptscip-go gomod github.com/bettercap/bettercap . `github.com/bettercap/bettercap/session`/DefaultPrompt. = "{by}{fw}{cidr} {fb}> {env.iface.ipv4} {reset} {bold}» {reset}" |
| 15 | DefaultPromptMonitorscip-go gomod github.com/bettercap/bettercap . `github.com/bettercap/bettercap/session`/DefaultPromptMonitor. = "{by}{fb} {env.iface.name} {reset} {bold}» {reset}" |
| 16 | ) |
| 17 | |
| 18 | var ( |
| 19 | effectsscip-go gomod github.com/bettercap/bettercap . `github.com/bettercap/bettercap/session`/effects. = map[string]string{} |
| 20 | PromptCallbacksscip-go gomod github.com/bettercap/bettercap . `github.com/bettercap/bettercap/session`/PromptCallbacks. = map[string]func(sscip-go gomod github.com/bettercap/bettercap . `github.com/bettercap/bettercap/session`/PromptCallbacks:s. *Sessionscip-go gomod github.com/bettercap/bettercap . `github.com/bettercap/bettercap/session`/Session#) string{ |
| 21 | "{cidr}": func(sscip-go gomod github.com/bettercap/bettercap . `github.com/bettercap/bettercap/session`/PromptCallbacks:s. *Sessionscip-go gomod github.com/bettercap/bettercap . `github.com/bettercap/bettercap/session`/Session#) string { |
| 22 | return sscip-go gomod github.com/bettercap/bettercap . `github.com/bettercap/bettercap/session`/PromptCallbacks:s..Interfacescip-go gomod github.com/bettercap/bettercap . `github.com/bettercap/bettercap/session`/Session#Interface..CIDRscip-go gomod github.com/bettercap/bettercap . `github.com/bettercap/bettercap/network`/Endpoint#CIDR().() |
| 23 | }, |
| 24 | "{net.sent}": func(sscip-go gomod github.com/bettercap/bettercap . `github.com/bettercap/bettercap/session`/PromptCallbacks:s. *Sessionscip-go gomod github.com/bettercap/bettercap . `github.com/bettercap/bettercap/session`/Session#) string { |
| 25 | return fmtscip-go gomod github.com/golang/go/src go1.16 fmt/.Sprintfscip-go gomod github.com/golang/go/src go1.16 fmt/Sprintf().("%d", sscip-go gomod github.com/bettercap/bettercap . `github.com/bettercap/bettercap/session`/PromptCallbacks:s..Queuescip-go gomod github.com/bettercap/bettercap . `github.com/bettercap/bettercap/session`/Session#Queue..Statsscip-go gomod github.com/bettercap/bettercap . `github.com/bettercap/bettercap/packets`/Queue#Stats..Sentscip-go gomod github.com/bettercap/bettercap . `github.com/bettercap/bettercap/packets`/Stats#Sent.) |
| 26 | }, |
| 27 | "{net.sent.human}": func(sscip-go gomod github.com/bettercap/bettercap . `github.com/bettercap/bettercap/session`/PromptCallbacks:s. *Sessionscip-go gomod github.com/bettercap/bettercap . `github.com/bettercap/bettercap/session`/Session#) string { |
| 28 | return humanizescip-go gomod github.com/dustin/go-humanize v1.0.1 `github.com/dustin/go-humanize`/.Bytesscip-go gomod github.com/dustin/go-humanize v1.0.1 `github.com/dustin/go-humanize`/Bytes().(sscip-go gomod github.com/bettercap/bettercap . `github.com/bettercap/bettercap/session`/PromptCallbacks:s..Queuescip-go gomod github.com/bettercap/bettercap . `github.com/bettercap/bettercap/session`/Session#Queue..Statsscip-go gomod github.com/bettercap/bettercap . `github.com/bettercap/bettercap/packets`/Queue#Stats..Sentscip-go gomod github.com/bettercap/bettercap . `github.com/bettercap/bettercap/packets`/Stats#Sent.) |
| 29 | }, |
| 30 | "{net.received}": func(sscip-go gomod github.com/bettercap/bettercap . `github.com/bettercap/bettercap/session`/PromptCallbacks:s. *Sessionscip-go gomod github.com/bettercap/bettercap . `github.com/bettercap/bettercap/session`/Session#) string { |
| 31 | return fmtscip-go gomod github.com/golang/go/src go1.16 fmt/.Sprintfscip-go gomod github.com/golang/go/src go1.16 fmt/Sprintf().("%d", sscip-go gomod github.com/bettercap/bettercap . `github.com/bettercap/bettercap/session`/PromptCallbacks:s..Queuescip-go gomod github.com/bettercap/bettercap . `github.com/bettercap/bettercap/session`/Session#Queue..Statsscip-go gomod github.com/bettercap/bettercap . `github.com/bettercap/bettercap/packets`/Queue#Stats..Receivedscip-go gomod github.com/bettercap/bettercap . `github.com/bettercap/bettercap/packets`/Stats#Received.) |
| 32 | }, |
| 33 | "{net.received.human}": func(sscip-go gomod github.com/bettercap/bettercap . `github.com/bettercap/bettercap/session`/PromptCallbacks:s. *Sessionscip-go gomod github.com/bettercap/bettercap . `github.com/bettercap/bettercap/session`/Session#) string { |
| 34 | return humanizescip-go gomod github.com/dustin/go-humanize v1.0.1 `github.com/dustin/go-humanize`/.Bytesscip-go gomod github.com/dustin/go-humanize v1.0.1 `github.com/dustin/go-humanize`/Bytes().(sscip-go gomod github.com/bettercap/bettercap . `github.com/bettercap/bettercap/session`/PromptCallbacks:s..Queuescip-go gomod github.com/bettercap/bettercap . `github.com/bettercap/bettercap/session`/Session#Queue..Statsscip-go gomod github.com/bettercap/bettercap . `github.com/bettercap/bettercap/packets`/Queue#Stats..Receivedscip-go gomod github.com/bettercap/bettercap . `github.com/bettercap/bettercap/packets`/Stats#Received.) |
| 35 | }, |
| 36 | "{net.packets}": func(sscip-go gomod github.com/bettercap/bettercap . `github.com/bettercap/bettercap/session`/PromptCallbacks:s. *Sessionscip-go gomod github.com/bettercap/bettercap . `github.com/bettercap/bettercap/session`/Session#) string { |
| 37 | return fmtscip-go gomod github.com/golang/go/src go1.16 fmt/.Sprintfscip-go gomod github.com/golang/go/src go1.16 fmt/Sprintf().("%d", sscip-go gomod github.com/bettercap/bettercap . `github.com/bettercap/bettercap/session`/PromptCallbacks:s..Queuescip-go gomod github.com/bettercap/bettercap . `github.com/bettercap/bettercap/session`/Session#Queue..Statsscip-go gomod github.com/bettercap/bettercap . `github.com/bettercap/bettercap/packets`/Queue#Stats..PktReceivedscip-go gomod github.com/bettercap/bettercap . `github.com/bettercap/bettercap/packets`/Stats#PktReceived.) |
| 38 | }, |
| 39 | "{net.errors}": func(sscip-go gomod github.com/bettercap/bettercap . `github.com/bettercap/bettercap/session`/PromptCallbacks:s. *Sessionscip-go gomod github.com/bettercap/bettercap . `github.com/bettercap/bettercap/session`/Session#) string { |
| 40 | return fmtscip-go gomod github.com/golang/go/src go1.16 fmt/.Sprintfscip-go gomod github.com/golang/go/src go1.16 fmt/Sprintf().("%d", sscip-go gomod github.com/bettercap/bettercap . `github.com/bettercap/bettercap/session`/PromptCallbacks:s..Queuescip-go gomod github.com/bettercap/bettercap . `github.com/bettercap/bettercap/session`/Session#Queue..Statsscip-go gomod github.com/bettercap/bettercap . `github.com/bettercap/bettercap/packets`/Queue#Stats..Errorsscip-go gomod github.com/bettercap/bettercap . `github.com/bettercap/bettercap/packets`/Stats#Errors.) |
| 41 | }, |
| 42 | } |
| 43 | ) |
| 44 | |
| 45 | type Promptscip-go gomod github.com/bettercap/bettercap . `github.com/bettercap/bettercap/session`/Prompt# struct { |
| 46 | } |
| 47 | |
| 48 | func NewPromptscip-go gomod github.com/bettercap/bettercap . `github.com/bettercap/bettercap/session`/NewPrompt().() Promptscip-go gomod github.com/bettercap/bettercap . `github.com/bettercap/bettercap/session`/Prompt# { |
| 49 | // these are here because if colors are disabled, |
| 50 | // we need the updated tui.* variables |
| 51 | effectsscip-go gomod github.com/bettercap/bettercap . `github.com/bettercap/bettercap/session`/effects. = map[string]string{ |
| 52 | "{bold}": tuiscip-go gomod github.com/evilsocket/islazy v1.11.0 `github.com/evilsocket/islazy/tui`/.BOLDscip-go gomod github.com/evilsocket/islazy v1.11.0 `github.com/evilsocket/islazy/tui`/BOLD., |
| 53 | "{dim}": tuiscip-go gomod github.com/evilsocket/islazy v1.11.0 `github.com/evilsocket/islazy/tui`/.DIMscip-go gomod github.com/evilsocket/islazy v1.11.0 `github.com/evilsocket/islazy/tui`/DIM., |
| 54 | "{r}": tuiscip-go gomod github.com/evilsocket/islazy v1.11.0 `github.com/evilsocket/islazy/tui`/.REDscip-go gomod github.com/evilsocket/islazy v1.11.0 `github.com/evilsocket/islazy/tui`/RED., |
| 55 | "{g}": tuiscip-go gomod github.com/evilsocket/islazy v1.11.0 `github.com/evilsocket/islazy/tui`/.GREENscip-go gomod github.com/evilsocket/islazy v1.11.0 `github.com/evilsocket/islazy/tui`/GREEN., |
| 56 | "{b}": tuiscip-go gomod github.com/evilsocket/islazy v1.11.0 `github.com/evilsocket/islazy/tui`/.BLUEscip-go gomod github.com/evilsocket/islazy v1.11.0 `github.com/evilsocket/islazy/tui`/BLUE., |
| 57 | "{y}": tuiscip-go gomod github.com/evilsocket/islazy v1.11.0 `github.com/evilsocket/islazy/tui`/.YELLOWscip-go gomod github.com/evilsocket/islazy v1.11.0 `github.com/evilsocket/islazy/tui`/YELLOW., |
| 58 | "{fb}": tuiscip-go gomod github.com/evilsocket/islazy v1.11.0 `github.com/evilsocket/islazy/tui`/.FOREBLACKscip-go gomod github.com/evilsocket/islazy v1.11.0 `github.com/evilsocket/islazy/tui`/FOREBLACK., |
| 59 | "{fw}": tuiscip-go gomod github.com/evilsocket/islazy v1.11.0 `github.com/evilsocket/islazy/tui`/.FOREWHITEscip-go gomod github.com/evilsocket/islazy v1.11.0 `github.com/evilsocket/islazy/tui`/FOREWHITE., |
| 60 | "{bdg}": tuiscip-go gomod github.com/evilsocket/islazy v1.11.0 `github.com/evilsocket/islazy/tui`/.BACKDARKGRAYscip-go gomod github.com/evilsocket/islazy v1.11.0 `github.com/evilsocket/islazy/tui`/BACKDARKGRAY., |
| 61 | "{br}": tuiscip-go gomod github.com/evilsocket/islazy v1.11.0 `github.com/evilsocket/islazy/tui`/.BACKREDscip-go gomod github.com/evilsocket/islazy v1.11.0 `github.com/evilsocket/islazy/tui`/BACKRED., |
| 62 | "{bg}": tuiscip-go gomod github.com/evilsocket/islazy v1.11.0 `github.com/evilsocket/islazy/tui`/.BACKGREENscip-go gomod github.com/evilsocket/islazy v1.11.0 `github.com/evilsocket/islazy/tui`/BACKGREEN., |
| 63 | "{by}": tuiscip-go gomod github.com/evilsocket/islazy v1.11.0 `github.com/evilsocket/islazy/tui`/.BACKYELLOWscip-go gomod github.com/evilsocket/islazy v1.11.0 `github.com/evilsocket/islazy/tui`/BACKYELLOW., |
| 64 | "{blb}": tuiscip-go gomod github.com/evilsocket/islazy v1.11.0 `github.com/evilsocket/islazy/tui`/.BACKLIGHTBLUEscip-go gomod github.com/evilsocket/islazy v1.11.0 `github.com/evilsocket/islazy/tui`/BACKLIGHTBLUE., // Ziggy this is for you <3 |
| 65 | "{reset}": tuiscip-go gomod github.com/evilsocket/islazy v1.11.0 `github.com/evilsocket/islazy/tui`/.RESETscip-go gomod github.com/evilsocket/islazy v1.11.0 `github.com/evilsocket/islazy/tui`/RESET., |
| 66 | } |
| 67 | return Promptscip-go gomod github.com/bettercap/bettercap . `github.com/bettercap/bettercap/session`/Prompt#{} |
| 68 | } |
| 69 | |
| 70 | func (p Promptscip-go gomod github.com/bettercap/bettercap . `github.com/bettercap/bettercap/session`/Prompt#) Renderscip-go gomod github.com/bettercap/bettercap . `github.com/bettercap/bettercap/session`/Prompt#Render().(s *Sessionscip-go gomod github.com/bettercap/bettercap . `github.com/bettercap/bettercap/session`/Session#) string { |
| 71 | found, prompt := s.Envscip-go gomod github.com/bettercap/bettercap . `github.com/bettercap/bettercap/session`/Session#Env..Getscip-go gomod github.com/bettercap/bettercap . `github.com/bettercap/bettercap/session`/Environment#Get().(PromptVariablescip-go gomod github.com/bettercap/bettercap . `github.com/bettercap/bettercap/session`/PromptVariable.) |
| 72 | if !found { |
| 73 | prompt = DefaultPromptscip-go gomod github.com/bettercap/bettercap . `github.com/bettercap/bettercap/session`/DefaultPrompt. |
| 74 | } |
| 75 | |
| 76 | for tok, effect := range effectsscip-go gomod github.com/bettercap/bettercap . `github.com/bettercap/bettercap/session`/effects. { |
| 77 | prompt = stringsscip-go gomod github.com/golang/go/src go1.16 strings/.Replacescip-go gomod github.com/golang/go/src go1.16 strings/Replace().(prompt, tok, effect, -1) |
| 78 | } |
| 79 | |
| 80 | for tok, cb := range PromptCallbacksscip-go gomod github.com/bettercap/bettercap . `github.com/bettercap/bettercap/session`/PromptCallbacks. { |
| 81 | prompt = stringsscip-go gomod github.com/golang/go/src go1.16 strings/.Replacescip-go gomod github.com/golang/go/src go1.16 strings/Replace().(prompt, tok, cb(s), -1) |
| 82 | } |
| 83 | |
| 84 | // make sure an user error does not screw all terminal |
| 85 | if !stringsscip-go gomod github.com/golang/go/src go1.16 strings/.HasPrefixscip-go gomod github.com/golang/go/src go1.16 strings/HasPrefix().(prompt, tuiscip-go gomod github.com/evilsocket/islazy v1.11.0 `github.com/evilsocket/islazy/tui`/.RESETscip-go gomod github.com/evilsocket/islazy v1.11.0 `github.com/evilsocket/islazy/tui`/RESET.) { |
| 86 | prompt += tuiscip-go gomod github.com/evilsocket/islazy v1.11.0 `github.com/evilsocket/islazy/tui`/.RESETscip-go gomod github.com/evilsocket/islazy v1.11.0 `github.com/evilsocket/islazy/tui`/RESET. |
| 87 | } |
| 88 | |
| 89 | return prompt |
| 90 | } |