Skip to content

Commit d282581

Browse files
author
RIOUX Guilhem
committed
Arsenal without tags shown
1 parent c025b78 commit d282581

File tree

2 files changed

+65
-33
lines changed

2 files changed

+65
-33
lines changed

arsenal/app.py

+3
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,7 @@ def get_args(self):
4949
group_out.add_argument('-t', '--tmux', action='store_true', help='Send command to tmux panel')
5050
group_out.add_argument('-c', '--check', action='store_true', help='Check the existing commands')
5151
group_out.add_argument('-f', '--prefix', action='store_true', help='command prefix')
52+
group_out.add_argument('--no-tags', action='store_false', help='Whether or not to show the tags when drawing the cheats')
5253
parser.add_argument('-V', '--version', action='version', version='%(prog)s (version {})'.format(__version__))
5354

5455
return parser.parse_args()
@@ -66,6 +67,8 @@ def run(self):
6667
self.start(args, cheatsheets)
6768

6869
def start(self, args, cheatsheets):
70+
arsenal_gui.Gui.with_tags = args.no_tags
71+
6972
# create gui object
7073
gui = arsenal_gui.Gui()
7174
while True:

arsenal/modules/gui.py

+62-33
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
from os import sep
88
import glob
99

10-
#  local
10+
# local
1111
from . import config
1212
from . import command
1313

@@ -85,46 +85,51 @@ def draw_cheat(win, cheat, selected):
8585
prompt = '> '
8686
max_width = win_width - len(prompt) - len("\n")
8787

88-
col4_size = math.floor(max_width * 14 / 100)
89-
col3_size = math.floor(max_width * 8 / 100)
90-
col1_size = math.floor(max_width * 23 / 100)
91-
col2_size = math.floor(max_width * 55 / 100)
92-
# col0_size = math.floor(max_width * 20 / 100)
93-
9488
title = cheat.tags if cheat.tags != '' else cheat.str_title
9589

9690
tags = cheat.get_tags()
9791

92+
columns_list = ["title", "name", "description"]
93+
if Gui.with_tags:
94+
columns_list = ["tags"] + columns_list
95+
96+
get_col_size = lambda ratio: math.floor( (max_width * ratio) / 100)
97+
ratios = Gui.get_ratios_for_column(columns_list)
98+
99+
columns = {
100+
"tags": {
101+
"width": get_col_size(ratios.get("tags", 0)),
102+
"val": tags,
103+
"color": Gui.COL4_COLOR_SELECT if selected else Gui.COL4_COLOR
104+
},
105+
"title": {
106+
"width": get_col_size(ratios.get("title", 0)),
107+
"val": cheat.str_title,
108+
"color": Gui.COL3_COLOR_SELECT if selected else Gui.COL1_COLOR
109+
},
110+
"name": {
111+
"width": get_col_size(ratios.get("name", 0)),
112+
"val": cheat.name,
113+
"color": Gui.COL2_COLOR_SELECT if selected else Gui.COL2_COLOR
114+
},
115+
"description": {
116+
"width": get_col_size(ratios.get("description", 0)),
117+
"val": cheat.printable_command,
118+
"color": Gui.COL3_COLOR_SELECT if selected else Gui.COL3_COLOR
119+
}
120+
}
121+
98122
if selected:
99123
win.addstr(prompt, curses.color_pair(Gui.CURSOR_COLOR_SELECT))
100-
win.addstr("{:{}s}".format(Gui.draw_string(tags, col4_size), col4_size),
101-
curses.color_pair(Gui.COL4_COLOR_SELECT))
102-
win.addstr("{:{}s}".format(Gui.draw_string(cheat.str_title, col3_size), col3_size),
103-
curses.color_pair(Gui.COL3_COLOR_SELECT))
104-
win.addstr("{:{}s}".format(Gui.draw_string(cheat.name, col1_size), col1_size),
105-
curses.color_pair(Gui.COL2_COLOR_SELECT))
106-
win.addstr("{:{}s}".format(Gui.draw_string(cheat.printable_command, col2_size), col2_size),
107-
curses.color_pair(Gui.COL3_COLOR_SELECT))
108-
# win.addstr("{:{}s}".format(Gui.draw_string(title, col0_size), col0_size),
109-
# curses.color_pair(Gui.COL1_COLOR_SELECT))
110-
win.addstr("\n")
111124
else:
112125
win.addstr(' ' * len(prompt), curses.color_pair(Gui.BASIC_COLOR))
113-
if tags.startswith('[W]'):
114-
win.addstr("{:{}s}".format(Gui.draw_string(tags, col4_size), col4_size),
115-
curses.color_pair(Gui.COL5_COLOR))
116-
else:
117-
win.addstr("{:{}s}".format(Gui.draw_string(tags, col4_size), col4_size),
118-
curses.color_pair(Gui.COL4_COLOR))
119-
win.addstr("{:{}s}".format(Gui.draw_string(cheat.str_title, col3_size), col3_size),
120-
curses.color_pair(Gui.COL1_COLOR))
121-
win.addstr("{:{}s}".format(Gui.draw_string(cheat.name, col1_size), col1_size),
122-
curses.color_pair(Gui.COL2_COLOR))
123-
win.addstr("{:{}s}".format(Gui.draw_string(cheat.printable_command, col2_size), col2_size),
124-
curses.color_pair(Gui.COL3_COLOR))
125-
# win.addstr("{:{}s}".format(Gui.draw_string(title, col0_size), col0_size),
126-
# curses.color_pair(Gui.COL1_COLOR))
127-
win.addstr("\n")
126+
127+
for column_name in columns_list:
128+
win.addstr("{:{}s}".format(Gui.draw_string(columns[column_name]["val"],
129+
columns[column_name]["width"]),
130+
columns[column_name]["width"]),
131+
curses.color_pair(columns[column_name]["color"]))
132+
win.addstr("\n")
128133

129134
def draw_cheatslistbox(self):
130135
"""
@@ -784,6 +789,9 @@ class Gui:
784789
INFO_CMD_COLOR = 0
785790
ARG_NAME_COLOR = 5
786791
loaded_menu = False
792+
with_tags = False
793+
794+
DEFAULT_RATIOS = {"tags": 14, "title": 8, "name": 23, "description": 55}
787795

788796
def __init__(self):
789797
self.cheats_menu = None
@@ -796,6 +804,27 @@ def init_colors():
796804
for i in range(0, 255):
797805
curses.init_pair(i + 1, i, -1)
798806

807+
@classmethod
808+
def get_ratios_for_column(cls, columns_in_use):
809+
"""
810+
Calculate the column size from the column to print
811+
812+
:param columns_in_use: List of the column to print when drawing the
813+
cheat
814+
:return: The updated ratios size of each columns
815+
"""
816+
missing_ratio = 0
817+
for col in cls.DEFAULT_RATIOS.keys():
818+
if col not in columns_in_use:
819+
missing_ratio += cls.DEFAULT_RATIOS.get(col)
820+
if not missing_ratio:
821+
return cls.DEFAULT_RATIOS
822+
823+
new_ratio = {}
824+
for column in columns_in_use:
825+
new_ratio[column] = math.floor(cls.DEFAULT_RATIOS[column] + missing_ratio / len(columns_in_use))
826+
return new_ratio
827+
799828
@staticmethod
800829
def draw_string(str_value, max_size):
801830
"""

0 commit comments

Comments
 (0)