Skip to content
Permalink

Comparing changes

Choose two branches to see what’s changed or to start a new pull request. If you need to, you can also or learn more about diff comparisons.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also . Learn more about diff comparisons here.
base repository: jomaway/typst-bytefield
Failed to load repositories. Confirm that selected base ref is valid, then try again.
Loading
base: v0.0.5
Choose a base ref
...
head repository: jomaway/typst-bytefield
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: main
Choose a head ref
  • 12 commits
  • 10 files changed
  • 2 contributors

Commits on Mar 11, 2024

  1. chore(changelog): add info for v0.0.5

    jomaway committed Mar 11, 2024
    Copy the full SHA
    ece0751 View commit details

Commits on Mar 20, 2024

  1. refactor(table): removed tablex dependencies

    Yaniss authored and jomaway committed Mar 20, 2024
    Copy the full SHA
    0aa9e6c View commit details
  2. Copy the full SHA
    4ace7df View commit details
  3. fix: brackets height calculation.

    changed from math module which seems to be the same as inline math to a block math to create a bracket with the height of a row.
    jomaway committed Mar 20, 2024
    Copy the full SHA
    102a98a View commit details
  4. Copy the full SHA
    1ab9ade View commit details
  5. chore(docs): remove ref to tablex

    using new typst tables so tablex is no longer needed and is removed now.
    jomaway committed Mar 20, 2024
    Copy the full SHA
    9c6765e View commit details

Commits on May 14, 2024

  1. fix(api): allow pattern as fill arguments

    fixes #36
    jomaway committed May 14, 2024
    Copy the full SHA
    a70f255 View commit details
  2. Copy the full SHA
    82f4ebc View commit details

Commits on May 22, 2024

  1. chore: bump to 0.0.6

    jomaway committed May 22, 2024
    Copy the full SHA
    b8f2ec6 View commit details
  2. chore: update excludes

    jomaway committed May 22, 2024
    Copy the full SHA
    8bc6de3 View commit details
  3. refactor: removed underlines from functionnames

    jomaway committed May 22, 2024
    Copy the full SHA
    13fae10 View commit details

Commits on May 23, 2024

  1. refactor: removed snake_case in all public apis

    jomaway committed May 23, 2024
    Copy the full SHA
    e9e8bfa View commit details
Showing with 177 additions and 177 deletions.
  1. +11 −1 CHANGELOG.md
  2. +2 −4 README.md
  3. +1 −1 docs/docs.typ
  4. +19 −17 lib/api.typ
  5. +14 −13 lib/asserts.typ
  6. +81 −92 lib/gen.typ
  7. +31 −31 lib/states.typ
  8. +3 −3 lib/types.typ
  9. +13 −13 lib/utils.typ
  10. +2 −2 typst.toml
12 changes: 11 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,10 +1,20 @@
# Changelog

## [0.0.5] - (Unreleased)
## [0.0.6] - (2024-05-22)

- Removed tablex dependencies
- Fixed bracket hight calculation
- Feat: Add option to specify row to note-fields.
- Feat: Allow pattern as fill arguments
- Replaced locate with context

## [0.0.5] - (2024-03-11)

### Added
- Option to style the header with a background color (`fill`) and stroke (`stroke`).
- Option to specify the row heights of the bytefield with a `row` argument.
- Option to add labels without a number by using a negative number.
- Improved option to show or hide markers underneath a label.

## [0.0.4] - (2024-02-18)

6 changes: 2 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
@@ -2,8 +2,6 @@

A simple way to create network protocol headers, memory maps, register definitions and more in typst.

Using [tablex](https://github.com/PgBiel/typst-tablex) under the hood.

⚠️ Warning. As this package is still in an early stage, things might break with the next version.

ℹ️ If you find a bug or a feature which is missing, please open an issue and/or send an PR.
@@ -13,7 +11,7 @@ Using [tablex](https://github.com/PgBiel/typst-tablex) under the hood.
![random colored bytefield example](docs/bytefield_example.png)

```typst
#import "@preview/bytefield:0.0.5": *
#import "@preview/bytefield:0.0.6": *
#bytefield(
// Config the header
@@ -57,7 +55,7 @@ bytes(2)[_End_],

## Usage

To use this library through the Typst package manager import bytefield with `#import "@preview/bytefield:0.0.5": *` at the top of your file.
To use this library through the Typst package manager import bytefield with `#import "@preview/bytefield:0.0.6": *` at the top of your file.

The package contains some of the most common network protocol headers which are available under: `common.ipv4`, `common.ipv6`, `common.icmp`, `common.icmpv6`, `common.dns`, `common.tcp`, `common.udp`.

2 changes: 1 addition & 1 deletion docs/docs.typ
Original file line number Diff line number Diff line change
@@ -77,7 +77,7 @@
= Example
#block[
#show: bf-config.with(
row_height: 2em,
row-height: 2em,
)

#figure(
36 changes: 19 additions & 17 deletions lib/api.typ
Original file line number Diff line number Diff line change
@@ -26,13 +26,13 @@
bpr: bpr,
msb: msb,
rows: rows,
side: (left_cols: pre, right_cols: post)
side: (left-cols: pre, right-cols: post)
)

let meta = generate_meta(fields.pos(), args)
let fields = finalize_fields(fields.pos(), meta)
let cells = generate_cells(meta, fields)
let table = generate_table(meta, cells)
let meta = generate-meta(fields.pos(), args)
let fields = finalize-fields(fields.pos(), meta)
let cells = generate-cells(meta, fields)
let table = generate-table(meta, cells)
return table
}

