diff --git a/Gopkg.lock b/Gopkg.lock index de540d56..52c1f123 100644 --- a/Gopkg.lock +++ b/Gopkg.lock @@ -60,7 +60,7 @@ [[projects]] branch = "master" - digest = "1:09a1322d2fc6f021b23d389c045479cf4fe94fca0f504c61bb0ca2c67e244506" + digest = "1:32d8e0c62dc075d198abf73428828689f4e9473cadb8ef270be45fb78ae8648b" name = "github.com/evilsocket/islazy" packages = [ "fs", @@ -70,7 +70,7 @@ "zip", ] pruneopts = "UT" - revision = "acbee79ddc39664d9a6ef5b2c4306dd470a58b2b" + revision = "fd12757cd7fd9e544ea374582c7015587d9ac534" [[projects]] branch = "master" diff --git a/session/events.go b/session/events.go index 5d05c1b2..c5b1c97f 100644 --- a/session/events.go +++ b/session/events.go @@ -32,8 +32,8 @@ func NewEvent(tag string, data interface{}) Event { func (e Event) Label() string { m := e.Data.(LogMessage) - label := log.LevelNames[m.Level] - color := log.LevelColors[m.Level] + label := log.LevelName(m.Level) + color := log.LevelColor(m.Level) return color + label + tui.RESET } diff --git a/session/prompt.go b/session/prompt.go index 936cd7c8..e2e0f627 100644 --- a/session/prompt.go +++ b/session/prompt.go @@ -15,24 +15,7 @@ const ( ) var ( - // these are here because if colors are disabled, - // we need the updated tui.* variables - effects = map[string]string{ - "{bold}": tui.BOLD, - "{dim}": tui.DIM, - "{r}": tui.RED, - "{g}": tui.GREEN, - "{b}": tui.BLUE, - "{y}": tui.YELLOW, - "{fb}": tui.FOREBLACK, - "{fw}": tui.FOREWHITE, - "{bdg}": tui.BACKDARKGRAY, - "{br}": tui.BACKRED, - "{bg}": tui.BACKGREEN, - "{by}": tui.BACKYELLOW, - "{blb}": tui.BACKLIGHTBLUE, // Ziggy this is for you <3 - "{reset}": tui.RESET, - } + effects = map[string]string{} PromptCallbacks = map[string]func(s *Session) string{ "{cidr}": func(s *Session) string { return s.Interface.CIDR() @@ -62,6 +45,24 @@ type Prompt struct { } func NewPrompt() Prompt { + // these are here because if colors are disabled, + // we need the updated tui.* variables + effects = map[string]string{ + "{bold}": tui.BOLD, + "{dim}": tui.DIM, + "{r}": tui.RED, + "{g}": tui.GREEN, + "{b}": tui.BLUE, + "{y}": tui.YELLOW, + "{fb}": tui.FOREBLACK, + "{fw}": tui.FOREWHITE, + "{bdg}": tui.BACKDARKGRAY, + "{br}": tui.BACKRED, + "{bg}": tui.BACKGREEN, + "{by}": tui.BACKYELLOW, + "{blb}": tui.BACKLIGHTBLUE, // Ziggy this is for you <3 + "{reset}": tui.RESET, + } return Prompt{} } diff --git a/session/session.go b/session/session.go index a372688e..02f81d47 100644 --- a/session/session.go +++ b/session/session.go @@ -95,13 +95,22 @@ type Session struct { } func New() (*Session, error) { - var err error + opts, err := core.ParseOptions() + if err != nil { + return nil, err + } + + if *opts.NoColors || !tui.Effects() { + tui.Disable() + log.NoEffects = true + } s := &Session{ - Prompt: NewPrompt(), - Env: nil, - Active: false, - Queue: nil, + Prompt: NewPrompt(), + Options: opts, + Env: nil, + Active: false, + Queue: nil, CoreHandlers: make([]CommandHandler, 0), Modules: make([]Module, 0), @@ -109,15 +118,6 @@ func New() (*Session, error) { UnkCmdCallback: nil, } - if s.Options, err = core.ParseOptions(); err != nil { - return nil, err - } - - if *s.Options.NoColors || !tui.Effects() { - tui.Disable() - log.NoEffects = true - } - if *s.Options.CpuProfile != "" { if f, err := os.Create(*s.Options.CpuProfile); err != nil { return nil, err diff --git a/vendor/github.com/evilsocket/islazy/log/level.go b/vendor/github.com/evilsocket/islazy/log/level.go index 10fda7fc..2c9b7e1f 100644 --- a/vendor/github.com/evilsocket/islazy/log/level.go +++ b/vendor/github.com/evilsocket/islazy/log/level.go @@ -42,3 +42,16 @@ var ( FATAL: tui.FOREWHITE + tui.BACKRED + tui.BOLD, } ) + +// LevelName returns the name of a verbosity level. +func LevelName(v Verbosity) string { + return LevelNames[v] +} + +// LevelColor returns the color of a verbosity level or "" if effects are disabled. +func LevelColor(v Verbosity) string { + if NoEffects { + return "" + } + return LevelColors[v] +}