raindown 0.11.0 → 0.13.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/lib/raindown/actions.rb +1 -1
- data/lib/raindown/bare_directives.rb +10 -16
- data/lib/raindown/blueprints.rb +7 -6
- data/lib/raindown/cli.rb +22 -16
- data/lib/raindown/code_blocks.rb +26 -16
- data/lib/raindown/document.rb +9 -9
- data/lib/raindown/editing.rb +2 -2
- data/lib/raindown/endpoint/endpoint_runner.rb +15 -29
- data/lib/raindown/markdown_nodes.rb +1 -1
- data/lib/raindown/node_blocks.rb +1 -6
- data/lib/raindown/node_injector.rb +7 -1
- data/lib/raindown/nodes.rb +5 -3
- data/lib/raindown/pages.rb +61 -12
- data/lib/raindown/rewriter.rb +13 -12
- data/lib/raindown/table/markdown_table.rb +33 -0
- data/lib/raindown/table/table.rb +73 -0
- data/lib/raindown/tui/blueprints/blueprints_view.rb +1 -1
- data/lib/raindown/tui/cloud.rb +154 -0
- data/lib/raindown/tui/feelings/celebration/celebration_renderer.rb +22 -0
- data/lib/raindown/tui/feelings/feelings_log.rb +4 -4
- data/lib/raindown/tui/feelings/feelings_renderer.rb +3 -16
- data/lib/raindown/tui/layout.rb +8 -1
- data/lib/raindown/tui/project.rb +23 -11
- data/lib/raindown/tui/renderers/endpoint_renderer.rb +4 -3
- data/lib/raindown/tui/terminal/loading.rb +34 -0
- data/lib/raindown/tui/terminal/screen.rb +6 -5
- data/lib/raindown/tui/terminal/styles.rb +13 -1
- data/lib/raindown/tui/views/endpoint_view.rb +5 -4
- data/lib/raindown/tui.rb +10 -6
- data/lib/raindown/watcher/file_watcher.rb +3 -3
- data/lib/raindown/watcher/project.rb +3 -4
- data/lib/version.rb +1 -1
- metadata +7 -2
data/lib/raindown/rewriter.rb
CHANGED
|
@@ -8,26 +8,27 @@ require_relative 'utils'
|
|
|
8
8
|
module Raindown
|
|
9
9
|
# Rewrites the generated parts of a Markdown file in place before it's rendered:
|
|
10
10
|
# node output, like the TOC, endpoint responses and table alignment.
|
|
11
|
-
# Each rewriter responds to rewrite(content:, path:, bare:, execute:, metadata:) and returns the new content.
|
|
12
11
|
module Rewriter
|
|
13
|
-
|
|
12
|
+
# The content written back, and the endpoint checks it failed, like "api.md:3: expected status 200, received 404".
|
|
13
|
+
Rewrite = Data.define(:original, :content, :failures) do
|
|
14
|
+
def changed?
|
|
15
|
+
content != original
|
|
16
|
+
end
|
|
17
|
+
end
|
|
14
18
|
|
|
15
19
|
module_function
|
|
16
20
|
|
|
17
21
|
def rewrite(content:, path:, bare: false, execute: false, metadata: NoMetadata)
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
22
|
+
injected = NodeInjector.rewrite(content:, path:, bare:, metadata:)
|
|
23
|
+
endpoints = EndpointRunner.new(content: injected, path:, bare: BareDirectives.enabled?(path:, content: injected, bare:), execute:)
|
|
24
|
+
Rewrite.new(original: content, content: TableFormatter.rewrite(content: endpoints.rewrite), failures: endpoints.failures)
|
|
21
25
|
end
|
|
22
26
|
|
|
23
|
-
#
|
|
27
|
+
# Writes the file only when it changed.
|
|
24
28
|
def update(path:, bare: false, execute: false, metadata: NoMetadata)
|
|
25
|
-
content
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
File.write(path, rewritten)
|
|
30
|
-
true
|
|
29
|
+
rewrite(content: Utils.read_markdown(path), path:, bare:, execute:, metadata:).tap do |rewrite|
|
|
30
|
+
File.write(path, rewrite.content) if rewrite.changed?
|
|
31
|
+
end
|
|
31
32
|
end
|
|
32
33
|
end
|
|
33
34
|
end
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module Raindown
|
|
4
|
+
# Rows of cells as a Markdown table, its first row the header, and back again. A | in a cell is escaped as \|, and
|
|
5
|
+
# a line break is written as a space, as a table's cells are one line. The TableFormatter lines up its columns.
|
|
6
|
+
module MarkdownTable
|
|
7
|
+
SEPARATOR = /\A\|?(\s*:?-+:?\s*\|)*\s*:?-+:?\s*\|?\z/
|
|
8
|
+
# A | that isn't escaped.
|
|
9
|
+
PIPE = /(?<!\\)\|/
|
|
10
|
+
|
|
11
|
+
module_function
|
|
12
|
+
|
|
13
|
+
def format(rows)
|
|
14
|
+
header, *body = rows.map { |row| "| #{row.map { escape(it) }.join(' | ')} |" }
|
|
15
|
+
[header, "|#{Array.new(rows.first.length, '---').join('|')}|", *body].join("\n")
|
|
16
|
+
end
|
|
17
|
+
|
|
18
|
+
# The rows of the table in the lines, leaving out its separator, or none when they aren't a table.
|
|
19
|
+
def parse(lines)
|
|
20
|
+
return [] unless lines[1]&.strip&.match?(SEPARATOR)
|
|
21
|
+
|
|
22
|
+
[lines[0], *lines.drop(2)].take_while { it.strip.start_with?('|') }.map { cells(it.strip) }
|
|
23
|
+
end
|
|
24
|
+
|
|
25
|
+
def cells(line)
|
|
26
|
+
line.delete_prefix('|').delete_suffix('|').split(PIPE, -1).map { it.strip.gsub('\|', '|') }
|
|
27
|
+
end
|
|
28
|
+
|
|
29
|
+
def escape(cell)
|
|
30
|
+
cell.gsub('|', '\|').gsub(/\s*\R\s*/, ' ')
|
|
31
|
+
end
|
|
32
|
+
end
|
|
33
|
+
end
|
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require 'csv'
|
|
4
|
+
require 'digest'
|
|
5
|
+
require 'json'
|
|
6
|
+
|
|
7
|
+
require_relative '../node'
|
|
8
|
+
require_relative 'markdown_table'
|
|
9
|
+
|
|
10
|
+
module Raindown
|
|
11
|
+
# The node behind table:, a CSV or TSV file relative to the project as a Markdown table, after a comment of how many
|
|
12
|
+
# rows it has and a hash of them, as they were when the table and the file last matched:
|
|
13
|
+
# table: 'data/team.csv'
|
|
14
|
+
# <!-- table 2 rows · 3f2a9c -->
|
|
15
|
+
# | name | role |
|
|
16
|
+
# |------|----------|
|
|
17
|
+
# | Ada | engineer |
|
|
18
|
+
# | Lin | design |
|
|
19
|
+
# Edit the table and its rows are written back to the file, or edit the file and the table's written again. When
|
|
20
|
+
# both changed, neither is, and the table's comment says so until they match again.
|
|
21
|
+
class Table < Node
|
|
22
|
+
COMMENT = /\A<!-- table (?:conflict|\d+ rows?) · (\h+) -->\z/
|
|
23
|
+
SEPARATORS = { '.csv' => ',', '.tsv' => "\t" }.freeze
|
|
24
|
+
|
|
25
|
+
def initialize(data)
|
|
26
|
+
@data = data
|
|
27
|
+
end
|
|
28
|
+
|
|
29
|
+
# Written is what it wrote last time, so it can tell which of the table and the file changed since.
|
|
30
|
+
def replace(written: [], metadata: NoMetadata)
|
|
31
|
+
path = File.expand_path(@data.to_s, metadata.respond_to?(:root) ? metadata.root : Dir.pwd)
|
|
32
|
+
return "Can't show #{@data.inspect} as a table: only CSV and TSV files can be" unless SEPARATORS.key?(File.extname(path).downcase)
|
|
33
|
+
return "Can't show #{@data.inspect} as a table: no such file" unless File.file?(path)
|
|
34
|
+
|
|
35
|
+
synced(path, written.map(&:chomp))
|
|
36
|
+
end
|
|
37
|
+
|
|
38
|
+
private
|
|
39
|
+
|
|
40
|
+
def synced(path, written)
|
|
41
|
+
file = read_rows(path)
|
|
42
|
+
synced_hash = written.first&.[](COMMENT, 1)
|
|
43
|
+
table = MarkdownTable.parse(written.drop(1))
|
|
44
|
+
return markdown(file) if synced_hash.nil? || table.empty? || [synced_hash, hash_rows(file)].include?(hash_rows(table))
|
|
45
|
+
return markdown(write_rows(path, table)) if hash_rows(file) == synced_hash
|
|
46
|
+
|
|
47
|
+
warn "raindown: #{@data} and its table both changed, so neither is written until they match"
|
|
48
|
+
["<!-- table conflict · #{synced_hash} -->", *written.drop(1)].join("\n")
|
|
49
|
+
end
|
|
50
|
+
|
|
51
|
+
def markdown(rows)
|
|
52
|
+
return '' if rows.empty?
|
|
53
|
+
|
|
54
|
+
count = rows.length - 1
|
|
55
|
+
"<!-- table #{count} row#{'s' unless count == 1} · #{hash_rows(rows)} -->\n#{MarkdownTable.format(rows)}"
|
|
56
|
+
end
|
|
57
|
+
|
|
58
|
+
def read_rows(path)
|
|
59
|
+
rows = CSV.read(path, col_sep: SEPARATORS[File.extname(path).downcase], skip_blanks: true, encoding: Encoding::UTF_8)
|
|
60
|
+
width = rows.map(&:length).max.to_i
|
|
61
|
+
rows.map { |row| Array.new(width) { row[it].to_s.strip } }
|
|
62
|
+
end
|
|
63
|
+
|
|
64
|
+
def write_rows(path, rows)
|
|
65
|
+
File.write(path, rows.map { CSV.generate_line(it, col_sep: SEPARATORS[File.extname(path).downcase]) }.join)
|
|
66
|
+
rows
|
|
67
|
+
end
|
|
68
|
+
|
|
69
|
+
def hash_rows(rows)
|
|
70
|
+
Digest::SHA256.hexdigest(JSON.generate(rows))[0, 6]
|
|
71
|
+
end
|
|
72
|
+
end
|
|
73
|
+
end
|
|
@@ -11,7 +11,7 @@ require_relative 'filter'
|
|
|
11
11
|
|
|
12
12
|
module Raindown
|
|
13
13
|
module TUI
|
|
14
|
-
# The blueprints from Claude Code's replies, in the project's .raindown/blueprints.md, newest first, then those in its
|
|
14
|
+
# The blueprints from Claude Code's replies, in the project's .raindown/data/blueprints.md, newest first, then those in its
|
|
15
15
|
# code's comments, one at a time, of
|
|
16
16
|
# those its Filter's keywords match, each traced to its code: the arrows move between the boxes drawn in one, or a
|
|
17
17
|
# click on one, the code each box names shows below, Space or another click moving on to
|
|
@@ -0,0 +1,154 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require 'zlib'
|
|
4
|
+
|
|
5
|
+
module Raindown
|
|
6
|
+
module TUI
|
|
7
|
+
# Raindown's logo, raindown.dev's rain cloud, in the middle of the screen while the terminal UI loads: bumps and a
|
|
8
|
+
# rounded base of blocks, each its own blue, lighter at the top, with a few corrupted, and rain falling from under it
|
|
9
|
+
# to the bottom of the screen, fading and thinning out as it goes:
|
|
10
|
+
# ███████████████▞███▄██████████
|
|
11
|
+
# ██████████████████████████
|
|
12
|
+
# ╎╎,┊ ' , ┊ ┊ ' ┊' ╎,
|
|
13
|
+
# ╎ │ ││ , │ │ , ' ' ┊,
|
|
14
|
+
# It's drawn like the site's RainCloud, with the same seed, so it's the same cloud, in the nearest of the 256 colours
|
|
15
|
+
# most terminals have.
|
|
16
|
+
class Cloud
|
|
17
|
+
WIDTH = 50
|
|
18
|
+
ROWS = 19
|
|
19
|
+
SEED = 5
|
|
20
|
+
# Bumps as [column, row, radius], and the base under them, with its corners rounded. Rows are stretched, as
|
|
21
|
+
# characters are taller than they're wide.
|
|
22
|
+
BUMPS = [[25, 8, 11], [13, 12, 7.5], [37, 11, 8.5]].freeze
|
|
23
|
+
BASE_ROWS = 12..18
|
|
24
|
+
BASE_COLUMNS = 7..43
|
|
25
|
+
CORNER = 5
|
|
26
|
+
ROW_STRETCH = 1.7
|
|
27
|
+
SHADES = %w[█ ▓].freeze
|
|
28
|
+
CORRUPT = %w[▀ ▄ ▚ ▞ ▌ ▐].freeze
|
|
29
|
+
CORRUPTED = 0.015
|
|
30
|
+
RAIN = %w[│ ╎ ┊ ' ,].freeze
|
|
31
|
+
# The rain's blue, as hue, saturation and lightness, which fades in steps as it falls, and thins out.
|
|
32
|
+
RAIN_BLUE = [212, 100, 70].freeze
|
|
33
|
+
RAIN_STEPS = 8
|
|
34
|
+
FADE = 0.11
|
|
35
|
+
# The levels of red, green and blue in the 256 colours' cube, from 16 to 231, leaving out the greys after it, so
|
|
36
|
+
# the rain stays blue as it fades.
|
|
37
|
+
CUBE = [0, 95, 135, 175, 215, 255].freeze
|
|
38
|
+
XTERM = (16..231).to_h { [it, CUBE.values_at((it - 16) / 36, ((it - 16) / 6) % 6, (it - 16) % 6)] }.freeze
|
|
39
|
+
|
|
40
|
+
class << self
|
|
41
|
+
# Each cell inside the cloud, by its row and column, as its block and its blue's style.
|
|
42
|
+
def cells = drawing.first
|
|
43
|
+
|
|
44
|
+
# The columns it rains from.
|
|
45
|
+
def rainy = drawing.last
|
|
46
|
+
|
|
47
|
+
# The rain's style at each step, from just under the cloud to the bottom of the screen.
|
|
48
|
+
def rain_styles
|
|
49
|
+
@rain_styles ||= Array.new(RAIN_STEPS) { |step| style(rgb(*RAIN_BLUE).map { (it * (1 - (step * FADE))).round }) }
|
|
50
|
+
end
|
|
51
|
+
|
|
52
|
+
# Every blue it's drawn in, for the screen's colours.
|
|
53
|
+
def styles = (cells.values.map(&:last) + rain_styles).uniq
|
|
54
|
+
|
|
55
|
+
private
|
|
56
|
+
|
|
57
|
+
# Rolled in the site's order, a cell at a time, then the rainy columns.
|
|
58
|
+
def drawing
|
|
59
|
+
@drawing ||= begin
|
|
60
|
+
random = Random.new(SEED)
|
|
61
|
+
cells = ROWS.times.to_a.product(WIDTH.times.to_a).select { inside?(*it) }.to_h { [it, cell(it.first, random)] }
|
|
62
|
+
[cells, ((BASE_COLUMNS.begin + 1)..(BASE_COLUMNS.end - 1)).select { random.rand < 0.6 }]
|
|
63
|
+
end
|
|
64
|
+
end
|
|
65
|
+
|
|
66
|
+
# A corrupted block now and then, and otherwise a shade, denser towards the bottom, with some noise.
|
|
67
|
+
def cell(row, random)
|
|
68
|
+
return [CORRUPT.sample(random:), blue(row, random)] if random.rand < CORRUPTED
|
|
69
|
+
|
|
70
|
+
depth = (row / ROWS.to_f) + random.rand(-0.25..0.25)
|
|
71
|
+
[SHADES[(1 - (depth * 2)).round.clamp(0, 1)], blue(row, random)]
|
|
72
|
+
end
|
|
73
|
+
|
|
74
|
+
# A random blue, lighter at the top of the cloud and darker at the bottom.
|
|
75
|
+
def blue(row, random)
|
|
76
|
+
light = (82 - (row * 2.4) + random.rand(-12..12)).round.clamp(25, 90)
|
|
77
|
+
style(rgb(random.rand(198..235), random.rand(65..100), light))
|
|
78
|
+
end
|
|
79
|
+
|
|
80
|
+
# The style of the nearest of the 256 colours.
|
|
81
|
+
def style(rgb) = :"cloud_#{XTERM.min_by { |_, color| color.zip(rgb).sum { (it[0] - it[1])**2 } }.first}"
|
|
82
|
+
|
|
83
|
+
def rgb(hue, saturation, lightness)
|
|
84
|
+
saturation /= 100.0
|
|
85
|
+
lightness /= 100.0
|
|
86
|
+
chroma = saturation * [lightness, 1 - lightness].min
|
|
87
|
+
[0, 8, 4].map do |offset|
|
|
88
|
+
k = (offset + (hue / 30.0)) % 12
|
|
89
|
+
((lightness - (chroma * [[k - 3, 9 - k, 1].min, -1].max)) * 255).round
|
|
90
|
+
end
|
|
91
|
+
end
|
|
92
|
+
|
|
93
|
+
def inside?(row, column)
|
|
94
|
+
BUMPS.any? { |x, y, radius| ((column - x)**2) + (((row - y) * ROW_STRETCH)**2) <= radius**2 } || base?(row, column)
|
|
95
|
+
end
|
|
96
|
+
|
|
97
|
+
def base?(row, column)
|
|
98
|
+
return false unless BASE_ROWS.cover?(row) && BASE_COLUMNS.cover?(column)
|
|
99
|
+
|
|
100
|
+
corner_row, corner_column = corner(row, column)
|
|
101
|
+
((column - corner_column)**2) + (((row - corner_row) * ROW_STRETCH)**2) <= CORNER**2
|
|
102
|
+
end
|
|
103
|
+
|
|
104
|
+
# The nearest point to the cell that's a corner's radius in from the base's edges, where its corners curve in
|
|
105
|
+
# from, reaching at most halfway up the base.
|
|
106
|
+
def corner(row, column)
|
|
107
|
+
inset = [CORNER / ROW_STRETCH, (BASE_ROWS.end - BASE_ROWS.begin) / 2.0].min
|
|
108
|
+
[row.clamp(BASE_ROWS.begin + inset, BASE_ROWS.end - inset), column.clamp(BASE_COLUMNS.begin + CORNER, BASE_COLUMNS.end - CORNER)]
|
|
109
|
+
end
|
|
110
|
+
end
|
|
111
|
+
|
|
112
|
+
attr_reader :width, :height
|
|
113
|
+
|
|
114
|
+
def initialize(width:, height:)
|
|
115
|
+
@width = width
|
|
116
|
+
@height = height
|
|
117
|
+
@left = (width - WIDTH) / 2
|
|
118
|
+
@top = [(height - ROWS) / 3, 0].max
|
|
119
|
+
end
|
|
120
|
+
|
|
121
|
+
# Draws the cloud and its rain at the tick into a Scene's cells.
|
|
122
|
+
def draw(cells, tick)
|
|
123
|
+
self.class.cells.each { |(row, column), (block, style)| put(cells, row, column, block, style) }
|
|
124
|
+
rain(cells, tick)
|
|
125
|
+
end
|
|
126
|
+
|
|
127
|
+
private
|
|
128
|
+
|
|
129
|
+
# Drops in the rainy columns, moving down a row a tick, fading and thinning out in steps below the cloud.
|
|
130
|
+
def rain(cells, tick)
|
|
131
|
+
falling = height - @top - ROWS
|
|
132
|
+
falling.times do |below|
|
|
133
|
+
step = below * RAIN_STEPS / falling
|
|
134
|
+
self.class.rainy.each { |column| drop(cells, column, below - tick, ROWS + below, step) }
|
|
135
|
+
end
|
|
136
|
+
end
|
|
137
|
+
|
|
138
|
+
# The drop in the column at the row, if there's one there at the tick, from a checksum of where it is in the rain.
|
|
139
|
+
def drop(cells, column, falling, row, step)
|
|
140
|
+
drop = Zlib.crc32("#{column} #{falling}")
|
|
141
|
+
return unless (drop % 100) < 90 - (step * 9)
|
|
142
|
+
|
|
143
|
+
put(cells, row, column, RAIN[drop % RAIN.length], self.class.rain_styles[step])
|
|
144
|
+
end
|
|
145
|
+
|
|
146
|
+
# The cell at the cloud's row and column, where it's on the screen.
|
|
147
|
+
def put(cells, row, column, char, style)
|
|
148
|
+
row += @top
|
|
149
|
+
column += @left
|
|
150
|
+
cells[row][column] = [char, style] if row.between?(0, height - 1) && column.between?(0, width - 1)
|
|
151
|
+
end
|
|
152
|
+
end
|
|
153
|
+
end
|
|
154
|
+
end
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require_relative '../../text'
|
|
4
|
+
require_relative '../waffle/waffle'
|
|
5
|
+
require_relative 'scene'
|
|
6
|
+
|
|
7
|
+
module Raindown
|
|
8
|
+
module TUI
|
|
9
|
+
# A Celebration over the whole screen, in place of the Layout: rain and fireworks, then a waffle popping out, among
|
|
10
|
+
# confetti, balloons and sparkles.
|
|
11
|
+
CelebrationRenderer = Struct.new(:celebration, :width, :height) do
|
|
12
|
+
include Text
|
|
13
|
+
include Waffle
|
|
14
|
+
|
|
15
|
+
def lines
|
|
16
|
+
return Scene.new(width:, height:).lines(celebration.frame) if celebration.raining?
|
|
17
|
+
|
|
18
|
+
waffle(Scene.new(width:, height:, animations: [Confetti, Balloons, Sparkles]).lines(celebration.popping), celebration.popping)
|
|
19
|
+
end
|
|
20
|
+
end
|
|
21
|
+
end
|
|
22
|
+
end
|
|
@@ -22,16 +22,16 @@ module Raindown
|
|
|
22
22
|
end
|
|
23
23
|
end
|
|
24
24
|
|
|
25
|
-
# The feelings everyone's sorted about the code as it is now, kept in .raindown/feelings.csv with the commit they were
|
|
25
|
+
# The feelings everyone's sorted about the code as it is now, kept in .raindown/data/feelings.csv with the commit they were
|
|
26
26
|
# felt at, which a node can count, like the README's code debt. A feeling about code that's since changed, or gone, moves to
|
|
27
|
-
# .raindown/memories.csv, so the feelings stay few, and the history's kept.
|
|
27
|
+
# .raindown/data/memories.csv, so the feelings stay few, and the history's kept.
|
|
28
28
|
class FeelingsLog
|
|
29
29
|
TEMPERS = %w[frolic numb woe dread malice].freeze
|
|
30
30
|
HEADER = %i[timestamp commit checksum location method temper note].freeze
|
|
31
31
|
def initialize(root:)
|
|
32
32
|
@root = root
|
|
33
|
-
@csv = File.join(root, '.raindown', 'feelings.csv')
|
|
34
|
-
@memories = File.join(root, '.raindown', 'memories.csv')
|
|
33
|
+
@csv = File.join(root, '.raindown', 'data', 'feelings.csv')
|
|
34
|
+
@memories = File.join(root, '.raindown', 'data', 'memories.csv')
|
|
35
35
|
end
|
|
36
36
|
|
|
37
37
|
# Adds the feeling, as the newest, in place of one about the method before, which moves to the memories if it was
|
|
@@ -7,14 +7,11 @@ require_relative 'bins'
|
|
|
7
7
|
require_relative 'feelings_code_box'
|
|
8
8
|
require_relative 'magnifier'
|
|
9
9
|
require_relative 'motion'
|
|
10
|
-
require_relative 'celebration/scene'
|
|
11
|
-
require_relative 'waffle/waffle'
|
|
12
10
|
|
|
13
11
|
module Raindown
|
|
14
12
|
module TUI
|
|
15
13
|
# Code feelings, right of the files: the methods as clusters of digits in a grid, with the selected one highlighted
|
|
16
14
|
# and its code below, then why it felt that way while that's typed, then the five bins and how many each holds.
|
|
17
|
-
# When the batch is refined, it rains over them, then there's a waffle:
|
|
18
15
|
# 0 0 2 2 2 5 5 9 9 9 9 1
|
|
19
16
|
# 1 3 3 7 7 7 6 4 4 0 8 8
|
|
20
17
|
# ╭─ lib/text.rb:62 · Text#segments_between ──────────── changed 6× ─╮
|
|
@@ -29,7 +26,6 @@ module Raindown
|
|
|
29
26
|
include FeelingsCodeBox
|
|
30
27
|
include Magnifier
|
|
31
28
|
include Motion
|
|
32
|
-
include Waffle
|
|
33
29
|
|
|
34
30
|
# The columns a cell takes, on a line of its own, its digit small in the middle, which is magnified in a stat's block
|
|
35
31
|
# digits across the cell and over the cells above and below it when the mouse is over its method.
|
|
@@ -66,7 +62,7 @@ module Raindown
|
|
|
66
62
|
return too_small if too_small?
|
|
67
63
|
|
|
68
64
|
cells = view.cells(columns, filled_rows)
|
|
69
|
-
return instead if view.code_methods.empty?
|
|
65
|
+
return instead if view.code_methods.empty?
|
|
70
66
|
|
|
71
67
|
below = [*code_box, *bins]
|
|
72
68
|
(grid(cells, below.length) + below).first(height)
|
|
@@ -76,20 +72,11 @@ module Raindown
|
|
|
76
72
|
|
|
77
73
|
def view = navigator.view
|
|
78
74
|
|
|
79
|
-
# Instead of the grid, that there's nothing to feel, as there are no projects or no methods
|
|
75
|
+
# Instead of the grid, that there's nothing to feel, as there are no projects or no methods.
|
|
80
76
|
def instead
|
|
81
77
|
return alert(NO_PROJECTS) if navigator.projects.empty?
|
|
82
|
-
return alert(["No functions or methods in #{File.basename(navigator.root)} to feel."]) if view.code_methods.empty?
|
|
83
78
|
|
|
84
|
-
|
|
85
|
-
end
|
|
86
|
-
|
|
87
|
-
# Rain and fireworks over the pane when the batch is refined, then a waffle popping out, among confetti, balloons and
|
|
88
|
-
# sparkles.
|
|
89
|
-
def celebration(celebration)
|
|
90
|
-
return Scene.new(width:, height:).lines(celebration.frame) if celebration.raining?
|
|
91
|
-
|
|
92
|
-
waffle(Scene.new(width:, height:, animations: [Confetti, Balloons, Sparkles]).lines(celebration.popping), celebration.popping)
|
|
79
|
+
alert(["No functions or methods in #{File.basename(navigator.root)} to feel."])
|
|
93
80
|
end
|
|
94
81
|
|
|
95
82
|
# The rows of the grid around the selected method's, between blank lines that leave the first and last rows room to
|
data/lib/raindown/tui/layout.rb
CHANGED
|
@@ -5,6 +5,7 @@ require_relative 'text'
|
|
|
5
5
|
require_relative 'title'
|
|
6
6
|
require_relative 'project_box'
|
|
7
7
|
require_relative 'search_box'
|
|
8
|
+
require_relative 'feelings/celebration/celebration_renderer'
|
|
8
9
|
|
|
9
10
|
module Raindown
|
|
10
11
|
module TUI
|
|
@@ -49,7 +50,7 @@ module Raindown
|
|
|
49
50
|
def lines
|
|
50
51
|
return [status].first(height) if height < CHROME_HEIGHT + 1
|
|
51
52
|
|
|
52
|
-
overlaid([title, *panes, status, button_bar])
|
|
53
|
+
celebration || overlaid([title, *panes, status, button_bar])
|
|
53
54
|
end
|
|
54
55
|
|
|
55
56
|
# A third of the width, within NAV_WIDTH, and never more than half of a narrow screen.
|
|
@@ -59,6 +60,12 @@ module Raindown
|
|
|
59
60
|
|
|
60
61
|
private
|
|
61
62
|
|
|
63
|
+
# Code feelings' celebration over the whole screen, while it's on.
|
|
64
|
+
def celebration
|
|
65
|
+
celebration = navigator.feelings.celebration
|
|
66
|
+
CelebrationRenderer.new(celebration, width, height).lines if celebration
|
|
67
|
+
end
|
|
68
|
+
|
|
62
69
|
# The project menu or Teleport, drawn over the lines while it's open.
|
|
63
70
|
def overlaid(lines)
|
|
64
71
|
return ProjectBox.new(navigator, width:, column: display_width(name)).apply(lines) if navigator.menu
|
data/lib/raindown/tui/project.rb
CHANGED
|
@@ -46,7 +46,7 @@ module Raindown
|
|
|
46
46
|
|
|
47
47
|
# A file's lines, headings and directives.
|
|
48
48
|
def outline(path)
|
|
49
|
-
document =
|
|
49
|
+
document = document(path)
|
|
50
50
|
Outline.new(lines: File.readlines(path, chomp: true), headings: document.headings, directives: document.directives)
|
|
51
51
|
end
|
|
52
52
|
|
|
@@ -66,9 +66,12 @@ module Raindown
|
|
|
66
66
|
# the ones whose snippet can't be read.
|
|
67
67
|
def endpoints
|
|
68
68
|
Projects.files(root).flat_map do |path|
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
69
|
+
document = document(path)
|
|
70
|
+
# Most files have no endpoint, so they aren't parsed for one.
|
|
71
|
+
next [] unless document.markdown.include?('endpoint')
|
|
72
|
+
|
|
73
|
+
runnable = document.directives.select { it.endpoint? && it.writes }
|
|
74
|
+
runnable.filter_map { |directive| endpoint(path, document.markdown.lines, directive) }
|
|
72
75
|
rescue StandardError
|
|
73
76
|
[]
|
|
74
77
|
end
|
|
@@ -96,19 +99,28 @@ module Raindown
|
|
|
96
99
|
end
|
|
97
100
|
|
|
98
101
|
def charts_in(path)
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
NodeBlocks.find(lines, front_matter: FrontMatter.parse(content).first, bare:)
|
|
102
|
+
document = document(path)
|
|
103
|
+
lines = document.markdown.lines
|
|
104
|
+
# Its headings are only parsed when it has a chart, as most files don't.
|
|
105
|
+
NodeBlocks.find(lines, front_matter: FrontMatter.parse(document.markdown).first, bare: document.bare)
|
|
105
106
|
.select { it[:node].respond_to?(:card_lines) }
|
|
106
|
-
.map { |block| chart(block, path:, lines:, headings:) }
|
|
107
|
+
.map { |block| chart(block, path:, lines:, headings: document.headings) }
|
|
107
108
|
rescue StandardError => e
|
|
108
109
|
@file_errors << "#{path.delete_prefix(File.join(root, ''))}: #{e.message}"
|
|
109
110
|
[]
|
|
110
111
|
end
|
|
111
112
|
|
|
113
|
+
# The file's Document, read and parsed again only once the file's changed, so its endpoints, charts and outline
|
|
114
|
+
# share it, and finding them again only parses the files that changed.
|
|
115
|
+
def document(path)
|
|
116
|
+
stat = File.stat(path)
|
|
117
|
+
changed = [stat.mtime, stat.size]
|
|
118
|
+
cached_at, document = (@documents ||= {})[path]
|
|
119
|
+
return document if cached_at == changed
|
|
120
|
+
|
|
121
|
+
Document.read(path, bare: @bare).tap { @documents[path] = [changed, it] }
|
|
122
|
+
end
|
|
123
|
+
|
|
112
124
|
def drawn
|
|
113
125
|
pages = {}
|
|
114
126
|
@charts.map do |chart|
|
|
@@ -12,7 +12,7 @@ module Raindown
|
|
|
12
12
|
# │ GET https://httpbin.org/uuid [Run] │
|
|
13
13
|
# ╰──────────────────────────────────────────╯
|
|
14
14
|
#
|
|
15
|
-
#
|
|
15
|
+
# response 200 · 142 ms · 2026-10-26 · json
|
|
16
16
|
# {
|
|
17
17
|
# "uuid": "48024974-f1b1-431a-a0cf-5cac0099a1a5"
|
|
18
18
|
# }
|
|
@@ -73,8 +73,9 @@ module Raindown
|
|
|
73
73
|
return [segment(" #{view.error}", :error, width:)] if view.error
|
|
74
74
|
return [segment(' No response yet. X runs the request.', :heading, width:)] if view.response.empty?
|
|
75
75
|
|
|
76
|
-
|
|
77
|
-
[
|
|
76
|
+
# As its comment in the file reads, or just response when it has none, then its language.
|
|
77
|
+
heading = [view.comment || 'response', view.language].reject { it.to_s.empty? }.join(' · ')
|
|
78
|
+
[segment(" #{heading}", :heading, width:)]
|
|
78
79
|
end
|
|
79
80
|
end
|
|
80
81
|
end
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require_relative '../cloud'
|
|
4
|
+
require_relative '../feelings/celebration/scene'
|
|
5
|
+
|
|
6
|
+
module Raindown
|
|
7
|
+
module TUI
|
|
8
|
+
# The Screen's first frames, which it's prepended to: Raindown's rain cloud over the whole screen while the Navigator's
|
|
9
|
+
# made in another thread, like while Rouge loads.
|
|
10
|
+
module Loading
|
|
11
|
+
private
|
|
12
|
+
|
|
13
|
+
def start
|
|
14
|
+
super
|
|
15
|
+
loading = Thread.new(&@loading)
|
|
16
|
+
loading.report_on_exception = false
|
|
17
|
+
rain_until(loading)
|
|
18
|
+
@navigator = loading.value
|
|
19
|
+
end
|
|
20
|
+
|
|
21
|
+
# The rain cloud, a frame each animation tick, until the thread's done.
|
|
22
|
+
def rain_until(thread)
|
|
23
|
+
scene = Scene.new(width: Curses.cols, height: Curses.lines, animations: [Cloud])
|
|
24
|
+
tick = 0
|
|
25
|
+
loop do
|
|
26
|
+
draw(scene.lines(tick))
|
|
27
|
+
break if thread.join(Screen::TICKS[:animation] / 1000.0)
|
|
28
|
+
|
|
29
|
+
tick += 1
|
|
30
|
+
end
|
|
31
|
+
end
|
|
32
|
+
end
|
|
33
|
+
end
|
|
34
|
+
end
|
|
@@ -3,6 +3,7 @@
|
|
|
3
3
|
require 'curses'
|
|
4
4
|
|
|
5
5
|
require_relative 'input'
|
|
6
|
+
require_relative 'loading'
|
|
6
7
|
require_relative '../layout'
|
|
7
8
|
require_relative 'ncurses_shim'
|
|
8
9
|
require_relative 'quiet'
|
|
@@ -15,15 +16,16 @@ module Raindown
|
|
|
15
16
|
# Only this class draws on the terminal, so another library could draw the same Layout.
|
|
16
17
|
class Screen
|
|
17
18
|
prepend TerminalTitle
|
|
19
|
+
prepend Loading
|
|
18
20
|
|
|
19
21
|
# How often, in milliseconds, the screen's drawn, and the open file checked for changes, while no key is pressed, by
|
|
20
22
|
# the view's pace, from when the last frame started drawing: every half second while it's active, at 12 frames a
|
|
21
23
|
# second while it's reactive, just faster than Code feelings' digits tremble, and at 20 during an animation.
|
|
22
24
|
TICKS = { active: 500, reactive: 83, animation: 50 }.freeze
|
|
23
25
|
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
@
|
|
26
|
+
# Loading makes the Navigator, while the rain cloud's drawn.
|
|
27
|
+
def initialize(&loading)
|
|
28
|
+
@loading = loading
|
|
27
29
|
end
|
|
28
30
|
|
|
29
31
|
def run
|
|
@@ -89,8 +91,7 @@ module Raindown
|
|
|
89
91
|
Curses.close_screen
|
|
90
92
|
end
|
|
91
93
|
|
|
92
|
-
def draw
|
|
93
|
-
lines = Layout.new(@navigator, width: Curses.cols, height: Curses.lines).lines
|
|
94
|
+
def draw(lines = Layout.new(@navigator, width: Curses.cols, height: Curses.lines).lines)
|
|
94
95
|
@zones = Input.zones(lines)
|
|
95
96
|
window = Curses.stdscr
|
|
96
97
|
window.erase
|
|
@@ -2,6 +2,8 @@
|
|
|
2
2
|
|
|
3
3
|
require 'curses'
|
|
4
4
|
|
|
5
|
+
require_relative '../cloud'
|
|
6
|
+
|
|
5
7
|
module Raindown
|
|
6
8
|
module TUI
|
|
7
9
|
# The curses attributes of a Layout's styles. Text is periwinkle where there are 256 colours, and the terminal's own
|
|
@@ -92,7 +94,7 @@ module Raindown
|
|
|
92
94
|
def colored
|
|
93
95
|
in_text_color.merge(
|
|
94
96
|
title: pair(:title) | Curses::A_BOLD, directive: pair(:directive), error: pair(:error) | Curses::A_BOLD,
|
|
95
|
-
button: pair(:button) | Curses::A_BOLD, **selections, **emphasis, **dividers, **code_tokens, **bright, **files,
|
|
97
|
+
button: pair(:button) | Curses::A_BOLD, **selections, **emphasis, **dividers, **code_tokens, **bright, **cloud, **files,
|
|
96
98
|
**unfocused
|
|
97
99
|
)
|
|
98
100
|
end
|
|
@@ -130,6 +132,8 @@ module Raindown
|
|
|
130
132
|
# The bright colours, bold, so they're bright in 8 colours too.
|
|
131
133
|
def bright = BRIGHT.keys.to_h { [it, pair(it) | Curses::A_BOLD] }
|
|
132
134
|
|
|
135
|
+
def cloud = Cloud.styles.to_h { [it, pair(it)] }
|
|
136
|
+
|
|
133
137
|
# The lines between the panes and beneath the title.
|
|
134
138
|
def dividers = { divider: pair(:divider) }
|
|
135
139
|
|
|
@@ -156,6 +160,7 @@ module Raindown
|
|
|
156
160
|
*(many ? METHODS : BASIC_METHODS).map { |name, color| [:"method_#{name}", color, -1] },
|
|
157
161
|
*(many ? CODE.merge(BRIGHT, FEELINGS, ACCENTS) : BASIC_CODE.merge(BASIC_BRIGHT, BASIC_FEELINGS, BASIC_ACCENTS))
|
|
158
162
|
.map { |name, color| [name, color, -1] },
|
|
163
|
+
*cloud_pairs,
|
|
159
164
|
[:text, text, -1],
|
|
160
165
|
[:selected, white, blues[:selected]], [:felt_selected, white, blues[:felt]], [:too_small, white, many ? DARK_RED : Curses::COLOR_RED],
|
|
161
166
|
[:selected_button, Curses::COLOR_YELLOW, blues[:selected]],
|
|
@@ -163,6 +168,13 @@ module Raindown
|
|
|
163
168
|
[:shine, white, -1]]
|
|
164
169
|
end
|
|
165
170
|
|
|
171
|
+
# The rain cloud's blues while the terminal UI loads, each the 256 colour its style's named after, or cyan with 8.
|
|
172
|
+
def cloud_pairs
|
|
173
|
+
return Cloud.styles.map { [it, Curses::COLOR_CYAN, -1] } if Curses.colors < 256
|
|
174
|
+
|
|
175
|
+
Cloud.styles.map { [it, it.to_s.delete_prefix('cloud_').to_i, -1] }
|
|
176
|
+
end
|
|
177
|
+
|
|
166
178
|
def pair(name)
|
|
167
179
|
Curses.color_pair(pairs.index { it.first == name } + 1)
|
|
168
180
|
end
|