raindown 0.5.1 → 0.6.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.
Files changed (44) hide show
  1. checksums.yaml +4 -4
  2. data/lib/raindown/cli.rb +2 -2
  3. data/lib/raindown/document.rb +15 -4
  4. data/lib/raindown/endpoint/curl.rb +15 -0
  5. data/lib/raindown/projects.rb +8 -4
  6. data/lib/raindown/tui/card.rb +56 -0
  7. data/lib/raindown/tui/endpoint.rb +16 -0
  8. data/lib/raindown/tui/endpoints.rb +40 -0
  9. data/lib/raindown/tui/events.rb +35 -0
  10. data/lib/raindown/tui/file_tree.rb +53 -11
  11. data/lib/raindown/tui/layout.rb +60 -78
  12. data/lib/raindown/tui/menu_overlay.rb +59 -0
  13. data/lib/raindown/tui/navigator/commands.rb +84 -0
  14. data/lib/raindown/tui/navigator/focus.rb +25 -0
  15. data/lib/raindown/tui/navigator/navigator.rb +127 -0
  16. data/lib/raindown/tui/navigator/project_menu.rb +61 -0
  17. data/lib/raindown/tui/navigator/views.rb +49 -0
  18. data/lib/raindown/tui/renderers/dashboard_renderer.rb +102 -0
  19. data/lib/raindown/tui/renderers/endpoint_renderer.rb +77 -0
  20. data/lib/raindown/tui/renderers/list_renderer.rb +15 -0
  21. data/lib/raindown/tui/renderers/outline_renderer.rb +21 -0
  22. data/lib/raindown/tui/renderers/renderer.rb +15 -0
  23. data/lib/raindown/tui/row.rb +10 -3
  24. data/lib/raindown/tui/rows.rb +57 -0
  25. data/lib/raindown/tui/{input.rb → terminal/input.rb} +10 -11
  26. data/lib/raindown/tui/terminal/ncurses_shim.rb +46 -0
  27. data/lib/raindown/tui/terminal/quiet.rb +32 -0
  28. data/lib/raindown/tui/{screen.rb → terminal/screen.rb} +32 -17
  29. data/lib/raindown/tui/terminal/styles.rb +96 -0
  30. data/lib/raindown/tui/text.rb +83 -0
  31. data/lib/raindown/tui/title.rb +29 -0
  32. data/lib/raindown/tui/views/dashboard_view.rb +145 -0
  33. data/lib/raindown/tui/views/endpoint_view.rb +75 -0
  34. data/lib/raindown/tui/{pane.rb → views/list_view.rb} +9 -8
  35. data/lib/raindown/tui/{outline.rb → views/outline_view.rb} +39 -20
  36. data/lib/raindown/tui/workers/project.rb +122 -0
  37. data/lib/raindown/tui/workers/worker.rb +124 -0
  38. data/lib/raindown/tui/workers/workers.rb +53 -0
  39. data/lib/raindown/tui.rb +8 -5
  40. data/lib/version.rb +1 -1
  41. metadata +32 -9
  42. data/lib/raindown/tui/commands.rb +0 -70
  43. data/lib/raindown/tui/navigator.rb +0 -123
  44. data/lib/raindown/tui/styles.rb +0 -36
@@ -2,8 +2,8 @@
2
2
 
3
3
  module Raindown
4
4
  module TUI
5
- # A pane's cursor and how far it's scrolled, over rows that can change between draws, like when a folder folds.
6
- class Pane
5
+ # Rows with a cursor, and how far they're scrolled, which can change between draws, like when a folder folds.
6
+ class ListView
7
7
  attr_writer :cursor
8
8
 
9
9
  def initialize(&rows)
@@ -12,6 +12,8 @@ module Raindown
12
12
  @offset = 0
13
13
  end
14
14
 
15
+ def renderer = ListRenderer
16
+
15
17
  def rows = @rows.call
16
18
  def selected = rows[cursor]
17
19
 
