Class: TRuby::Watcher

Inherits:
Object
  • Object
show all
Defined in:
lib/t_ruby/watcher.rb

Constant Summary collapse

COLORS =

ANSI color codes (similar to tsc output style)

{
  reset: "\e[0m",
  bold: "\e[1m",
  dim: "\e[2m",
  red: "\e[31m",
  green: "\e[32m",
  yellow: "\e[33m",
  blue: "\e[34m",
  cyan: "\e[36m",
  gray: "\e[90m"
}.freeze

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(paths: ["."], config: nil, incremental: true, cross_file_check: true, parallel: true) ⇒ Watcher

Returns a new instance of Watcher.



22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
# File 'lib/t_ruby/watcher.rb', line 22

def initialize(paths: ["."], config: nil, incremental: true, cross_file_check: true, parallel: true)
  @paths = paths.map { |p| File.expand_path(p) }
  @config = config || Config.new
  @compiler = Compiler.new(@config)
  @error_count = 0
  @file_count = 0
  @use_colors = $stdout.tty?

  # Enhanced features
  @incremental = incremental
  @cross_file_check = cross_file_check
  @parallel = parallel

  # Initialize incremental compiler
  if @incremental
    @incremental_compiler = EnhancedIncrementalCompiler.new(
      @compiler,
      enable_cross_file: @cross_file_check
    )
  end

  # Parallel processor
  @parallel_processor = ParallelProcessor.new if @parallel

  # Statistics
  @stats = {
    total_compilations: 0,
    incremental_hits: 0,
    total_time: 0.0
  }
end

Instance Attribute Details

#incremental_compilerObject (readonly)

Returns the value of attribute incremental_compiler.



20
21
22
# File 'lib/t_ruby/watcher.rb', line 20

def incremental_compiler
  @incremental_compiler
end

#statsObject (readonly)

Returns the value of attribute stats.



20
21
22
# File 'lib/t_ruby/watcher.rb', line 20

def stats
  @stats
end

Instance Method Details

#watchObject



54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
# File 'lib/t_ruby/watcher.rb', line 54

def watch
  print_start_message

  # Initial compilation
  start_time = Time.now
  compile_all
  @stats[:total_time] += Time.now - start_time

  # Start watching
  listener = Listen.to(*watch_directories, only: /\.trb$/) do |modified, added, removed|
    handle_changes(modified, added, removed)
  end

  listener.start

  print_watching_message

  # Keep the process running
  begin
    sleep
  rescue Interrupt
    puts "\n#{colorize(:dim, timestamp)} #{colorize(:cyan, "Stopping watch mode...")}"
    print_stats if @incremental
    listener.stop
  end
end