mirror of https://github.com/n1nj4sec/pupy.git
add option to disable server prompt coloring (dirty hack)
This commit is contained in:
parent
c2a3a00988
commit
42249f9564
|
@ -6,6 +6,7 @@ certfile = crypto/cert.pem
|
||||||
|
|
||||||
[cmdline]
|
[cmdline]
|
||||||
display_banner = yes
|
display_banner = yes
|
||||||
|
colors = yes
|
||||||
|
|
||||||
[aliases]
|
[aliases]
|
||||||
info = get_info
|
info = get_info
|
||||||
|
|
|
@ -44,6 +44,7 @@ from .PupyJob import PupyJob
|
||||||
import argparse
|
import argparse
|
||||||
from pupysh import __version__
|
from pupysh import __version__
|
||||||
import copy
|
import copy
|
||||||
|
from functools import partial
|
||||||
|
|
||||||
BANNER="""
|
BANNER="""
|
||||||
_____ _ _ _
|
_____ _ _ _
|
||||||
|
@ -56,12 +57,14 @@ BANNER="""
|
||||||
"""%__version__
|
"""%__version__
|
||||||
|
|
||||||
|
|
||||||
def color(s, color, prompt=False):
|
def color_real(s, color, prompt=False, colors_enabled=True):
|
||||||
""" color a string using ansi escape characters. set prompt to true to add marks for readline to see invisible portions of the prompt
|
""" color a string using ansi escape characters. set prompt to true to add marks for readline to see invisible portions of the prompt
|
||||||
cf. http://stackoverflow.com/questions/9468435/look-how-to-fix-column-calculation-in-python-readline-if-use-color-prompt"""
|
cf. http://stackoverflow.com/questions/9468435/look-how-to-fix-column-calculation-in-python-readline-if-use-color-prompt"""
|
||||||
if s is None:
|
if s is None:
|
||||||
return ""
|
return ""
|
||||||
s=str(s)
|
s=str(s)
|
||||||
|
if not colors_enabled:
|
||||||
|
return s
|
||||||
res=s
|
res=s
|
||||||
COLOR_STOP="\033[0m"
|
COLOR_STOP="\033[0m"
|
||||||
prompt_stop=""
|
prompt_stop=""
|
||||||
|
@ -118,16 +121,21 @@ def obj2utf8(obj):
|
||||||
return obj
|
return obj
|
||||||
|
|
||||||
class PupyCmd(cmd.Cmd):
|
class PupyCmd(cmd.Cmd):
|
||||||
intro = color(BANNER, 'green')
|
|
||||||
prompt = color('>> ','blue', prompt=True)
|
|
||||||
doc_header = 'Available commands :\n'
|
|
||||||
complete_space=['run']
|
|
||||||
def __init__(self, pupsrv, configFile="pupy.conf"):
|
def __init__(self, pupsrv, configFile="pupy.conf"):
|
||||||
cmd.Cmd.__init__(self)
|
cmd.Cmd.__init__(self)
|
||||||
self.pupsrv=pupsrv
|
self.pupsrv=pupsrv
|
||||||
self.config = configparser.ConfigParser()
|
self.config = configparser.ConfigParser()
|
||||||
self.config.read(configFile)
|
self.config.read(configFile)
|
||||||
self.init_readline()
|
self.init_readline()
|
||||||
|
global color
|
||||||
|
try:
|
||||||
|
color = partial(color_real, colors_enabled=self.config.getboolean("cmdline","colors"))
|
||||||
|
except Exception:
|
||||||
|
color = color_real
|
||||||
|
self.intro = color(BANNER, 'green')
|
||||||
|
self.prompt = color('>> ','blue', prompt=True)
|
||||||
|
self.doc_header = 'Available commands :\n'
|
||||||
|
self.complete_space=['run']
|
||||||
try:
|
try:
|
||||||
if not self.config.getboolean("cmdline","display_banner"):
|
if not self.config.getboolean("cmdline","display_banner"):
|
||||||
self.intro=""
|
self.intro=""
|
||||||
|
|
Loading…
Reference in New Issue