@@ -20,13 +22,12 @@ module Raindown
20
22
  @cursor.clamp(0, [rows.length - 1, 0].max)
21
23
  end
22
24
 
25
+ # Moves past rows that can't be selected, like separators, and stays at the first or last row rather than moving off them.
23
26
  def move(by)
24
- @cursor = (cursor + by).clamp(0, [rows.length - 1, 0].max)
25
- end
26
-
27
- def reset
28
- @cursor = 0
29
- @offset = 0
27
+ rows = self.rows
28
+ index = cursor + by
29
+ index += by while index.between?(0, rows.length - 1) && !rows[index].selectable?
30
+ @cursor = index if index.between?(0, rows.length - 1)
30
31
  end
31
32
 
32
33
  # The rows that fit in the height, scrolled so the cursor's row is one of them, and the first one's index.
@@ -1,30 +1,41 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require_relative '../document'
4
- require_relative 'row'
3
+ require_relative '../../document'
4
+ require_relative '../events'
5
+ require_relative 'list_view'
6
+ require_relative '../row'
7
+ require_relative '../workers/worker'
5
8
 
6
9
  module Raindown
7
10
  module TUI
8
- # The outline pane: a file's headings and directives, read from its Document. Headings fold the section below them,
9
- # and a directive's output, the lines Raindown wrote back, expands below it. Both start folded away.
10
- class Outline
11
+ # The outline: a file's headings and directives, read by its project's Worker. Headings fold the section below them,
12
+ # and a directive's body expands below it, like the lines a node wrote back or an endpoint's request and response.
13
+ # Both start folded away. It's read when it's opened, and it's a ListView, with its own cursor.
14
+ class OutlineView < ListView
11
15
  attr_reader :path, :error
12
16
 
13
- def initialize(path)
17
+ def initialize(path, workers:)
18
+ super()
14
19
  @path = path
20
+ @workers = workers
15
21
  @folded = Set.new
16
22
  @expanded = Set.new
17
- read
18
23
  end
19
24
 
25
+ def renderer = OutlineRenderer
26
+ def target = path
27
+ def next_step?(_key) = false
28
+ def status(navigator) = [:info, "Opened #{navigator.relative(path)}"]
29
+
20
30
  # Reads the file again, keeping what's folded.
21
- def read
31
+ def load
22
32
  @mtime = File.mtime(path)
23
- @document = Document.read(path)
24
- @lines = File.readlines(path, chomp: true)
25
- @document.directives # Finds an error in the file, like a missing end tag, now rather than while drawing.
33
+ outline = @workers.for(path).call(:outline, path)
34
+ @lines = outline.lines
35
+ @headings = outline.headings
36
+ @directives = outline.directives
26
37
  @error = nil
27
- rescue StandardError => e
38
+ rescue Worker::Error, SystemCallError => e
28
39
  @error = e.message
29
40
  end
30
41
 
@@ -72,34 +83,42 @@ module Raindown
72
83
 
73
84
  # Headings a directive wrote are part of its output, so they show when it's expanded rather than on their own.
74
85
  def items
75
- outputs = @document.directives.filter_map(&:output)
76
- @document.outline.reject { |item| item.is_a?(Document::Heading) && outputs.any? { it.cover?(item.line) } }
86
+ outputs = @directives.filter_map(&:output)
87
+ (@headings + @directives).sort_by(&:line)
88
+ .reject { |item| item.is_a?(Document::Heading) && outputs.any? { it.cover?(item.line) } }
77
89
  end
78
90
 
79
91
  def min_level
80
- @document.headings.map(&:level).min || 1
92
+ @headings.map(&:level).min || 1
81
93
  end
82
94
 
83
95
  def heading_row(heading)
84
96
  folded = @folded.include?(heading.line) ? ' …' : ''
85
97
  Row.new(text: "#{'#' * heading.level} #{heading.text}#{folded}", depth: heading.level - min_level, kind: :heading,
86
- target: heading)
98
+ target: heading, fold: -> { fold(heading) })
87
99
  end
