Skip to content

Commit 10a9d04

Browse files
committed
Simplified logic by adding guard clause for case that allow_style is NEVER
1 parent c773a79 commit 10a9d04

File tree

1 file changed

+8
-6
lines changed

1 file changed

+8
-6
lines changed

cmd2/pt_utils.py

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -244,8 +244,13 @@ def get_line(lineno: int) -> list[tuple[str, str]]:
244244
line = document.lines[lineno]
245245
tokens: list[tuple[str, str]] = []
246246

247+
# No syntax highlighting if styles are disallowed
248+
if ru.ALLOW_STYLE == ru.AllowStyle.NEVER:
249+
tokens.append(('', line))
250+
return tokens
251+
247252
# Only attempt to match a command on the first line
248-
if lineno == 0 and ru.ALLOW_STYLE != ru.AllowStyle.NEVER:
253+
if lineno == 0:
249254
# Use cmd2's command pattern to find the first word (the command)
250255
match = self.cmd_app.statement_parser._command_pattern.search(line)
251256
if match:
@@ -292,11 +297,8 @@ def get_line(lineno: int) -> list[tuple[str, str]]:
292297
# No command match found on the first line
293298
tokens.append(('', line))
294299
else:
295-
# All other lines are unstyled or treated as arguments
296-
if ru.ALLOW_STYLE != ru.AllowStyle.NEVER:
297-
highlight_args(line, tokens)
298-
else:
299-
tokens.append(('', line))
300+
# All other lines are treated as arguments
301+
highlight_args(line, tokens)
300302

301303
return tokens
302304

0 commit comments

Comments
 (0)