Skip to content

Commit

Permalink
Filter out comments from h1s
Browse files Browse the repository at this point in the history
  • Loading branch information
sholderbach committed Dec 22, 2024
1 parent 5b4c557 commit 376e89a
Show file tree
Hide file tree
Showing 5 changed files with 64 additions and 35 deletions.
4 changes: 2 additions & 2 deletions benchmarks/gradient-autoview.nu
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,9 @@ seq 0 $height | par-each {|| # create these in parallel
let row_data = (seq 0 $width | each { |col|
let fgcolor = 2 + 2 * $col
if $fgcolor > $stamp_start and $fgcolor < $stamp_end {
$"(ansi -e '48;2;0;0;')($fgcolor)m($stamp)(ansi -e '0m')"
$"(ansi -e '48;2;0;0;')($fgcolor)m($stamp)(ansi reset)"
} else {
$"(ansi -e '48;2;0;0;')($fgcolor)m (ansi -e '0m')"
$"(ansi -e '48;2;0;0;')($fgcolor)m (ansi reset)"
}
} | str join)
print -n $"($row_data)" | table
Expand Down
6 changes: 3 additions & 3 deletions benchmarks/gradient.nu
Original file line number Diff line number Diff line change
Expand Up @@ -26,12 +26,12 @@ for line in 0..$height {
let fgcolor = 2 + 2 * $col

if $fgcolor > 200 and $fgcolor < 210 {
$row_data += $"(ansi -e '48;2;0;0;')($fgcolor)m($stamp)(ansi -e '0m')"
$row_data += $"(ansi -e '48;2;0;0;')($fgcolor)m($stamp)(ansi reset)"
} else {
let fg = $fgcolor mod 256
$row_data += $"(ansi -e '48;2;0;0;')($fg)m (ansi -e '0m')"
$row_data += $"(ansi -e '48;2;0;0;')($fg)m (ansi reset)"
}
}

print $row_data
}
}
28 changes: 14 additions & 14 deletions benchmarks/gradient_benchmark.nu
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,9 @@ if ($is_release | str downcase | str trim) == "y" {
let row_data = (seq 0 $width | each { |col|
let fgcolor = (iter_inc 2 2 $col)
if $fgcolor > 200 and $fgcolor < 210 {
$"(ansi -e '48;2;0;0;')($fgcolor)m($stamp)(ansi -e '0m')"
$"(ansi -e '48;2;0;0;')($fgcolor)m($stamp)(ansi reset)"
} else {
$"(ansi -e '48;2;0;0;')($fgcolor)m(char sp)(ansi -e '0m')"
$"(ansi -e '48;2;0;0;')($fgcolor)m(char sp)(ansi reset)"
}
} | str join)
$"($row_data)(char newline)"
Expand All @@ -37,9 +37,9 @@ if ($is_release | str downcase | str trim) == "y" {
let row_data = (seq 0 $width | each { |col|
let fgcolor = (iter_inc 2 2 $col)
if $fgcolor > 200 and $fgcolor < 210 {
$"(ansi -e '48;2;0;0;')($fgcolor)m($stamp)(ansi -e '0m')"
$"(ansi -e '48;2;0;0;')($fgcolor)m($stamp)(ansi reset)"
} else {
$"(ansi -e '48;2;0;0;')($fgcolor)m(char sp)(ansi -e '0m')"
$"(ansi -e '48;2;0;0;')($fgcolor)m(char sp)(ansi reset)"
}
} | str join)
$"($row_data)(char cr)"
Expand All @@ -56,23 +56,23 @@ if ($is_release | str downcase | str trim) == "y" {
let row_data = (seq 0 $width | each { |col|
let fgcolor = (iter_inc 2 2 $col)
if $fgcolor > 200 and $fgcolor < 210 {
$"(ansi -e '48;2;0;0;')($fgcolor)m($stamp)(ansi -e '0m')"
$"(ansi -e '48;2;0;0;')($fgcolor)m($stamp)(ansi reset)"
} else {
$"(ansi -e '48;2;0;0;')($fgcolor)m (ansi -e '0m')"
$"(ansi -e '48;2;0;0;')($fgcolor)m (ansi reset)"
}
} | str join)
$"($row_data)(char cr)"
} | str join
}} | math avg)