88
100
 
89
101
  def directive_rows(directive, depth:)
90
102
  expanded = @expanded.include?(directive.line)
91
103
  row = Row.new(text: directive_text(directive), depth:, kind: :directive, target: directive,
92
- buttons: buttons(directive, expanded:))
104
+ buttons: buttons(directive, expanded:), **directive_action(directive))
93
105
  return [row] unless expanded
94
106
 
95
- [row, *directive.output.map do |number|
96
- Row.new(text: @lines[number - 1].to_s, depth: depth + 1, kind: :output, target: number)
107
+ [row, *directive.body.map do |number|
108
+ Row.new(text: @lines[number - 1].to_s, depth: depth + 1, kind: :body, target: number, open: Edit.new(path:, line: number))
97
109
  end]
98
110
  end
99
111
 
112
+ # A directive with a body expands it, and one without opens in the editor, like a line of its body.
113
+ def directive_action(directive)
114
+ if directive.body then { fold: -> { expand(directive) } }
115
+ else { open: Edit.new(path:, line: directive.line) }
116
+ end
117
+ end
118
+
100
119
  def buttons(directive, expanded:)
101
120
  buttons = []
102
- buttons << [expanded ? '[-]' : "[+#{directive.output.size}]", :toggle] if directive.output
121
+ buttons << [expanded ? '[-]' : "[+#{directive.body.size}]", :toggle] if directive.body
103
122
  buttons << ['[Run]', :execute] if directive.endpoint?
104
123
  buttons
105
124
  end
@@ -0,0 +1,122 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative '../../actions'
4
+ require_relative '../../bare_directives'
5
+ require_relative '../../chart/chart'
6
+ require_relative '../../document'
7
+ require_relative '../../front_matter'
8
+ require_relative '../../node_blocks'
9
+ require_relative '../../nodes'
10
+ require_relative '../../pages'
11
+ require_relative '../../projects'
12
+ require_relative '../card'
13
+ require_relative '../endpoint'
14
+ require_relative '../../code_blocks'
15
+ require_relative '../../endpoint/curl'
16
+
17
+ module Raindown
18
+ module TUI
19
+ # What the terminal UI asks of a project, answered in the project's Worker with its own nodes loaded,
20
+ # so two projects' nodes of the same name stay apart. Answers are plain data, which a Worker sends back through a pipe.
21
+ class Project
22
+ Outline = Data.define(:lines, :headings, :directives)
23
+
24
+ attr_reader :root
25
+
26
+ # The projects inside this one have workers of their own, so their files are left out.
27
+ def initialize(root:)
28
+ @root = root
29
+ @load_errors = []
30
+ @file_errors = []
31
+ Nodes.load(File.join(root, Nodes::FOLDER))
32
+ rescue StandardError, ScriptError => e
33
+ @load_errors << "#{File.basename(root)}/#{Nodes::FOLDER}: #{e.message}"
34
+ end
35
+
36
+ # A file's lines, headings and directives.
37
+ def outline(path)
38
+ document = Document.read(path)
39
+ Outline.new(lines: File.readlines(path, chomp: true), headings: document.headings, directives: document.directives)
40
+ end
41
+
42
+ # Every chart in the project's files, drawn from its data, and the files that couldn't be read.
43
+ # The charts are found again when asked, and otherwise drawn again, so they follow changes to their data.
44
+ def charts(find: false)
45
+ if find || @charts.nil?
46
+ @file_errors = []
47
+ @charts = Projects.files(root).flat_map { |path| charts_in(path) }
48
+ end
49
+
50
+ { cards: drawn, errors: @load_errors + @file_errors }
51
+ end
52
+
53
+ # Every endpoint in the project's files, by its request, leaving out the ones whose snippet can't be read.
54
+ def endpoints
55
+ Projects.files(root).flat_map do |path|
56
+ lines = File.readlines(path, encoding: Encoding::UTF_8)
57
+ Document.read(path).directives.select(&:endpoint?).filter_map { |directive| endpoint(path, lines, directive) }
58
+ rescue StandardError
59
+ []
60
+ end
61
+ end
62
+
63
+ def write_back(path)
64
+ Actions.write_back(path)
65
+ end
66
+
67
+ # Runs the endpoint on the line, replacing its response.
68
+ def execute(path, line)
69
+ directive = Document.read(path).directives.find { it.line == line && it.endpoint? }
70
+ raise Actions::NotAnEndpoint, "There's no endpoint on line #{line}" unless directive
71
+
72
+ Actions.execute(path, directive)
73
+ end
74
+
75
+ private
76
+
77
+ def endpoint(path, lines, directive)
78
+ snippet = CodeBlocks.endpoint(lines, directive.line).first&.dig(:body)
79
+ request = Curl.request(snippet.to_s)
80
+ Endpoint.new(project: root, path:, line: directive.line, **request.to_h) if request
81
+ end
82
+
83
+ def charts_in(path)
84
+ content = File.read(path, encoding: Encoding::UTF_8)
85
+ bare = BareDirectives.enabled?(path:, content:)
86
+ lines = content.lines
87
+ headings = Document.parse(content, bare:).headings
88
+
89
+ NodeBlocks.find(lines, front_matter: FrontMatter.parse(content).first, bare:)
90
+ .select { |block| block[:node].is_a?(Raindown::Chart) }
91
+ .map { |block| chart(block, path:, lines:, headings:) }
92
+ rescue StandardError => e
93
+ @file_errors << "#{path.delete_prefix(File.join(root, ''))}: #{e.message}"
94
+ []
95
+ end
96
+
97
+ def drawn
98
+ pages = {}
99
+ @charts.map do |chart|
100
+ lines = lines(chart, pages[File.dirname(chart[:path])] ||= Pages.for(chart[:path]))
101
+ Card.new(project: root, chart: lines, **chart.except(:node))
102
+ end
103
+ end
104
+
105
+ def chart(block, path:, lines:, headings:)
106
+ line = block[:open] + 1
107
+ directive = lines[block[:open]].strip.delete_prefix('<{').delete_suffix('}>').strip
108
+
109
+ { path:, line:, heading: headings.select { it.line < line }.last&.text, directive:, node: block[:node] }
110
+ end
111
+
112
+ # Draws the chart as its Markdown would be written back, with the files its project lists.
113
+ def lines(chart, metadata)
114
+ node = chart[:node]
115
+ points = node.points(metadata:)
116
+ points.empty? ? ['No data'] : node.draw(points).map(&:rstrip)
117
+ rescue StandardError => e
118
+ ["Can't chart: #{e.message}"]
119
+ end
120
+ end
121
+ end
122
+ end
@@ -0,0 +1,124 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative 'project'
4
+
5
+ module Raindown
6
+ module TUI
7
+ # A Project in a process of its own, forked so it loads the project's nodes apart from other projects', like watching.
8
+ # Requests and answers go through two pipes, as Marshal data, one at a time. Without fork, like on Windows,
9
+ # or with fork off, like in specs, the Project answers in this process instead.
10
+ # The process ends with exit!, since it's forked mid-call, so the terminal UI's ensure doesn't run in it.
11
+ class Worker
12
+ class Error < StandardError; end
13
+
14
+ class << self
15
+ attr_writer :fork
16
+
17
+ def fork?
18
+ @fork.nil? ? Process.respond_to?(:fork) : @fork
19
+ end
20
+
21
+ # Every worker's pipes, which a new worker closes the others of, since a worker holding another's pipe open
22
+ # would keep that worker from seeing it close.
23
+ def pipes
24
+ @pipes ||= []
25
+ end
26
+ end
27
+
28
+ attr_reader :root
29
+
30
+ def initialize(root:, fork: self.class.fork?)
31
+ @root = root
32
+ @fork = fork
33
+ end
34
+
35
+ # The Project's answer, or a Worker::Error with its error's message. A worker that stopped starts again.
36
+ def call(name, *args, **options)
37
+ return local(name, args, options) unless @fork
38
+
39
+ start unless alive?
40
+ write(@requests, [name, args, options])
41
+ status, value = read(@answers) || raise(Error, "The worker for #{File.basename(root)} stopped")
42
+ status == :ok ? value : raise(Error, value)
43
+ end
44
+
45
+ def stop
46
+ [@requests, @answers].compact.each { it.close unless it.closed? }
47
+ return unless @pid
48
+
49
+ Process.kill('TERM', @pid)
50
+ Process.wait(@pid)
51
+ rescue Errno::ECHILD, Errno::ESRCH
52
+ nil
53
+ ensure
54
+ @pid = nil
55
+ end
56
+
57
+ private
58
+
59
+ def local(name, args, options)
60
+ @project ||= Project.new(root:)
61
+ @project.public_send(name, *args, **options)
62
+ rescue StandardError => e
63
+ raise Error, e.message
64
+ end
65
+
66
+ def start
67
+ stop
68
+ requests, @requests = IO.pipe
69
+ @answers, answers = IO.pipe
70
+ self.class.pipes.reject!(&:closed?)
71
+ self.class.pipes.push(@requests, @answers)
72
+ @pid = fork do
73
+ self.class.pipes.each { it.close unless it.closed? }
74
+ serve(requests, answers)
75
+ end
76
+ requests.close
77
+ answers.close
78
+ end
79
+
80
+ # Answers until the terminal UI closes its end. The screen is the terminal UI's, so nothing is written to it,
81
+ # and Ctrl+C, which reaches every process in the terminal, is the terminal UI's to handle.
82
+ def serve(requests, answers)
83
+ trap('INT', 'IGNORE')
84
+ $stdout.reopen(File::NULL)
85
+ $stderr.reopen(File::NULL)
86
+ project = Project.new(root:)
87
+
88
+ while (request = read(requests))
89
+ write(answers, answer(project, *request))
90
+ end
91
+ ensure
92
+ exit!(0)
93
+ end
94
+
95
+ def answer(project, name, args, options)
96
+ [:ok, project.public_send(name, *args, **options)]
97
+ rescue StandardError, ScriptError => e
98
+ [:error, e.message]
99
+ end
100
+
101
+ def alive?
102
+ @pid && Process.waitpid(@pid, Process::WNOHANG).nil?
103
+ rescue Errno::ECHILD
104
+ false
105
+ end
106
+
107
+ # A message is its length, then its Marshal data.
108
+ def write(io, message)
109
+ data = Marshal.dump(message)
110
+ io.write([data.bytesize].pack('N'), data)
111
+ io.flush
112
+ rescue Errno::EPIPE, IOError
113
+ raise Error, "The worker for #{File.basename(root)} stopped"
114
+ end
115
+
116
+ def read(io)
117
+ length = io.read(4)&.unpack1('N')
118
+ Marshal.load(io.read(length)) if length # rubocop:disable Security/MarshalLoad -- from this process's own fork
119
+ rescue IOError
120
+ nil
121
+ end
122
+ end
123
+ end
124
+ end
@@ -0,0 +1,53 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative '../../projects'
4
+ require_relative 'worker'
5
+
6
+ module Raindown
7
+ module TUI
8
+ # A Worker for each project in the terminal UI's folder: the folder's own, and every project inside it.
9
+ # A file's requests go to the worker of the project it's in, the nearest one above it, even when it's new.
10
+ # Workers start when they're first asked something.
11
+ class Workers
12
+ attr_reader :root, :roots
13
+
14
+ def initialize(root:, fork: Worker.fork?)
15
+ @root = root
16
+ @fork = fork
17
+ @workers = {}
18
+ find_roots
19
+ end
20
+
21
+ def for(path)
22
+ worker(Projects.root(path) || root)
23
+ end
24
+
25
+ # A worker for each project, as they were found when the workers last started.
26
+ def each(&)
27
+ roots.map { worker(it) }.each(&)
28
+ end
29
+
30
+ # Stops the workers, so the next requests start them again, loading their projects' nodes again,
31
+ # and finds the projects again, like ones added since.
32
+ def restart
33
+ stop
34
+ @workers.clear
35
+ find_roots
36
+ end
37
+
38
+ def stop
39
+ @workers.each_value(&:stop)
40
+ end
41
+
42
+ private
43
+
44
+ def worker(project)
45
+ @workers[project] ||= Worker.new(root: project, fork: @fork)
46
+ end
47
+
48
+ def find_roots
49
+ @roots = [root, *Projects.roots(root)].uniq.sort
50
+ end
51
+ end
52
+ end
53
+ end
data/lib/raindown/tui.rb CHANGED
@@ -1,8 +1,7 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require_relative 'nodes'
4
3
  require_relative 'projects'
5
- require_relative 'tui/navigator'
4
+ require_relative 'tui/navigator/navigator'
6
5
 
7
6
  module Raindown
8
7
  # The terminal UI, started with "raindown tui": a project's Markdown files beside the open file's outline,
@@ -13,15 +12,19 @@ module Raindown
13
12
 
14
13
  # PATH is a file to open, or a directory. Its project is the one it's in, or else the directory itself.
15
14
  def start(path)
16
- require_relative 'tui/screen'
15
+ require_relative 'tui/terminal/screen'
17
16
  # Without a terminal, curses' own error is "Error opening terminal: unknown".
18
17
  abort('raindown tui needs a terminal') unless $stdin.tty? && $stdout.tty?
19
18
 
20
19
  path = File.expand_path(path)
21
20
  root = Projects.root(path) || (File.directory?(path) ? path : File.dirname(path))
22
- Nodes.load(File.join(root, Nodes::FOLDER))
21
+ # The projects inside it are shown too. Each loads its own nodes in its worker's process, like when watching,
22
+ # so two projects' nodes of the same name stay apart.
23
+ workers = Workers.new(root:)
23
24
 
24
- Screen.new(Navigator.new(root:, path: (path unless File.directory?(path)))).run
25
+ Screen.new(Navigator.new(root:, path: (path unless File.directory?(path)), workers:)).run
26
+ ensure
27
+ workers&.stop
25
28
  end
26
29
  end
27
30
  end
data/lib/version.rb CHANGED
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Raindown
4
- VERSION = '0.5.1'
4
+ VERSION = '0.6.0'
5
5
  end
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: raindown
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.5.1
4
+ version: 0.6.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - maedi
8
8
  bindir: bin
9
9
  cert_chain: []
10
- date: 2026-10-26 00:00:00.000000000 Z
10
+ date: 2026-10-27 00:00:00.000000000 Z
11
11
  dependencies:
12
12
  - !ruby/object:Gem::Dependency
13
13
  name: antlers
@@ -216,16 +216,39 @@ files:
216
216
  - lib/raindown/table_formatter.rb
217
217
  - lib/raindown/toc.rb
218
218
  - lib/raindown/tui.rb
219
- - lib/raindown/tui/commands.rb
219
+ - lib/raindown/tui/card.rb
220
+ - lib/raindown/tui/endpoint.rb
221
+ - lib/raindown/tui/endpoints.rb
222
+ - lib/raindown/tui/events.rb
220
223
  - lib/raindown/tui/file_tree.rb
221
- - lib/raindown/tui/input.rb
222
224
  - lib/raindown/tui/layout.rb
223
- - lib/raindown/tui/navigator.rb
224
- - lib/raindown/tui/outline.rb
225
- - lib/raindown/tui/pane.rb
225
+ - lib/raindown/tui/menu_overlay.rb
226
+ - lib/raindown/tui/navigator/commands.rb
227
+ - lib/raindown/tui/navigator/focus.rb
228
+ - lib/raindown/tui/navigator/navigator.rb
229
+ - lib/raindown/tui/navigator/project_menu.rb
230
+ - lib/raindown/tui/navigator/views.rb
231
+ - lib/raindown/tui/renderers/dashboard_renderer.rb
232
+ - lib/raindown/tui/renderers/endpoint_renderer.rb
233
+ - lib/raindown/tui/renderers/list_renderer.rb
234
+ - lib/raindown/tui/renderers/outline_renderer.rb
235
+ - lib/raindown/tui/renderers/renderer.rb
226
236
  - lib/raindown/tui/row.rb
227
- - lib/raindown/tui/screen.rb
228
- - lib/raindown/tui/styles.rb
237
+ - lib/raindown/tui/rows.rb
238
+ - lib/raindown/tui/terminal/input.rb
239
+ - lib/raindown/tui/terminal/ncurses_shim.rb
240
+ - lib/raindown/tui/terminal/quiet.rb
241
+ - lib/raindown/tui/terminal/screen.rb
242
+ - lib/raindown/tui/terminal/styles.rb
243
+ - lib/raindown/tui/text.rb
244
+ - lib/raindown/tui/title.rb
245
+ - lib/raindown/tui/views/dashboard_view.rb
246
+ - lib/raindown/tui/views/endpoint_view.rb
247
+ - lib/raindown/tui/views/list_view.rb
248
+ - lib/raindown/tui/views/outline_view.rb
249
+ - lib/raindown/tui/workers/project.rb
250
+ - lib/raindown/tui/workers/worker.rb
251
+ - lib/raindown/tui/workers/workers.rb
229
252
  - lib/raindown/variables.rb
230
253
  - lib/raindown/watcher.rb
231
254
  - lib/version.rb
@@ -1,70 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require_relative '../actions'
4
-
5
- module Raindown
6
- module TUI
7
- # What a Navigator does to the open file: run an endpoint, open the editor, write back and read it again.
8
- # Each sets the status, so the Screen shows how it went, and returns what the Screen should do next, if anything.
9
- module Commands
10
- private
11
-
12
- def execute
13
- directive = selected(:outline)&.target if @focus == :outline
14
- return error('Select an endpoint to run') unless directive.is_a?(Document::Directive) && directive.endpoint?
15
-
16
- [:wait, "Running the endpoint on line #{directive.line}...", -> { run_endpoint(directive) }]
17
- end
18
-
19
- def run_endpoint(directive)
20
- changed = Actions.execute(path, directive)
21
- @outline.read
22
- info(changed ? "Ran the endpoint on line #{directive.line}" : 'The response is the same')
23
- rescue StandardError => e
24
- error(e.message)
25
- end
26
-
27
- # In the files pane, the selected file opens at its top, and in the outline, the open file at the selected line.
28
- def edit
29
- row = selected
30
- show(row.target) if @focus == :files && row&.kind == :file
31
- return error('Open a file to edit') unless path
32
-
33
- line = @focus == :outline && row ? row.line : 1
34
- [:run, Actions.edit_command(path, line:)]
35
- end
36
-
37
- def write_back
38
- return error('Open a file to write back') unless path
39
-
40
- changed = Actions.write_back(path)
41
- @outline.read
42
- info(changed ? "Updated #{relative(path)}" : "#{relative(path)} is up to date")
43
- rescue StandardError => e
44
- error(e.message)
45
- end
46
-
47
- def reload
48
- @files.load
49
- @outline&.read if path && File.exist?(path)
50
- info('Reloaded')
51
- end
52
-
53
- # Reads the file again when it's changed, like when it's saved in an editor or a watcher writes back to it.
54
- def refresh
55
- @outline.read if @outline&.changed?
56
- nil
57
- end
58
-
59
- def info(message)
60
- @status = [:info, message]
61
- nil
62
- end
63
-
64
- def error(message)
65
- @status = [:error, message]
66
- nil
67
- end
68
- end
69
- end
70
- end