Fix #13: Expose Pre-edit Backup restoration

Preserve full diff opcodes before grouping, route modal navigation to a two-axis viewport-sized scroller, and calculate side-by-side layout using terminal cell widths so tabbed Hosts File lines keep a stable divider.
This commit is contained in:
Philip Henning 2026-09-04 20:19:17 +02:00
parent 6a3e1e0d5a
commit e268794564
13 changed files with 1103 additions and 19 deletions

View file

@ -55,9 +55,8 @@ enabling mutations it verifies write access and creates a Pre-edit Backup.
If authorization, permission validation, or backup creation fails, the
application remains in Read-only Mode.
The footer shows `Edit` while Privileged Mode is active. This label refers to
Privileged Mode; it is separate from the Entry Editor used to change one Host
Entry.
The footer shows `PRIVILEGED` while Privileged Mode is active. This label is
separate from the Entry Editor used to change one Host Entry.
## Change a Host Entry
@ -127,11 +126,29 @@ If an immediate save fails, the application restores the complete pre-action
in-memory state, visible selection, and undo/redo history. A later mutation
therefore cannot accidentally persist the failed change.
### Locate a Pre-edit Backup
### Restore the session Pre-edit Backup
Entering Privileged Mode creates one timestamped Pre-edit Backup below the
operating system's temporary directory. The application does not currently show
this path. Ask Python for the directory used on your system:
operating system's temporary directory. While that Privileged Mode session is
active, press `b` to open the restore review. It displays the exact backup
source path and `/etc/hosts` target path, then shows a Git-style diff of the
current Hosts File (before) and Pre-edit Backup (after restoration). At 120 or
more columns the diff is side by side; at smaller supported sizes it is a
unified diff. Use `[` and `]` to move between changed hunks, `f` to toggle the
full diff, and `r` to refresh it.
Choose **Restore Hosts File** only when those paths are the ones you intend.
The application copies the displayed backup over the Hosts File, reloads the
on-disk contents into the interface, and clears undo/redo history. If the copy
fails, the current Hosts File and interface remain unchanged and the status
message names the failure. The application checks both displayed files again
when you confirm; if either changed, it refreshes the diff and requires a new
confirmation. Cancel leaves both files unchanged.
The TUI does not list old backups, apply retention rules, or retain the session
association after leaving Privileged Mode. For recovery outside that session,
locate and restore a backup manually. Ask Python for the temporary directory on
your system:
```bash
python3 -c 'import tempfile; print(tempfile.gettempdir() + "/hosts-manager-backups")'
@ -148,9 +165,10 @@ The application does not remove old Pre-edit Backups, apply retention rules, or
record which file belongs to a later session. Do not choose a backup solely
because it is the newest; inspect its timestamp and contents first.
### Restore manually
### Restore manually outside the session
Restoration is not available through the TUI. To restore manually:
To restore a backup that is no longer associated with an active Privileged Mode
session:
1. Leave the application or return it to Read-only Mode.
2. Locate and inspect the intended Pre-edit Backup.
@ -243,6 +261,7 @@ continually retrying it.
| `Shift+R` | Refresh all DNS Entries |
| `Ctrl+Z` / `Ctrl+Y` | Undo or redo and save the result |
| `Ctrl+S` | Save the current in-memory state |
| `b` | Review session backup changes and confirm restoration |
Within the Entry Editor, use `Tab` and `Shift+Tab` to move between fields and
`Escape` to leave the form. If values changed, the application asks whether to