Skip to content

Commit 778d6dc

Browse files
committed
run/README: Configuration infrastructure to enable/disable transparency.
This hooks up the underlying feature from the previous commit to new configuration options possible in the zuliprc file, which can be overridden by command-line options. These take the same form as for notifications and autohide, with - `transparency=enabled|disabled` in zuliprc - `--transparency` or `-no-transparency` on the command-line The default value for this option is to be disabled. This value is not currently passed to the Controller, since the theme is generated in run.py. README updated to indicate new transparency configuration option. Tests updated.
1 parent c51218c commit 778d6dc

File tree

3 files changed

+44
-5
lines changed

3 files changed

+44
-5
lines changed

README.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -246,6 +246,11 @@ notify=disabled
246246
247247
## Color-depth: set to one of 1 (for monochrome), 16, 256, or 24bit
248248
color-depth=256
249+
250+
## Transparency: set to 'enabled' to allow background transparency
251+
## This is highly dependent on a suitable terminal emulator, and support in the selected theme
252+
## Terminal emulators without this feature may show an arbitrary solid background color
253+
transparency=disabled
249254
```
250255

251256
> **NOTE:** Most of these configuration settings may be specified on the

tests/cli/test_run.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -143,6 +143,8 @@ def test_main_help(capsys: CaptureFixture[str], options: str) -> None:
143143
"--color-depth",
144144
"--notify",
145145
"--no-notify",
146+
"--transparency",
147+
"--no-transparency",
146148
}
147149
optional_argument_lines = {
148150
line[2:] for line in lines if len(line) > 2 and line[2] == "-"
@@ -203,6 +205,7 @@ def test_valid_zuliprc_but_no_connection(
203205
" maximum footlinks value '3' specified from default config.",
204206
" color depth setting '256' specified from default config.",
205207
" notify setting 'disabled' specified from default config.",
208+
" transparency setting 'disabled' specified from default config.",
206209
"\x1b[91m",
207210
f"Error connecting to Zulip server: {server_connection_error}.\x1b[0m",
208211
]
@@ -262,6 +265,7 @@ def test_warning_regarding_incomplete_theme(
262265
" maximum footlinks value '3' specified from default config.",
263266
" color depth setting '256' specified from default config.",
264267
" notify setting 'disabled' specified from default config.",
268+
" transparency setting 'disabled' specified from default config.",
265269
"\x1b[91m",
266270
f"Error connecting to Zulip server: {server_connection_error}.\x1b[0m",
267271
]
@@ -481,6 +485,7 @@ def test_successful_main_function_with_config(
481485
f" maximum footlinks value {footlinks_output}",
482486
" color depth setting '256' specified in zuliprc file.",
483487
" notify setting 'enabled' specified in zuliprc file.",
488+
" transparency setting 'disabled' specified from default config.",
484489
]
485490
assert lines == expected_lines
486491

zulipterminal/cli/run.py

Lines changed: 34 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,7 @@ class SettingData(NamedTuple):
6262
"autohide": ("autohide", "no_autohide"),
6363
"notify": ("enabled", "disabled"),
6464
"exit_confirmation": ("enabled", "disabled"),
65+
"transparency": ("enabled", "disabled"),
6566
}
6667

6768
COLOR_DEPTH_ARGS_TO_DEPTHS: Dict[str, int] = {
@@ -80,13 +81,15 @@ class SettingData(NamedTuple):
8081
"color-depth": "256",
8182
"maximum-footlinks": "3",
8283
"exit_confirmation": "enabled",
84+
"transparency": "disabled",
8385
}
8486
assert DEFAULT_SETTINGS["autohide"] in VALID_BOOLEAN_SETTINGS["autohide"]
8587
assert DEFAULT_SETTINGS["notify"] in VALID_BOOLEAN_SETTINGS["notify"]
8688
assert DEFAULT_SETTINGS["color-depth"] in COLOR_DEPTH_ARGS_TO_DEPTHS
8789
assert (
8890
DEFAULT_SETTINGS["exit_confirmation"] in VALID_BOOLEAN_SETTINGS["exit_confirmation"]
8991
)
92+
assert DEFAULT_SETTINGS["transparency"] in VALID_BOOLEAN_SETTINGS["transparency"]
9093

9194

9295
def in_color(color: str, text: str) -> str:
@@ -155,6 +158,22 @@ def parse_args(argv: List[str]) -> argparse.Namespace:
155158
help="do not mark messages as read in the session",
156159
)
157160

161+
transparency_group = parser.add_mutually_exclusive_group()
162+
transparency_group.add_argument(
163+
"--transparency",
164+
dest="transparency",
165+
action="store_const",
166+
const="enabled",
167+
help="enable transparent background (if supported by theme and terminal)",
168+
)
169+
transparency_group.add_argument(
170+
"--no-transparency",
171+
dest="transparency",
172+
action="store_const",
173+
const="disabled",
174+
help="disable transparent background",
175+
)
176+
158177
notify_group = parser.add_mutually_exclusive_group()
159178
notify_group.add_argument(
160179
"--notify",
@@ -496,6 +515,11 @@ def main(options: Optional[List[str]] = None) -> None:
496515
theme_to_use = SettingData(real_theme_name, theme_to_use.source)
497516

498517
### Load overrides & validate remaining settings
518+
if args.transparency:
519+
zterm["transparency"] = SettingData(
520+
args.transparency, ConfigSource.COMMANDLINE
521+
)
522+
499523
if args.autohide:
500524
zterm["autohide"] = SettingData(args.autohide, ConfigSource.COMMANDLINE)
501525

@@ -553,22 +577,27 @@ def print_setting(setting: str, data: SettingData, suffix: str = "") -> None:
553577
print_setting("maximum footlinks value", zterm["maximum-footlinks"])
554578
print_setting("color depth setting", zterm["color-depth"])
555579
print_setting("notify setting", zterm["notify"])
580+
print_setting("transparency setting", zterm["transparency"])
556581

557582
### Generate data not output to user, but into Controller
583+
# Translate valid strings for boolean values into True/False
584+
boolean_settings: Dict[str, bool] = dict()
585+
for setting, valid_values in VALID_BOOLEAN_SETTINGS.items():
586+
boolean_settings[setting] = zterm[setting].value == valid_values[0]
587+
558588
# Generate urwid palette
559589
color_depth_str = zterm["color-depth"].value
560590
color_depth = COLOR_DEPTH_ARGS_TO_DEPTHS[color_depth_str]
591+
transparency_enabled = boolean_settings["transparency"]
561592

562593
theme_data = generate_theme(
563594
theme_to_use.value,
564595
color_depth=color_depth,
565-
transparent_background=False,
596+
transparent_background=transparency_enabled,
566597
)
567598

568-
# Translate valid strings for boolean values into True/False
569-
boolean_settings: Dict[str, bool] = dict()
570-
for setting, valid_boolean_values in VALID_BOOLEAN_SETTINGS.items():
571-
boolean_settings[setting] = zterm[setting].value == valid_boolean_values[0]
599+
# Avoid passing this to the Controller
600+
boolean_settings.pop("transparency")
572601

573602
Controller(
574603
config_file=zuliprc_path,

0 commit comments

Comments
 (0)