Skip to content

Commit cdf5e15

Browse files
authored
Better tracking of shells and terminal colors, and other internal improvements (#970)
1 parent 35c47fe commit cdf5e15

File tree

19 files changed

+824
-293
lines changed

19 files changed

+824
-293
lines changed

.coderabbit.yaml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,9 @@ enable_free_tier: true
55
reviews:
66
profile: chill
77
request_changes_workflow: false
8-
high_level_summary: true
8+
high_level_summary: false
99
high_level_summary_placeholder: '@coderabbitai summary'
10-
high_level_summary_in_walkthrough: false
10+
high_level_summary_in_walkthrough: true
1111
auto_title_placeholder: '@coderabbitai'
1212
auto_title_instructions: ''
1313
review_status: true

.dockerignore

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,8 @@ aws-assumed-role/
2424
**/*.terraform.auto.tfvars.json
2525
**/*.helmfile.vars.yaml
2626

27+
src/colorsaurus/target/**
28+
2729
# Module directory
2830
**/.terraform/
2931
**/.module/
@@ -41,4 +43,4 @@ aws-assumed-role/
4143
**/.DS_Store
4244
**/.CFUserTextEncoding
4345
**/.Trash/
44-
**/$RECYCLE.BIN/
46+
**/$RECYCLE.BIN/

.gitignore

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,8 @@ aws-assumed-role/
1919
**/*.terraform.auto.tfvars.json
2020
**/*.helmfile.vars.yaml
2121

22+
src/colorsaurus/target/**
23+
2224
# Module directory
2325
**/.terraform/
2426
**/.module/
@@ -35,4 +37,4 @@ aws-assumed-role/
3537
**/.DS_Store
3638
**/.CFUserTextEncoding
3739
**/.Trash/
38-
**/$RECYCLE.BIN/YCLE.BIN/
40+
**/$RECYCLE.BIN/

ReleaseNotes-v4.md

Lines changed: 78 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -244,6 +244,16 @@ or you can replace it with the following, which works with both Geodesic v3 and
244244
either `$HOME`, `$WORKSPACE_MOUNT`, or `$WORKSPACE_FOLDER` as appropriate. As a temporary workaround,
245245
you can run `ln -s "$LOCAL_HOME" /localhost` in your customizations.
246246

247+
- By default, Geodesic automatically sets `TF_PLUGIN_CACHE_DIR` to `"${HOME}/.terraform.d/plugin-cache"`
248+
to provide a location for the [Terraform Provider Plugin Cache](https://developer.hashicorp.com/terraform/cli/config/config-file#provider-plugin-cache).
249+
This is a location on the host filesystem, allowing the cache to be shared between the host and the container,
250+
and to persist between container runs. This saves significant time and bandwidth, and we highly recommend
251+
using the plugin cache, which is why we have been setting it for years.
252+
However, the way this was implemented, it was difficult for users to opt-out of the plugin cache altogether.
253+
To accommodate those users while maintaining backward compatibility,
254+
Geodesic now checks, and if `TF_PLUGIN_CACHE_DIR` is set empty, or to "false" or "disabled",
255+
Geodesic unsets the variable, allowing users to avoid having a cache directory.
256+
247257
- Previously, you could have Geodesic perform file ownership mapping between host and container
248258
by setting `GEODESIC_HOST_BINDFS_ENABLED=true`; this variable is now deprecated.
249259
Use `MAP_FILE_OWNERSHIP=true` instead. This feature is disabled by default and can
@@ -528,16 +538,18 @@ the directories being searched.
528538

529539
#### New Customization Command-Line Options
530540

531-
3 command line options regarding customization have been added:
541+
Some line options regarding customization have been added:
532542

533543
1. `--no-custom` (or `--no-customization`, or `--geodesic-customization-disabled`) will disable all user-specific
534544
customizations. This is equivalent to setting `GEODESIC_CUSTOMIZATION_DISABLED=true`. This is useful for
535545
"works in my environment" testing, where you want to disable all customizations to see if the problem is in the
536546
customizations or in the base image. Note that this does not disable changes made by `launch-options.sh`.
537547
2. `--trace` will enable tracing the Geodesic script as it performs customizations. Equivalent to `--trace=custom`.
538548
3. `--trace="custom terminal hist` will enable tracing of the customizations, terminal configuration (mainly with respect
539-
to light and dark mode support), and determining which Bash history file to use, respectively. You can use these options
540-
in any combination, for example, `--trace="hist"`.
549+
to light/dark mode support), and the determination of which Bash history file to use, respectively.
550+
You can use these options in any combination.
551+
4. `--dark` and `--light` will set the terminal theme to dark or light, respectively, disabling attempts to automatically detect it.
552+
This is mainly useful if the automatic detection is not working.
541553

542554
## Dark mode support
543555

@@ -546,49 +558,69 @@ Support for terminals being in dark mode was introduced in Geodesic v2.10.0,
546558
but was not previously well documented. There have also been some enhancements
547559
since then. The following describes the state of support as of v4.0.0.
548560

549-
### Switching between light and dark mode
561+
### Switching between light and dark themes
550562

551-
Geodesic provides basic support for terminal dark and light modes.
563+
Geodesic provides basic support for terminal dark and light themes.
552564
Primarily, this is used to ensure Geodesic's colored output is readable in both modes,
553565
for example, black in light mode and white in dark mode.
554566

555-
There is no standard way to be notified of a terminal's color mode change. Geodesic
556-
listens for SIGWINCH and updates the color mode when receiving it. Some terminals
557-
send this when the color mode changes, but not all do. (For example, macOS Terminal does not.)
558-
559-
There can be issues with the signal handler. For example, if your computer is
560-
waking from sleep, the signal handler may be called multiple times, but
561-
the terminal may take several seconds to respond to the query about its color mode.
562-
This can result in long delays while Geodesic waits for the terminal to respond,
563-
and if it times out, the response may eventually be written to the terminal
564-
command line, looking something like `10;rgb:0000/0000/000011;rgb:ffff/ffff/ffff`.
565-
This area of Geodesic is still new and under development, so there are likely to be subtle bugs.
566-
If you want to disable this feature, you can set `GEODESIC_TERM_COLOR_AUTO=false`.
567-
If Geodesic detects a problem with the terminal color mode, it will disable this feature
568-
by setting `GEODESIC_TERM_COLOR_AUTO=disabled`.
569-
570-
You can report issues with this, or any Geodesic feature, via the `#geodesic`
571-
channel in the [Cloud Posse Slack workspace](https://cpco.io/slack?utm_source=github&utm_medium=release_notes&utm_campaign=cloudposse/geodesic&utm_content=slack).
572-
573-
Geodesic provides a shell function called `update-terminal-color-mode` that can be used to manually
574-
update the terminal mode. This function is called automatically when Geodesic starts, but
575-
if you change the terminal color mode while Geodesic is running, you can call this function
576-
to update the color mode. If your terminal supports calling a function when the color mode changes,
577-
you can call this function from there. Alternately, you can trigger the function call
578-
by resizing the terminal window, which triggers the SIGWINCH signal handler.
579-
580-
The `update-terminal-color-mode` function takes one argument, which is the terminal color mode,
581-
either `light` or `dark`. If you do not provide an argument, it will attempt to determine
582-
the terminal color mode itself.
583-
584-
You can query Geodesic for its cached color mode setting by running `get-terminal-color-mode`.
585-
586-
Changing Geodesic's color mode does not change anything already on the screen. It only affects
567+
While there are standard ways to detect the terminal color settings, they are not
568+
universally supported, and various terminals have their quirks. As a result, color
569+
detection is not always reliable, and you may see errors or 'garbage' output
570+
during startup, especially if you are not using a widely popular terminal.
571+
572+
#### Initial theme detection
573+
574+
It is critical to detect the terminal theme when Geodesic starts. This is done
575+
by default, and can only be disabled by specifying the desired theme,
576+
"light" or "dark", via `--light` or `--dark` command line options,
577+
or by setting the GEODESIC_TERM_THEME environment variable to "light" or "dark". This
578+
must be set in the environment before Geodesic starts, e.g. in the `launch-options.sh` file.
579+
580+
#### Detecting changes in theme while running (experimental)
581+
582+
You may have your terminal set to automatically switch between light and dark themes
583+
based on the time of day, or you may manually switch between themes. Unfortunately,
584+
there is no standard way for a shell to be notified when a terminal's theme changes. Furthermore,
585+
due to the inherent challenges of detecting terminal themes, automatic
586+
detection of changes in the terminal theme has too often injected disruptive characters and messages
587+
into the user's workflow. As a result, Geodesic by default does not attempt to detect changes
588+
in the terminal theme while running.
589+
590+
If you want to manually notify Geodesic of the change, you can call
591+
592+
```bash
593+
set-terminal-theme [light|dark]
594+
```
595+
596+
If you provide an argument, it will set the terminal theme to that argument. If you do not provide an argument,
597+
it will attempt to determine the terminal theme itself.
598+
599+
You can query Geodesic for its cached theme setting by running
600+
601+
```bash
602+
get-terminal-theme
603+
```
604+
605+
Some terminals notify the shell of color changes by sending a `SIGWINCH` signal.
606+
Geodesic also sends this signal to its shell when it detects a change in the size of the window.
607+
You can set the environment variable `GEODESIC_TERM_THEME_AUTO=enabled` to enable
608+
Geodesic to listen for this signal and update the theme when it is received.
609+
Beware that while updates are called from the prompt command hook, we have seen many
610+
instances where the terminal does not respond to the query about its color settings
611+
promptly, resulting in failed detection, and the response being written to the
612+
terminal command line. It might look something like `^[]11;rgb:fdfd/f6f5/e3e3^G`.
613+
614+
Be aware that this is not an area where good solutions exist, which is why
615+
this feature is disabled by default. Unlike with the initial theme detection,
616+
this is not an area where we are investing effort to improve.
617+
618+
Changing Geodesic's theme does not change anything already on the screen. It only affects
587619
future output.
588620

589621
#### Named text color helpers
590622

591-
To help you take advantage of the color mode, Geodesic provides a set of named text color helpers.
623+
To help you take advantage of the terminal color theme support, Geodesic provides a set of named text color helpers.
592624
They are defined as functions that output all their arguments in the named mode.
593625
The named colors are
594626

@@ -600,6 +632,12 @@ The named colors are
600632
Note: yellow is problematic. To begin with, "yellow" is not necessarily yellow,
601633
it varies with the terminal theme, and would be better named "caution" or "info".
602634
In addition, it is too light to be used in light mode, so we substitute magenta instead.
635+
We intentionally avoid `blue` and `magenta` because they are problematic in dark mode,
636+
and because we use magenta as a substitute for yellow in light mode.
637+
We also avoid `black` and `white` because they are completely unsuitable for use in
638+
an environment where the terminal theme can switch between light and dark. Instead,
639+
we take care to use the terminal's stated foreground and background colors, which
640+
the terminal itself will change (including text already on the screen) when changing its theme.
603641

604642
Each of these colors has 4 variations. Using "red" as an example, they would be:
605643

@@ -682,4 +720,5 @@ V4 changes:
682720
- `WORKSPACE_FOLDER` is the base directory of the project inside the container. Analogous to the target of Dev Container's
683721
`workspaceFolder`. Typically, this is the same as `WORKSPACE_MOUNT`, but may be a subdirectory if, for example, the Git repository is
684722
a "monorepo" containing multiple projects. It must be an absolute path either equal to or a subdirectory of `WORKSPACE_FOLDER_HOST_DIR`.
685-
- `GEODESIC_TERM_COLOR_AUTO` is normally unset. Set it to "false" to disable attempts at automatic terminal light/dark mode detection.
723+
- `GEODESIC_TERM_THEME` is normally unset. Set it to "light" or "dark" _before launching Geodesic_ to disable the initial attempt at automatic terminal light/dark theme detection, and use the set value instead.
724+
- `GEODESIC_TERM_THEME_AUTO` is normally unset. Set it to "enabled" to enable automatic attempts to detect changes in terminal light/dark theme. This feature should be considered experimental and may not work as expected.

docs/environment.md

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -34,14 +34,15 @@ Geodesic version 4 additions and changes:
3434
- `WORKSPACE_MOUNT` is the container path where `WORKSPACE_MOUNT_HOST_DIR` will be mounted. Analogous to the target of Dev Container's
3535
`workspaceMount`. Defaults to `/workspace`, which is the default for a Dev Container, but you may want to set it to
3636
something like your project name or git repository name for visibility in the container.
37-
- `GEODESIC_TERM_COLOR_AUTO` is normally unset. Set it to "false" to disable attempts at automatic terminal light/dark mode detection.
37+
- `GEODESIC_TERM_THEME` is normally unset. Geodesic will attempt to detect the terminal light/dark mode and default to light. Set this to "light" or "dark" to disable the automatic detection at startup and force the theme.
38+
- `GEODESIC_TERM_THEME_AUTO` is normally unset. Set it to "true" to enable attempts to automatically detect _changes_ in terminal light/dark theme. Use `set-terminal-theme` to manually switch between light and dark themes.
3839
- `GEODESIC_MOTD_ENABLED` can be set to "false" to disable printing the message of the day at shell startup.
3940
- `MAP_FILE_OWNERSHIP` replaces `GEODESIC_HOST_BINDFS_ENABLED`. If set to true, Geodesic will use `bindfs` to map file ownership
4041
between the host and container. This not normally needed, as it should be handled automatically by Docker.
4142

4243
### Geodesic Version 3 Environment Variables
4344

44-
Below is a list of environment variable that may be visible in the shell and were present in Geodesic v3.
45+
Below is a list of environment variables that may be visible in the shell and were present in Geodesic v3.
4546
Many of these variables are only recognized if you explicitly set or export them prior to running the script.
4647
Others are set and read internally to control optional behaviors.
4748

@@ -107,13 +108,14 @@ and not Geodesic itself.
107108
| `PROMPT_STYLE` | Style of the prompt: plain, fancy, or unicode. |
108109
| `PS1` | `bash`: Primary prompt string (the final assembled Bash prompt). |
109110
| `SCREEN_SIZE` | Internal: Tracks the current terminal screen size as LINES x COLUMNS. |
110-
| `SHLVL` | `bash`1: Shell nesting level (1 for the main shell, higher for subshells). |
111+
| `SHLVL` | `bash`: Shell nesting level (1 for the main shell, higher for subshells). |
111112
| `SSH_AGENT_CONFIG`* | Obsolete: Path to the file storing SSH agent environment variables. |
112113
| `SSH_AUTH_SOCK` | `ssh`: Socket path for the running SSH agent. |
113114
| `SSH_KEY`* | Path to private SSH key file to automatically add to the SSH agent. |
114115
| `STAGE` | Identifies the environment stage (e.g., dev, prod). |
115116
| `TELEPORT_LOGIN` | `teleport`: Username for Teleport-based SSH sessions. |
116117
| `TELEPORT_LOGIN_BIND_ADDR` | `teleport`: Local bind address for Teleport SAML-based login callbacks. |
117118
| `TELEPORT_PROXY` | `teleport`: Teleport proxy host (defaults to tele.<docker-image-subdomain>). |
119+
| `TF_PLUGIN_CACHE_DIR` | `terraform`: Location for the [Terraform Provider Plugin Cache][1]. |
118120

119-
121+
[1]: https://developer.hashicorp.com/terraform/cli/config/config-file#provider-plugin-cache

os/debian/Dockerfile.debian

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,11 @@ ARG HELM_DIFF_VERSION=3.9.13
2222
# https://github.com/aslafy-z/helm-git/releases
2323
ARG HELM_GIT_VERSION=1.3.0
2424

25+
FROM rust:1-${DEBIAN_CODENAME} AS rust
26+
COPY /src/colorsaurus /src/colorsaurus
27+
WORKDIR /src/colorsaurus
28+
RUN cargo install --path . --root /usr/local
29+
2530

2631
FROM python:${PYTHON_VERSION}-slim-${DEBIAN_CODENAME} AS python
2732

@@ -157,6 +162,9 @@ RUN echo 'set noswapfile' >> /etc/vim/vimrc
157162

158163
WORKDIR /tmp
159164

165+
# Copy the Rust binary from the Rust build stage
166+
COPY --from=rust /usr/local/bin/terminal-theme-detector /usr/local/bin/terminal-theme-detector
167+
160168
# Copy python dependencies
161169
COPY --from=python /usr/local/ /usr/local/
162170

0 commit comments

Comments
 (0)