{"modulePath":"github.com/FelineStateMachine/012","version":"v0.8.0","isLatest":true,"isStandardLibrary":false,"goos":"all","goarch":"all","docs":"# package diff\n\nPackage diff compares and merges .012 workbooks cell by cell, for 012 diff and 012 merge-driver (see docs/files/git.md). Compare lists what changed between two workbooks: sheets added, removed, renamed or moved, each cell's input, value, format and note, notebook cells, regions, named ranges, macros and the other fields of sheets and workbooks. Merge combines two workbooks changed from a common one, and conflicts only where both changed the same part of the same cell or field.\n\nBoth read files as their JSON fields (raw.go), so nothing a file holds goes unseen, and use the engine only to compute formulas' values, which the file doesn't store. Nothing here runs a notebook cell or asks JEV: values come from what the formulas compute alone.\n\n## Constants\n\n```go\nconst (\n\tKindSheet    = \"sheet\"    // a sheet added, removed, renamed or moved\n\tKindCell     = \"cell\"     // a cell's input, value, format or note\n\tKindRegion   = \"region\"   // a notebook region or linked file\n\tKindTable    = \"table\"    // a table\n\tKindLayout   = \"layout\"   // another field of a sheet: widths, rules, charts\n\tKindName     = \"name\"     // a named range\n\tKindMacro    = \"macro\"    // a macro\n\tKindWorkbook = \"workbook\" // a field of the workbook: locale, arithmetic\n)\n```\nKinds of Change.\n\n```go\nconst KindNotebook = \"notebook\"\n```\nKindNotebook is a Change to a notebook tab's cell: its source, or what its last run left.\n\n## Variables\n\n```go\nvar Formats = []string{\"text\", \"json\", \"nuon\"}\n```\nFormats are what WriteChanges writes.\n\n## Functions\n\n```go\nfunc Dump(w io.Writer, b *Book) error\n```\nDump writes a workbook as lines of text, one for each cell and each field, each naming its sheet: what git diffs when 012 diff --textconv is a .012 file's textconv. A formula's line ends with its value, unless it changes on every recalculation (NOW, RAND and what reads them), which would show as a change each time.\n\n```go\nfunc WriteChanges(w io.Writer, changes []Change, format string, color bool) error\n```\nWriteChanges writes changes in format: text, a line each (colored with color), or a table of records with the columns kind, sheet, item, field, old and new as JSON or NUON.\n\n## Types\n\n```go\ntype Book struct {\n\t// contains filtered or unexported fields\n}\n```\nBook is a workbook read for comparing: its file's fields and the workbook they make.\n\n```go\nfunc Read(data []byte) (*Book, error)\n```\nRead reads a workbook file's contents. Empty contents are a workbook without sheets, which is what git hands over for a file that doesn't exist on one side.\n\n```go\ntype Change struct {\n\tKind  string\n\tSheet string // the sheet, by its name in the second workbook where it has one\n\tItem  string // the cell, region, name, macro or field that changed\n\t// Field is what about it changed: for a cell input, value, format or\n\t// note; for a sheet added, removed, renamed or moved; for a region,\n\t// name or macro added, removed or its field's name; for a layout\n\t// field, its key when it has keys (a column's width), else \"\".\n\tField    string\n\tOld, New nuon.Value\n\t// contains filtered or unexported fields\n}\n```\nChange is one difference. Old or New is null where the thing isn't on that side.\n\n```go\nfunc Compare(a, b *Book) []Change\n```\nCompare lists what changed from a to b: sheets first, then each sheet's cells in row order, a notebook tab's cells, its regions and other fields, then the workbook's names, macros and settings.\n\n```go\nfunc (c Change) Where() string\n```\nWhere names the change's place as the text output does: Q3!B7, sheet Q3, Q3 region r1, Q3 table Sales, Q3 widths, name Sales.\n\n```go\ntype Conflict struct {\n\tWhere string // as a Change's: Q3!B7, sheet Q3, Q3 widths, name Sales\n\tField string // what about it: input, format, note, a field's key, or \"\"\n\t// Base, Ours and Theirs are the three versions as text, \"\" where\n\t// the thing isn't there; What says what happened instead, when the\n\t// conflict is about a whole sheet.\n\tBase, Ours, Theirs string\n\tWhat               string\n}\n```\nConflict is a part of a workbook both sides changed differently. The merge keeps ours; the report says what theirs had.\n\n```go\nfunc Merge(base, ours, theirs []byte) ([]byte, []Conflict, error)\n```\nMerge combines ours and theirs, two workbook files changed from base, and returns the merged file as 012 saves it. Each cell's input, format and note, each field of a sheet or the workbook (a column's width, a region, a named range, a macro) and each sheet's name and presence merge on their own: a part changed on one side only takes that side's version, and a part both changed alike takes it too. A part both changed differently is a conflict: the merge keeps ours, and a cell's note says what theirs had (on top of its own note), so the conflicts can be found in the grid. Empty contents stand for a missing file.\n\nSheets are matched by name or, when renamed, by their cells (see matchSheets). Rows or columns inserted on one side shift the cells below or right of them, which a cell-by-cell merge can't tell from edits: merge such changes in 012 rather than here.\n\n```go\nfunc (c Conflict) String() string\n```\nString is the conflict as the merge report lists it.\n\n","path":"github.com/FelineStateMachine/012/internal/diff","name":"diff","synopsis":"Package diff compares and merges .012 workbooks cell by cell, for 012 diff and 012 merge-driver (see docs/files/git.md).","isRedistributable":true}