@@ -45,7 +45,7 @@
/// - body (content): The label which is displayed inside the field.
#let _field(size, fill: none, body) = {
if size != auto { assert.eq(type(size), int, message: strfmt("expected size to be an integer or auto, found {}", type(size))) }
if fill != none { assert(type(fill) in (color, gradient), message: strfmt("expected fill to be an color or gradient, found {}.", type(fill)))}
if fill != none { assert(type(fill) in (color, gradient, pattern), message: strfmt("expected fill to be an color or gradient, found {}.", type(fill)))}
data-field(none, size, none, none, body, format: (fill: fill))
}

@@ -97,13 +97,15 @@
/// The note is always shown in the same row as the next data field which is specified.
///
/// - side (left, right): Where the annotation should be displayed
/// - level (int): Defines the nesting level of the note.
/// - row (int, auto): Define a row where the note should be displayed.
/// - rowspan (int): Defines if the cell is spanned over multiple rows.
/// - level (int): Defines the nesting level of the note.
/// - inset (length): Inset of the the annotation cell.
/// - bracket (bool): Defines if a bracket will be shown for this note.
/// - content (content): The content of the note.
#let note(
side,
row: auto,
rowspan:1,
level:0,
inset: 5pt,
@@ -122,12 +124,12 @@

if (side == left) {
_align = right
_first = box(height:100%,content)
_second = box(height:100%,inset:(right:0pt),layout(size => {math.lr("{",size:size.height)}))
_first = content
_second = layout(size => {$ lr("{",size:size.height) $})
} else {
_align = left
_first = box(height:100%,inset:(left:0pt),layout(size => {math.lr("}",size:size.height)}))
_second = box(height:100%,content)
_first = layout(size => {$ lr("}",size:size.height) $})
_second = content
}

let body = if (bracket == false) { content } else {
@@ -144,7 +146,7 @@
align:_align+horizon,
)

return note-field(none, none, side, level:level, body, format: format, rowspan: rowspan)
return note-field(none, side, level:level, body, format: format, row: row, rowspan: rowspan)
}

/// Shows a note with a bracket and spans over multiple rows.
@@ -159,17 +161,17 @@
///
/// #emoji.warning *experimental:* This will probably change in a future version.
///
/// - start_addr (string, content): The start address will be top aligned
/// - end_addr (string, content): The end address will be bottom aligned
#let section(start_addr, end_addr, span: 1) = {
/// - start-addr (string, content): The start address will be top aligned
/// - end-addr (string, content): The end address will be bottom aligned
#let section(start-addr, end-addr, span: 1) = {
note(
left,
rowspan: span,
inset: (x:5pt, y:2pt),
box(height:100%, [
#set text(0.8em, font: "Noto Mono", weight: 100)
#align(top + end)[#start_addr]
#align(bottom + end)[#end_addr]
#align(top + end)[#start-addr]
#align(bottom + end)[#end-addr]
]))
}

27 changes: 14 additions & 13 deletions lib/asserts.typ
Original file line number Diff line number Diff line change
@@ -1,50 +1,51 @@
#import "@preview/oxifmt:0.2.0": strfmt


#let assert_dict(arg, var_name) = {
#let assert-dict(arg, var_name) = {
assert.eq(type(arg),dictionary, message: strfmt("expected {} to be a dictionary, found {}",var_name, type(arg)));
}


/// fail if field is not a bf-field
#let assert_bf-field(field) = {
assert_dict(field, "field")
#let assert-bf-field(field) = {
assert-dict(field, "field")
let bf-type = field.at("bf-type", default: none)
assert.eq(bf-type, "bf-field", message: strfmt("expected bf-type of 'bf-field', found {}",bf-type));
let field-type = field.at("field-type", default: none)
assert.ne(field-type, none, message: strfmt("could not find field-type at bf-field {}", field));
}

/// fail if field is not a bf-field of type data-field
#let assert_data-field(field) = {
assert_bf-field(field);
#let assert-data-field(field) = {
assert-bf-field(field);
let field-type = field.at("field-type", default: none)
assert.eq(field-type, "data-field", message: strfmt("expected field-type == data-field, found {}",field-type))
let size = field.data.size;
assert(type(size) == int, message: strfmt("expected integer for parameter size, found {} ", type(size)))
}

/// fail if field is not a bf-field of type data-field
#let assert_note-field(field) = {
assert_bf-field(field);
#let assert-note-field(field) = {
assert-bf-field(field);
// Check for correct field-type
let field-type = field.at("field-type", default: none)
assert.eq(field-type, "note-field", message: strfmt("expected field-type == note-field, found {}",field-type))
// Check if it has a valid anchor id
let anchor = field.data.anchor
assert(type(anchor) == int, message: strfmt("expected integer for parameter anchor, found {} ", type(anchor)))
let row = field.data.row
assert(type(row) == int, message: strfmt("expected integer for parameter anchor, found {} ", type(row)))

// Check side
assert(field.data.side == left or field.data.side == right, message: strfmt("expected left or right for the notes side argument."))
}

/// fail if it does not match
#let assert_header-field(field) = {
assert_bf-field(field);
#let assert-header-field(field) = {
assert-bf-field(field);
}

/// fail if cell is not a bf-cell
#let assert_bf-cell(cell) = {
assert_dict(cell, "cell");
#let assert-bf-cell(cell) = {
assert-dict(cell, "cell");
// Check bf-type
let bf-type = cell.at("bf-type", default: none)
assert.eq(bf-type, "bf-cell", message: strfmt("expected bf-type of 'bf-cell', found {}",bf-type));
Loading