Skip to content

feat(tui): open and save .sql files from disk in their own tabs - #814

Merged
DokaDev merged 7 commits into
files-048/3-file-corefrom
files-048/4-open-save
Dec 6, 2026
Merged

DokaDev merged 7 commits into
files-048/3-file-corefrom
files-048/4-open-save

Conversation

@DokaDev

@DokaDev DokaDev commented Dec 4, 2026 •

Copy link
Copy Markdown
Owner

Related issue: #311
Related issue: #817

Fourth part of the 0.48.0 "files" stack, on top of #808 (files-048/3-file-core). This is the TUI of part B of #311: .sql files from anywhere on disk, each in a tab of its own, built on #808's textfile reader and writer, its unsaved-text store and the workspace's file tab.

What changes for users

  • Open. :e <path> opens a file when the argument starts with /, ~, ./ or ../ (on Windows also C:\, C:/, \\); anything else stays a saved query's name, so :e reports/daily still opens that saved query. Relative paths start from the folder datarig was started from. The : line completes the path from the names in its folder (read off the UI thread, as the export path field does); until a name is picked, Enter takes the path as typed. Space f o (a new Space f group, "File") opens the file browser in the launch folder, else home: .sql names as they are, the rest dimmed, any file opens. A path inside the saved queries' folder opens that saved query. One tab per file, told by the file itself, so a link or another spelling goes to its tab. A new file tab takes the active tab's connection, as a new console does. With no profile at all, :e <path> and Space f o work from the welcome panel too.
  • Refusals at open, in words: "Not opened: query.sql is not UTF-8 or UTF-16 text", "Not opened: dump.sql is 412 MB; files over 20 MB are not opened here", "Not opened: the path is not UTF-8 text", "Not opened: query.sql cannot be read (permissions)".
  • The file tab. Named after the file; the pane title is Query · <path> with ~ for home, clipped from the left when narrow, and "read-only file" for a file without write permission.
  • Save only when asked (Q1 b). Ctrl+S and :w write the file after checking its stamp and hash. :w <path> and Space f a (the browser; a name typed is a file in the folder shown) save a tab as a file; replacing another file asks "Replace the file?" and Enter keeps it. A console saved as a file becomes a file tab, and its console goes to the trash as on close. A read-only file and a folder that cannot be written refuse the save, pointing to :w <path>.
  • Nothing typed is lost. * shows text that is not in the file yet. That text is kept in the state folder (0600, feat(core): read and write .sql files from anywhere on disk #808's store) on the console autosave clock and removed once saved or closed, so quitting asks nothing and the next start brings the tab back with *; the kept text wins over the file. Closing a tab with * asks: s save and close, d close and drop, Enter/Esc keep. A second instance keeps no copies, so it asks on close and on quit.
  • Not saved yet, in the status line (Say in the status line that a file tab has changes not saved to its file #817). While a file tab's text is not in its file, the status line says "Not saved to the file yet" (a warning or an error it shows keeps its place), and the hint line starts with the keys that save the tab: Ctrl+S save and Space f a save as a file (only the latter for a read-only file). At 80x24 the note and Ctrl+S save fit, and the save as hint follows where there is room. English and Korean.
  • Changed on disk (no watching): looked at on tab enter and before each write. A clean tab is reloaded ("Reloaded query.sql: it changed on disk"); a tab with changes keeps them and its next save asks (r reload, o overwrite, Esc later), naming the file. At restore, a file changed since the last stamp comes back with that question pending; a file gone comes back only with kept text (:w writes it again), else it is left out with a notice. :e! reloads from disk and asks when that drops changes; Space t u brings a closed file tab back, read again.
  • Line endings when running. A file or saved query whose every line break is CRLF (edited as LF since feat(core): read and write .sql files from anywhere on disk #808) sends its statements with CRLF again, as the file holds them; a mixed file keeps CR in its lines, as before.
  • Safety. A file tab runs through the same checks as a console (pinned on a read-only profile with the fake driver). A file's text never reaches errors.log or a notice; failure lines name the path only (pinned with a marker).
  • Docs: a new guide page "Files" (open, save, encodings, line endings, the 20 MiB limit, read-only files, quitting), linked from the summary and from getting started; docs/keybindings.md regenerated (Space f o, Space f a, :e!, the :e/:w texts). changes/added/files-from-disk.md.

Failing first:

On the stack base e0fc73d2 (files-048/3-file-core), cargo test -p datarig-tui --test it -- flows_files: 15 failed, 0 passed. What each saw:

e_with_a_path_opens_the_file_in_a_tab_of_its_own: "a tab of its own" (1 tab, not 2);
    the status line: "No saved query named ~/work/query.sql"
an_edit_shows_a_star_and_ctrl_s_writes_the_file_byte_for_byte: the editor held "" (nothing opened)
closing_a_file_tab_with_changes_asks_save_drop_or_keep: "Ctrl+W asks": left None, right Some(Confirm)
quit_asks_nothing_and_the_next_start_brings_the_unsaved_text_back: "the unsaved text wins"
a_clean_tab_changed_on_disk_is_reloaded_when_entered: the editor held "" (nothing opened)
an_unsaved_tab_changed_on_disk_asks_at_save: "the tab keeps its text"
save_as_onto_another_existing_file_asks_and_enter_keeps_it: no "Replace the file?"
a_read_only_file_opens_and_its_save_is_refused_in_words: no "read-only file"
a_folder_that_cannot_be_written_refuses_the_save_in_words: no refusal on the screen (nothing opened)
the_same_file_through_a_link_focuses_its_tab: the first :e opened nothing
a_name_still_opens_a_saved_query_and_a_path_into_the_scripts_folder_too:
    :e reports/daily opened the saved query (as today), then the path into the scripts folder
    did not: left None, right Some("reports/daily.sql")
files_that_cannot_be_read_exactly_are_refused_in_words: "No saved query named ~/work/latin1.sql"
statements_of_a_crlf_file_are_sent_with_crlf: e ~/work/crlf.sql: [] (nothing opened, nothing sent)
a_file_tab_on_a_read_only_profile_refuses_a_write_as_a_console_does: left "", right "DELETE FROM ..."
a_file_that_fails_to_save_never_puts_its_text_in_the_log_or_a_notice: the file never opened

For #817, on d938dc3e (this branch before it), the_status_line_says_a_file_tab_is_not_saved failed at its first check: the status line of the edited file tab was NORMAL local-pg │ │ i type · Ctrl+E run · Tab next pane · : commands · Space ? help · Space more EN (no note, no keys that save).

The CRLF pin with the saved query first (it opens on the base), -- statements_of_a_crlf_file:

e saved: ["select 5,\n  6"]     (the saved query's CRLF lines were sent as LF since #808)

From the review bot's three findings (fixed in bcf0fbec), on 977fdcf7, each test failed first:

a_clean_tab_whose_file_is_gone_keeps_its_text: no "query.sql *" once the file was removed
    (the cached comparison said "clean", so the copy was removed instead of written)
a_second_instance_asks_before_quitting_with_a_file_in_conflict: "asks first" (:qa quit)
a_file_tab_saved_as_a_query_becomes_that_saved_query: "no file any more" (doc.file was still set)

Tests

  • Flows (crates/tui/tests/it/flows_files.rs, new): the 15 above, and the_command_line_completes_paths, space_f_o_opens_a_file_and_space_f_a_saves_a_tab_as_one, files_open_from_the_welcome_panel, a_second_instance_asks_before_closing_or_quitting_with_unsaved_files, restore_keeps_a_gone_file_with_its_text_and_asks_about_a_changed_one, e_bang_reloads_from_disk_and_asks_when_it_drops_changes, a_closed_file_tab_comes_back_read_again, and from the review a_clean_tab_whose_file_is_gone_keeps_its_text, a_second_instance_asks_before_quitting_with_a_file_in_conflict, a_file_tab_saved_as_a_query_becomes_that_saved_query.
  • Screens (file_tab_screens, Unix: the paths are drawn with /), English at 80x24 and 120x40: file_clean, file_unsaved, file_read_only, file_close, file_conflict, file_open_browser, file_save_browser; each also in Korean through check_localized.
  • flows_scripts::a_file_tab_comes_back_with_its_file_and_keeps_the_keys_a_later_version_adds replaces feat(core): read and write .sql files from anywhere on disk #808's a_file_tab_this_build_does_not_open_stays_in_the_workspace: this build opens the tab, and the keys a later version adds are still written back.
  • Key map: the conflict check and the generated docs/keybindings.md (keybindings_doc, blessed).

Binary size

Measured by CI's performance job at bcf0fbec: the Linux binary is 34,695,152 bytes, 33.088 MiB against the 34 MiB budget (33.013 MiB at #808's head, so this part adds 0.075 MiB). The budget is unchanged.

Not in this part

  • The status line of a file tab does not yet say "Not saved to the file yet" or offer Ctrl+S save · Space f a save as as M3 draws it; the tab's *, its pane title and the close question carry that today (a Follow-up).
  • n (a new, empty database file) in the SQLite browser comes in files-048/5-new-db-file.

@DokaDev
DokaDev added this pull request to stack #798 December 4, 2026 11:03
@DokaDev DokaDev changed the title files 048/4 open save feat(tui): open and save .sql files from disk in their own tabs Dec 4, 2026
@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Dec 4, 2026 •

Copy link
Copy Markdown
Codex Review Summary: ✅ Completed

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-12-04T11:06:28.952949Z edb3ca6 PR opened
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: edb3ca6fc6

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread crates/tui/src/app/file_ops.rs Resolved
Comment thread crates/tui/src/app/script_ops.rs Resolved
Comment thread crates/tui/src/app/persist.rs Resolved
@DokaDev
DokaDev force-pushed the files-048/4-open-save branch 3 times, most recently from 3320377 to d938dc3 Compare December 6, 2026 05:39
:e <path> opens a file from anywhere on disk in a tab of its own (one tab
per file, a link included), on the active tab's connection; any other
argument stays a saved query's name, and a path inside the saved queries'
folder opens that saved query. Ctrl+S and :w write the file only when asked,
after checking that it is the version last read; :w <path> saves a tab as a
file and asks before replacing another one. * shows text that is not in the
file yet, which is kept in the state folder meanwhile, so quitting asks
nothing and the next start brings it back. Closing asks: save, drop or keep.
A file changed on disk is reloaded when its clean tab is entered, and a tab
with changes asks at its next save. Read-only files open and refuse saves in
words, as does a folder that cannot be written. :e! reloads from disk.
Statements of a CRLF file or saved query are sent with CRLF again.

Related issue: #311
…e paths on the : line

Space f o opens the file browser in the folder datarig was started from
(else home), with .sql files drawn as they are and other files dimmed; any
file opens. Space f a saves the active tab as a file there, a name typed
being a file in the folder shown. The : line completes the path argument of
:e and :w from the names in its folder, read off the UI thread as the export
path field reads them. A closed file tab comes back with Space t u, read
again from its file, and a file gone from disk is found by its path.

Also the new Files guide page, getting started, the regenerated key map and
the screens of a file tab, its questions and the browsers.

Related issue: #311
…h> in Korean

The close question of a file tab says where its changes would go ("Its
changes are not saved to ~/work/query.sql."), and the Korean refusals keep
the :w <path> syntax as typed. The leader group list, the command list and
the which-key screens gain Space f and :e!.

Related issue: #311
…ct, and let a file become a saved query

A clean tab whose file is gone now compares its text again, so it shows *,
keeps its text in the copy and asks on close. A file tab in conflict whose
text is in no copy (a second instance, a failed copy) is counted before
quitting. A file tab saved under a saved query's name drops its file and
its copy, so the next start brings back the saved query. The file tests also
build and pass on Windows.

Related issue: #311
The browser's top row writes a folder under the home folder as its
field takes it, ~/ and then the rest with /, on every platform, as the
key file picker always has. The test expected the platform's separator
there and failed on Windows.

Related issue: #311
A file tab whose text is not in its file showed * in the tab bar, but
the status line said nothing about it. It now says "Not saved to the
file yet", over an outcome that is only information (a warning or an
error said there keeps its place), and the hint line starts with the
keys that save the tab: Ctrl+S save, then Space f a save as a file
(only the latter for a read-only file). At 80x24 the note and Ctrl+S
save fit; the save as hint follows where there is room. In English and
Korean.

Related issue: #817
@DokaDev
DokaDev force-pushed the files-048/4-open-save branch from d938dc3 to 387bcad Compare December 6, 2026 08:37
@DokaDev
DokaDev merged commit f90de4f into main Dec 6, 2026
22 of 23 checks passed
@DokaDev
DokaDev deleted the files-048/4-open-save branch December 6, 2026 09:11
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant