raindown 0.12.0 → 0.14.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/elements.rb +12 -25
- data/lib/lexemes/node_lexeme.rb +37 -0
- data/lib/nodes/list_node.rb +22 -25
- data/lib/nodes/write_in_node.rb +95 -0
- data/lib/raindown/bare_directives.rb +11 -17
- data/lib/raindown/chart/chart.rb +1 -1
- data/lib/raindown/code_blocks.rb +23 -15
- data/lib/raindown/context.rb +19 -0
- data/lib/raindown/directives.rb +1 -1
- data/lib/raindown/document.rb +9 -9
- data/lib/raindown/endpoint/endpoint_runner.rb +15 -24
- data/lib/raindown/fragments.rb +6 -1
- data/lib/raindown/js/host.mjs +2 -2
- data/lib/raindown/js/js_nodes.rb +4 -4
- data/lib/raindown/list.rb +31 -0
- data/lib/raindown/markdown_nodes.rb +3 -2
- data/lib/raindown/node.rb +10 -2
- data/lib/raindown/node_blocks.rb +28 -27
- data/lib/raindown/node_injector.rb +7 -1
- data/lib/raindown/nodes.rb +61 -21
- data/lib/raindown/pages.rb +14 -8
- data/lib/raindown/pre_renderer.rb +13 -10
- data/lib/raindown/stat.rb +1 -1
- data/lib/raindown/table/markdown_table.rb +35 -0
- data/lib/raindown/table/table.rb +87 -0
- data/lib/raindown/toc.rb +2 -2
- 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_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/wiki_links.rb +1 -1
- data/lib/raindown.rb +9 -14
- data/lib/version.rb +1 -1
- metadata +11 -5
- data/lib/lexemes/list_lexeme.rb +0 -32
- data/lib/nodes/component_nodes.rb +0 -38
- data/lib/raindown/files.rb +0 -22
|
@@ -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
|
|
@@ -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
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
# frozen_string_literal: true
|
|
2
2
|
|
|
3
|
+
require_relative '../../code_blocks'
|
|
3
4
|
require_relative '../events'
|
|
4
5
|
require_relative '../../workers/worker'
|
|
5
6
|
|
|
@@ -9,11 +10,11 @@ module Raindown
|
|
|
9
10
|
# Worker when it's opened, which scrolls.
|
|
10
11
|
# A key's next step, for the Navigator, is nil, an Open or Edit of its directive, or an Execute of it.
|
|
11
12
|
class EndpointView
|
|
12
|
-
# The
|
|
13
|
-
|
|
13
|
+
# The text of the comment above a response, like "response 200 · 142 ms · 2026-10-26".
|
|
14
|
+
COMMENT = /<!--\s*(.*?)\s*-->/
|
|
14
15
|
FENCE = /\A\s*`{3,}(\S*)/
|
|
15
16
|
|
|
16
|
-
attr_reader :endpoint, :response, :language, :
|
|
17
|
+
attr_reader :endpoint, :response, :language, :comment, :error
|
|
17
18
|
|
|
18
19
|
def initialize(endpoint, workers:)
|
|
19
20
|
@endpoint = endpoint
|
|
@@ -36,7 +37,7 @@ module Raindown
|
|
|
36
37
|
# Reads the response again, like after the request's run.
|
|
37
38
|
def load
|
|
38
39
|
lines = output_lines
|
|
39
|
-
@
|
|
40
|
+
@comment = lines.shift[COMMENT, 1] if lines.first&.match?(CodeBlocks::RESPONSE_COMMENT)
|
|
40
41
|
@language = lines.first.to_s[FENCE, 1]
|
|
41
42
|
@response = @language ? lines[1...-1] : lines
|
|
42
43
|
@error = nil
|
data/lib/raindown/tui.rb
CHANGED
|
@@ -27,12 +27,16 @@ module Raindown
|
|
|
27
27
|
# so two projects' nodes of the same name stay apart.
|
|
28
28
|
workers = Project.workers(root:, bare:, execute:)
|
|
29
29
|
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
30
|
+
saves = nil
|
|
31
|
+
Screen.new do
|
|
32
|
+
# Rouge loads here, rather than with Raindown, which doesn't highlight code outside the TUI, while the screen shows
|
|
33
|
+
# the rain cloud.
|
|
34
|
+
require 'rouge'
|
|
35
|
+
# Saved files are written back, like when the folder's watched.
|
|
36
|
+
require_relative 'tui/saves'
|
|
37
|
+
saves = Saves.new(root)
|
|
38
|
+
Navigator.new(root:, path: (path unless File.directory?(path)), workers:, saves:, runs_endpoints: execute)
|
|
39
|
+
end.run
|
|
36
40
|
true
|
|
37
41
|
ensure
|
|
38
42
|
saves&.stop
|
data/lib/raindown/wiki_links.rb
CHANGED
|
@@ -5,7 +5,7 @@ require_relative 'front_matter'
|
|
|
5
5
|
|
|
6
6
|
module Raindown
|
|
7
7
|
# Obsidian's links between notes, which render as Markdown links to the file they name, by its path in the project,
|
|
8
|
-
# like
|
|
8
|
+
# like list: links, while the file keeps them as they are:
|
|
9
9
|
# [[Reading list]] [Reading list](<notes/Reading list.md>)
|
|
10
10
|
# [[Reading list|books]] [books](<notes/Reading list.md>)
|
|
11
11
|
# [[Reading list#To read]] [Reading list > To read](<notes/Reading list.md#to-read>)
|
data/lib/raindown.rb
CHANGED
|
@@ -8,6 +8,7 @@ require_relative 'elements'
|
|
|
8
8
|
require_relative 'raindown/bare_directives'
|
|
9
9
|
require_relative 'raindown/code'
|
|
10
10
|
require_relative 'raindown/config'
|
|
11
|
+
require_relative 'raindown/context'
|
|
11
12
|
require_relative 'raindown/directives'
|
|
12
13
|
require_relative 'raindown/fragments'
|
|
13
14
|
require_relative 'raindown/front_matter'
|
|
@@ -32,7 +33,7 @@ module Raindown
|
|
|
32
33
|
# Without highlighting, code blocks are left for the browser to highlight, like <pre><code class="language-ruby">.
|
|
33
34
|
UNHIGHLIGHTED_OPTIONS = { render: { **HTML_OPTIONS[:render], github_pre_lang: false } }.freeze
|
|
34
35
|
|
|
35
|
-
# Stands in for an app's metadata when there isn't any, so list:
|
|
36
|
+
# Stands in for an app's metadata when there isn't any, so list: lists nothing.
|
|
36
37
|
module NoMetadata
|
|
37
38
|
def self.list(**) = []
|
|
38
39
|
end
|
|
@@ -49,13 +50,12 @@ module Raindown
|
|
|
49
50
|
# Bare directives like "toc:" show in bold in the HTML, and the rest stay hidden, as comments.
|
|
50
51
|
# Code blocks are highlighted, unless highlight_code is false for a site that highlights code in the browser.
|
|
51
52
|
def render(markdown:, metadata: NoMetadata, bare: false, highlight_code: true)
|
|
52
|
-
bare
|
|
53
|
+
context = Context.new(document: markdown, metadata:, bare: bare || BareDirectives.front_matter?(markdown))
|
|
53
54
|
|
|
54
55
|
highlighting(highlight_code) do
|
|
55
56
|
Fragments.collect do
|
|
56
57
|
# Components' HTML goes back in, then their headings get unique ids, before nodes like the TOC see it.
|
|
57
|
-
html = assembled(
|
|
58
|
-
html = Nodes.render_placeholders(html, document: markdown, metadata:, bare:, html:)
|
|
58
|
+
html = Nodes.render_placeholders(assembled(context), context)
|
|
59
59
|
|
|
60
60
|
Directives.render("#{html.chomp}\n")
|
|
61
61
|
end
|
|
@@ -77,15 +77,14 @@ module Raindown
|
|
|
77
77
|
end
|
|
78
78
|
|
|
79
79
|
# The document's HTML with its components' HTML put back, and unique heading ids.
|
|
80
|
-
def assembled(
|
|
81
|
-
HeadingIds.unique(Fragments.fill(html(
|
|
80
|
+
def assembled(context)
|
|
81
|
+
HeadingIds.unique(Fragments.fill(html(context)))
|
|
82
82
|
end
|
|
83
83
|
|
|
84
84
|
# The document's HTML from Commonmarker, after nodes and the template pass, with components as fragments.
|
|
85
|
-
def html(
|
|
86
|
-
markdown = NodeBlocks.to_rendered(
|
|
87
|
-
markdown
|
|
88
|
-
commonmark(PreRenderer.render(markdown, variables:, metadata:, bare:))
|
|
85
|
+
def html(context)
|
|
86
|
+
markdown = WikiLinks.to_markdown(NodeBlocks.to_rendered(context), metadata: context.metadata)
|
|
87
|
+
commonmark(PreRenderer.render(markdown, variables: context.variables, context:))
|
|
89
88
|
end
|
|
90
89
|
|
|
91
90
|
# Markdown to HTML, like a document's or a component's slot.
|
|
@@ -103,10 +102,6 @@ module Raindown
|
|
|
103
102
|
doc.to_html(options: UNHIGHLIGHTED_OPTIONS, plugins: { syntax_highlighter: nil })
|
|
104
103
|
end
|
|
105
104
|
|
|
106
|
-
def variables(markdown:)
|
|
107
|
-
Variables.new(FrontMatter.parse(markdown).first)
|
|
108
|
-
end
|
|
109
|
-
|
|
110
105
|
# Commonmarker escapes directives, so they're hidden in HTML comments until it's done.
|
|
111
106
|
def hide_directives(markdown:)
|
|
112
107
|
markdown.gsub('<{', '<!-- ANTLERS').gsub('}>', 'ANTLERS -->').force_encoding('UTF-8')
|
data/lib/version.rb
CHANGED