print $"running test 3 at (date now | format date '%Y-%m-%d %H:%M:%S.%3f')"
# 3. Precompute (ansi -e '48;2;0;0;') and (ansi -e '0m') -- seems to be slower
# 3. Precompute (ansi -e '48;2;0;0;') and (ansi reset) -- seems to be slower
let 3 = (seq 1 10 | each { timeit {
let height = 40
let width = 160
let stamp = 'Nu'
let ansi1 = (ansi -e '48;2;0;0;')
let ansi2 = (ansi -e '0m')
let ansi2 = (ansi reset)
seq 0 $height | each { |row|
let row_data = (seq 0 $width | each { |col|
let fgcolor = (iter_inc 2 2 $col)
Expand All @@ -96,9 +96,9 @@ if ($is_release | str downcase | str trim) == "y" {
let row_data = (seq 0 $width | each { |col|
let fgcolor = 2 + 2 * $col
if $fgcolor > 200 and $fgcolor < 210 {
$"(ansi -e '48;2;0;0;')($fgcolor)m($stamp)(ansi -e '0m')"
$"(ansi -e '48;2;0;0;')($fgcolor)m($stamp)(ansi reset)"
} else {
$"(ansi -e '48;2;0;0;')($fgcolor)m(char sp)(ansi -e '0m')"
$"(ansi -e '48;2;0;0;')($fgcolor)m(char sp)(ansi reset)"
}
} | str join)
$"($row_data)(char cr)"
Expand All @@ -115,9 +115,9 @@ if ($is_release | str downcase | str trim) == "y" {
let row_data = (seq 0 $width | each { |col|
let fgcolor = 2 + 2 * $col
if $fgcolor > 200 and $fgcolor < 210 {
$"(ansi -e '48;2;0;0;')($fgcolor)m($stamp)(ansi -e '0m')"
$"(ansi -e '48;2;0;0;')($fgcolor)m($stamp)(ansi reset)"
} else {
$"(ansi -e '48;2;0;0;')($fgcolor)m (ansi -e '0m')"
$"(ansi -e '48;2;0;0;')($fgcolor)m (ansi reset)"
}
} | str join)
$"($row_data)(char cr)"
Expand All @@ -134,9 +134,9 @@ if ($is_release | str downcase | str trim) == "y" {
let row_data = (seq 0 $width | each { |col|
let fgcolor = 2 + 2 * $col
if $fgcolor > 200 and $fgcolor < 210 {
$"(ansi -e '48;2;0;0;')($fgcolor)m($stamp)(ansi -e '0m')"
$"(ansi -e '48;2;0;0;')($fgcolor)m($stamp)(ansi reset)"
} else {
$"(ansi -e '48;2;0;0;')($fgcolor)m (ansi -e '0m')"
$"(ansi -e '48;2;0;0;')($fgcolor)m (ansi reset)"
}
} | str join)
$"($row_data)(char cr)"
Expand Down
28 changes: 14 additions & 14 deletions benchmarks/gradient_benchmark_no_check.nu
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,9 @@ if ($is_release | str downcase | str trim) == "y" {
let row_data = (seq 0 $width | each { |col|
let fgcolor = (iter_inc 2 2 $col)
if $fgcolor > 200 and $fgcolor < 210 {
$"(ansi -e '48;2;0;0;')($fgcolor)m($stamp)(ansi -e '0m')"
$"(ansi -e '48;2;0;0;')($fgcolor)m($stamp)(ansi reset)"
} else {
$"(ansi -e '48;2;0;0;')($fgcolor)m(char sp)(ansi -e '0m')"
$"(ansi -e '48;2;0;0;')($fgcolor)m(char sp)(ansi reset)"
}
} | str join)
$"($row_data)(char newline)"
Expand All @@ -39,9 +39,9 @@ if ($is_release | str downcase | str trim) == "y" {
let row_data = (seq 0 $width | each { |col|
let fgcolor = (iter_inc 2 2 $col)
if $fgcolor > 200 and $fgcolor < 210 {
$"(ansi -e '48;2;0;0;')($fgcolor)m($stamp)(ansi -e '0m')"
$"(ansi -e '48;2;0;0;')($fgcolor)m($stamp)(ansi reset)"
} else {
$"(ansi -e '48;2;0;0;')($fgcolor)m(char sp)(ansi -e '0m')"
$"(ansi -e '48;2;0;0;')($fgcolor)m(char sp)(ansi reset)"
}
} | str join)
$"($row_data)(char cr)"
Expand All @@ -58,23 +58,23 @@ if ($is_release | str downcase | str trim) == "y" {
let row_data = (seq 0 $width | each { |col|
let fgcolor = (iter_inc 2 2 $col)
if $fgcolor > 200 and $fgcolor < 210 {
$"(ansi -e '48;2;0;0;')($fgcolor)m($stamp)(ansi -e '0m')"
$"(ansi -e '48;2;0;0;')($fgcolor)m($stamp)(ansi reset)"
} else {
$"(ansi -e '48;2;0;0;')($fgcolor)m (ansi -e '0m')"
$"(ansi -e '48;2;0;0;')($fgcolor)m (ansi reset)"
}
} | str join)
$"($row_data)(char cr)"
} | str join
} | math avg)

print $"running test 3 at (date now | format date '%Y-%m-%d %H:%M:%S.%3f')"
# 3. Precompute (ansi -e '48;2;0;0;') and (ansi -e '0m') -- seems to be slower
# 3. Precompute (ansi -e '48;2;0;0;') and (ansi reset) -- seems to be slower
let 3 = (seq 10 | timeit {
let height = 40
let width = 160
let stamp = 'Nu'
let ansi1 = (ansi -e '48;2;0;0;')
let ansi2 = (ansi -e '0m')
let ansi2 = (ansi reset)
seq 0 $height | each { |row|
let row_data = (seq 0 $width | each { |col|
let fgcolor = (iter_inc 2 2 $col)
Expand All @@ -98,9 +98,9 @@ if ($is_release | str downcase | str trim) == "y" {
let row_data = (seq 0 $width | each { |col|
let fgcolor = 2 + 2 * $col
if $fgcolor > 200 and $fgcolor < 210 {
$"(ansi -e '48;2;0;0;')($fgcolor)m($stamp)(ansi -e '0m')"
$"(ansi -e '48;2;0;0;')($fgcolor)m($stamp)(ansi reset)"
} else {
$"(ansi -e '48;2;0;0;')($fgcolor)m(char sp)(ansi -e '0m')"
$"(ansi -e '48;2;0;0;')($fgcolor)m(char sp)(ansi reset)"
}
} | str join)
$"($row_data)(char cr)"
Expand All @@ -117,9 +117,9 @@ if ($is_release | str downcase | str trim) == "y" {
let row_data = (seq 0 $width | each { |col|
let fgcolor = 2 + 2 * $col
if $fgcolor > 200 and $fgcolor < 210 {
$"(ansi -e '48;2;0;0;')($fgcolor)m($stamp)(ansi -e '0m')"
$"(ansi -e '48;2;0;0;')($fgcolor)m($stamp)(ansi reset)"
} else {
$"(ansi -e '48;2;0;0;')($fgcolor)m (ansi -e '0m')"
$"(ansi -e '48;2;0;0;')($fgcolor)m (ansi reset)"
}
} | str join)
$"($row_data)(char cr)"
Expand All @@ -136,9 +136,9 @@ if ($is_release | str downcase | str trim) == "y" {
let row_data = (seq 0 $width | each { |col|
let fgcolor = 2 + 2 * $col
if $fgcolor > 200 and $fgcolor < 210 {
$"(ansi -e '48;2;0;0;')($fgcolor)m($stamp)(ansi -e '0m')"
$"(ansi -e '48;2;0;0;')($fgcolor)m($stamp)(ansi reset)"
} else {
$"(ansi -e '48;2;0;0;')($fgcolor)m (ansi -e '0m')"
$"(ansi -e '48;2;0;0;')($fgcolor)m (ansi reset)"
}
} | str join)
$"($row_data)(char cr)"
Expand Down
33 changes: 31 additions & 2 deletions make_release/release-note/notes.nu
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,14 @@ const toc = '[[toc](#table-of-contents)]'

# Generate and write the table of contents to a release notes file
export def write-toc [file: path] {
let known_h1s = [
"# Highlights and themes of this release",
"# Changes",
"# Notes for plugin developers",
"# Hall of fame",
"# Full changelog",
]

let lines = open $file | lines | each { str trim -r }

let content_start = 2 + (
Expand All @@ -64,12 +72,33 @@ export def write-toc [file: path] {
| wrap line
| insert level {
get line | split chars | take while { $in == '#' } | length
}
| insert nocomment {
if ($in.level == 1) {
let line = $in.line

# Try to use the whitelist first
if ($known_h1s | any {|| $line =~ $in}) {
return true
}
let user = ([Ignore Accept] |
input list $"Is this a code comment or a markdown h1 heading:(char nl)(ansi blue)($line)(ansi reset)(char nl)Choose if we include it in the TOC!")
match $user {
"Accept" => {true}
"Ignore" => {false}
}

} else {
return true
}
}
)

print $data

let table_of_contents = (
$data
| where level in 1..=3
| where level in 1..=3 and nocomment == true
| each {|header|
let indent = '- ' | fill -w ($header.level * 2) -a right

Expand All @@ -91,7 +120,7 @@ export def write-toc [file: path] {
)

let content = $data | each {
if $in.level in 1..=3 and not ($in.line ends-with $toc) {
if $in.level in 1..=3 and not ($in.line ends-with $toc) and $in.nocomment {
$'($in.line) ($toc)'
} else {
$in.line
Expand Down

0 comments on commit 376e89a

Please sign in to comment.