Move the full editor out of src/app.zi into workbook/editor: a handle owns its workbook, undo history, autosave, focus and save/change counters. EditorOpen/EditorNew/EditorClose create and release a document, EditorFrame draws and handles one frame in a host region, EditorSave/EditorSaveAs write it, and EditorSample takes input only while the editor is focused. app.zi keeps profiles, documents, the window title, menus and theme; the Werkzeug bundle uses the same editor through EditorInitWithWorkbook. Add a minimal host in previews/host.zi and tests/host_test.zi, which drives it on a private display through Kryon's test driver: open a .gnumeric and a .csv, type a value and a formula, undo/redo, save, close, reopen and hand keyboard focus between host and editor. Build the bundle from the project exports with ziran bundle --project. Pin Kryon facaace3, CSS 7dd9fff2 and Ziran 9432a110 for the shared Autotrade/plot/data_views build graph. Verified with make check, make bundle and make test-ci against the locked pins.
workbook
Native spreadsheet editor written in Ziran with Kryon. Open a document from your file manager, drop it onto Workbook, or pass its path directly:
workbook /path/to/file.gnumeric
The window title shows the document's filename. Edits save back to that file; when you drop another document, Workbook saves the current edit before opening it. Launching without a file uses the profile described below.
Everything in the repository is Ziran (.zi) apart from the Makefile and
configuration. src/app.zi is the desktop application, src/engine.zi is the
spreadsheet engine, and src/cell.zi is the headless driver. Imported documents
use the installed gnumeric library for loading, calculation and saving.
New workbooks and CSV use the independent Ziran engine. Document format,
dependencies and rendering limitations are covered in
format notes.
build & run
Workbook is a Ziran package. ziran.toml names the dependencies and
ziran.lock pins the Ziran toolchain and Kryon to exact commits, so a fresh
clone builds the same code. Install the ziran command once with
make install-user in a Ziran checkout, and have the SDL2 and Cairo
development packages installed.
make # build ./build/workbook-desktop and ./build/cell
make cell # build only the headless engine driver
make check # type-check the application, the driver, and the tests
make run # open the editor
make test # source audit, structure and conversion tests, desktop and host tests on private displays, gnumeric parity
make test-ci # the same without parity, which is what CI runs
make gnumeric-test # native document, edit, undo and round-trip regressions
make hidden-rows-test # row visibility, totals and undo/redo on a private display
make host-test # the exported editor inside a minimal host, on a private display
make parity # evaluation and round-trip tests against Gnumeric
make fuzz REFERENCE=PATH # compare this cell with another on generated inputs
make install # install workbook, cell, and geld under ~/.local
make deb # build a Debian package
cell eval FILE # evaluate a .gnumeric/.csv file and print CSV
geld # the finance profile: a link to workbook
Update the pinned dependencies with ziran update kryon or ziran update ziran
and commit the new ziran.lock. To build against sibling checkouts while
developing Kryon or Ziran, put their paths in an ignored ziran.local.toml:
[overrides]
kryon = "../kryon"
ziran = "../../ziranlang/ziran"
make test needs xvfb-run, xdotool, xfwm4, dbus-run-session, xmessage,
ImageMagick's import, and gnumeric (for ssconvert). The
desktop test (tests/desktop_test.zi) runs the editor only on a private Xvfb
display; it never opens a window on your desktop. Parity compares against the
ssconvert on your path, or
against GNUMERIC_SSCONVERT, or a local master build at
~/Tools/gnumeric-1.12.62; the newest catalog functions exist only in a
Gnumeric master build, so an older distribution Gnumeric reports those fixtures
as different. For imported documents, use a reference from the same installed
version, e.g. GNUMERIC_SSCONVERT=/usr/bin/ssconvert make parity.
CI runs make test-ci with Gnumeric installed.
The menu test also runs a private Xfce window manager and D-Bus session. It checks that the first right-click after another window has focus shows the menu, that commands act on the clicked cell, and that menus work after resizing. To verify the installed app, run:
WORKBOOK_TEST_APP="$HOME/.local/bin/workbook" build/desktop_test --menu-only
tests/differential_fuzz.zi checks one build of cell against another. Point
REFERENCE at a build whose answers are right, for example cell built from an
earlier commit, and make fuzz runs the current build and the reference on the
same generated inputs, then reports each one they answer differently: random
function calls on a fixed sheet, random CSV files, the fixtures with random
damage, and workbooks whose sheets refer to each other. SEED and COUNT
choose the inputs, and the program can also be run by hand:
build/differential_fuzz REFERENCE build/cell formulas 1 100
build/differential_fuzz REFERENCE build/cell check 'DAY(-2147483648.5)'
A run that hangs is killed after FUZZ_TIMEOUT seconds (20 by default).
editing
arrows move the selection
Tab move right
type start editing the selected cell (replacing its value)
Enter edit the selected cell; in the formula bar, commit and move down
Esc leave the formula bar without changing the cell
Delete clear the selected cell
double click edit the clicked cell in the formula bar
right click open the cell menu, including when activating the window
Ctrl+C/X/V copy, cut, or paste cells through the system clipboard
Ctrl+Z undo; while a cell is edited, undo its typing word by word
Ctrl+Y redo (also Ctrl+Shift+Z)
wheel scroll rows
Ctrl+S save
Chart button create a linked formula chart from a selected label/value range
Formula cells show their calculated value in the grid and their source in the formula bar. The toolbar provides save and row/column insertion and deletion, and the sheet tabs at the bottom switch sheets. Cells accept text, numbers, or formulas in the Gnumeric expression language.
Right-click a row number and choose Hide rows to collapse it to a thin
line. Shift-click row numbers to select several rows first. Click a thin line
to show its row again; both actions support undo and redo. Hidden rows stay
in the document. Use =SUBTOTAL(109,A1:A20) for totals that skip hidden rows;
ordinary SUM and SUBTOTAL(9,…) continue to include them.
Changes save automatically, including the cell you are typing, pasted values, and inserted or deleted rows and columns. Clicking another cell or closing the app keeps the latest edit without requiring Enter or Ctrl+S. Escape restores the cell's value from before the edit. A failed save leaves the previous file intact, reports the failure in the status bar, and retries automatically.
Undo and redo cover every change: a finished cell edit, paste, cut, clear, fill, and row or column insertion and deletion, each with the formula references it moved. Undoing a change selects the cells it touched again and shows their sheet. Up to the last 100 changes can be undone.
Select a two-column label/value range, then use Chart in the toolbar or
Sheet → Create formula chart from selection. Workbook adds a new sheet whose
labels and values link to the selected cells, plus a live text bar chart. This
portable chart works in ordinary .gnumeric documents and updates when its
source values change.
profiles
workbook is the generic profile. geld is a link to the same program; it
opens the finance profile, with an independent data directory, because of the
name it is started under (WORKBOOK_PROFILE=geld workbook does the same).
WORKBOOK_PROFILE=NAME workbook opens any other profile the same way, with its
data in $XDG_DATA_HOME/NAME; a name uses lowercase letters, digits, - and
_. Harmony starts its Workbook profiles like this. All of them run the same
application:
D = units
E = rate
G = value, e.g. =D1*E1
H = diff, e.g. =(E1-OLD_RATE)*D1
The profiles/*.json files are profile metadata, not source code.
data
A workbook is saved as workbook.gnumeric. The generic profile loads from the
first of:
WORKBOOK_DIR generic workbook directory
workbook.gnumeric in the current directory
~/.local/share/workbook/workbook.gnumeric
Geld always uses GELD_DIR when set, or $XDG_DATA_HOME/geld (default
~/.local/share/geld). A workbook in the directory Geld was launched from
does not replace its finance profile. Missing data directories are created
automatically. Named profiles and explicit data-directory overrides import
legacy workbook.json files when no workbook.gnumeric exists beside them; subsequent changes go to
workbook.gnumeric, keeping the original JSON intact. Ordinary Workbook launches leave the former
finance JSON untouched and start with an empty sheet when no saved document exists.
workbook.json holds private workbook data and is intentionally ignored by
git. workbook.example.json is safe sample data for demos.
Embedded grid
Other Kryon apps embed Workbook's grid with the workbook/grid export: the
editor's column letters, row numbers, cell squares, theme colors and sheet tabs,
showing a real workbook from workbook/engine. Cells hold numbers, text and
formulas such as =SUM(B2:B9); columns can have their own width and a count
(1,250,734) or money ($12.85) format. The view is read-only and scrolls with
the wheel, three rows a notch or a column with Shift. frozen_rows keeps title
rows on top, total_rows styles closing rows like headers, and trim draws only
the used cells. Hosts whose windows route the wheel themselves fill in
GridInput; others use GridSample. The Workbook editor paints its grid with
the same squares.
Engine :: #import "workbook/engine";
using Grid :: #import "workbook/grid";
book := Engine.WorkbookNew()
sheet := GridAddSheet(book, "Usage")
unused GridSet(book, sheet, 0, 0, "Folder"); unused GridSet(book, sheet, 0, 1, "Tokens")
unused GridSet(book, sheet, 1, 0, "aurea"); unused GridSet(book, sheet, 1, 1, "4795296906")
unused GridSet(book, sheet, 2, 0, "Total"); unused GridSet(book, sheet, 2, 1, "=SUM(B2:B2)")
Engine.WorkbookEvaluate(book)
view: GridView
view.key = 5000000; view.widths[0] = 180.0; view.formats[1] = GridCount
GridDraw(session, bounds, book, *view, GridSample(session, bounds))
make grid-test checks it.
Embedded editor
Other Kryon apps embed the complete editor — toolbar, formula bar, cell grid,
selection, formula reference picking, fill handle, copy/cut/paste, hidden rows,
undo/redo, sheet tabs and automatic saving — with the workbook/editor export.
Each document is an Editor handle with its own workbook, undo history and
autosave; the host owns the window, menus and other pages.
using Editor :: #import "workbook/editor";
handle := EditorOpen("plan.gnumeric") // null when it cannot be read
defer { EditorClose(handle) }
typed: [128]u8
HostFrame :: (session: Session, bounds: Rectangle) -> s32 {
input := EditorSample(session, bounds, handle, typed[:])
unused EditorFrame(session, bounds, handle, input)
return 0
}
EditorFrame draws inside the given bounds and handles one frame of input; it
returns whether the editor consumed it. The editor takes the keyboard only
while focused: a press inside focuses it, a press outside commits and releases
it, and Escape on the grid releases it. EditorSample follows that rule, and a
host with its own keyboard UI can call EditorSetFocused instead. Give each
embedded editor its own key base with EditorSetKeyBase so widget keys do not
collide.
Documents:
EditorOpen(path) -> *Editoropens a.gnumericor.csv;EditorNew(path = "")makes an empty workbook. Both, andEditorClose(editor), exist only in native builds.EditorInitWithWorkbook(editor, book, path, load_failed = false)starts a caller-owned, zero-initializedEditor;EditorDestroyreleases its workbook without freeing the handle. The Werkzeug bundle uses this because its host cannot allocate.EditorSave(editor, finish_edit = true) -> boolsaves to the handle's path (CSV for.csv),EditorSaveAs(editor, path) -> boolsaves a copy and switches to it, andEditorOpenPath(editor, path) -> boolreplaces the document, saving the current one first.EditorDirty,EditorSaveCountandEditorChangeCounttell a host when to refresh data computed from the document. The counters only grow; autosave and undo belong to the handle.EditorSetAutosave(editor, false)leaves saving to the host.EditorWorkbook(editor) -> *Engine.Workbookgives a host read access for totals and other derived views.EditorPath(editor, out)andEditorStatus(editor, out)copy into caller storage, andEditorSetStatus(editor, message)puts a host message in the status bar.EditorFocused,EditorEditingCell,EditorCanUndo,EditorCanRedo,EditorSheetIndex,EditorSheetCountandEditorClipboardAvailableare queries.
Commands a host can place in its own menus: EditorUndo, EditorRedo,
EditorCut, EditorCopy, EditorPaste, EditorClear, EditorSelectAll,
EditorGoToFirstCell, EditorInsertRow, EditorInsertRowBelow,
EditorDeleteRow, EditorInsertColumn, EditorDeleteColumn, EditorAddSheet,
EditorSelectSheet, EditorRecalculate and EditorCreateFormulaChart.
The standalone Workbook app uses this same module; src/app.zi adds profile
selection, documents, the window title, menus and the theme. make host-test
builds previews/host.zi, a minimal host with a host-owned sidebar, and drives
it on a private X display: open a .gnumeric and a .csv, type a value and a
formula, undo/redo, save, close, reopen and hand focus between host and editor.
Native Gnumeric charts and drawing objects stay in a saved document but are not drawn; the embedded editor has the same limitation as the grid. Showing them needs a chart view over the document's chart objects.
Werkzeug app bundle
make bundle builds build/workbook.zib, the spreadsheet editor for a host
with the spreadsheet.v1 capability. Werkzeug on Linux includes the native
calculation service and keeps Workbook documents in its own private folder.
The bundle runs in Werkzeug on Linux, Android and the web, with the same compact grid, bottom sheet tabs and editing commands
as the desktop editor. Its File menu imports and exports documents with the
system chooser on Linux and Android, or a browser upload and download;
imported source files stay unchanged. On narrow screens the toolbar includes
arrow controls for navigating cells without a keyboard. Linux and the web
also offer File → Download Workbook.zx to save the app bundle.
Android and browser hosts use Workbook's built-in calculation engine and save portable Gnumeric documents containing sheets, cell values and formulas. The Linux host also uses Gnumeric for imported documents, preserving their additional formatting and document features. Charts, styles and other native Gnumeric document metadata are not preserved by the built-in document reader.
The native menu bar contains File, Edit, View, Insert and Sheet. Ctrl+O opens a document, Ctrl+Shift+S saves a copy, and F10 or Alt+F focuses the menus.