Module: IRB2025Mikan

Defined in:
lib/irb/theme/rk2025.rb

Defined Under Namespace

Classes: Canvas

Class Method Summary collapse

Class Method Details

.paramsObject



106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
# File 'lib/irb/theme/rk2025.rb', line 106

def self.params
  prev_color = nil
  @params ||= 100.times.map do |i|
    bi = rand(0.02..0.05)
    bo = rand(0.05..0.1)
    bm = bo * rand(1.0..2.0)
    color = prev_color
    color = 16+36*5+6*rand(3..5)+rand(1..2) while color == prev_color
    prev_color = color
    {
      cx: rand,
      cy: 15 * i + rand(10),
      segments: rand(7..9),
      theta: 2 * Math::PI * rand,
      rot: (0.2 + 0.4 * rand) * (rand > 0.5 ? 1 : -1),
      bi:, bm:, bo:,
      radius: rand(12..24),
      color:
    }
  end
end

.reset_paramsObject



128
129
130
# File 'lib/irb/theme/rk2025.rb', line 128

def self.reset_params
  @params = nil
end

.startObject



132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
# File 'lib/irb/theme/rk2025.rb', line 132

def self.start
  Reline::LineEditor.prepend Module.new {
    def colorize_completion_dialog
      dialog = @dialogs[0]
      unless dialog&.contents
        IRB2025Mikan.reset_params
        return
      end

      canvas = Canvas.new(dialog.width, dialog.contents.size)
      face = Reline::Face[:completion_dialog]
      time = Time.now.to_f
      original_contents = dialog.contents.instance_eval { @original ||= dup }
      canvas.focus_line = original_contents.find_index { |line| line.include?(face[:enhanced]) }
      uncolored_lines = original_contents.map do |line|
        line.gsub(/\e\[[\d;]*m/, '')
      end
      canvas.lines = uncolored_lines
      IRB2025Mikan.params.each do |param|
        param in { cx:, cy:, segments:, theta:, rot:, bo:, bi:, bm:, radius:, color: }
        cy = (cy - dialog.scroll_top) % 1500 - 100
        theta += time * rot
        canvas.draw(5 + (canvas.w - 5)*cx, cy, radius+0.5, color){|x,y|
          z = x+y.i
          a = z.arg
          a2 = ((a-theta)/2/Math::PI*segments).round*2*Math::PI/segments+theta
          (z*Complex.polar(1, -a2)).imag.abs > bi + 10**(10*(z.abs2 - 1 + bo + bm)) || (z.abs<1&&z.abs>1-bo)
        }
      end

      dialog.contents[0..] = canvas.render_to_lines
    end

    def update_dialogs(...)
      @_updating_dialogs = true
      super(...)
      colorize_completion_dialog
    ensure
      @_updating_dialogs = false
    end

    def _updating_dialogs?
      @_updating_dialogs
    end

    def rerender
      (@mutex ||= Mutex.new).synchronize { super }
    end
  }
  Thread.new do
    Reline.line_editor.instance_eval do
      loop do
        sleep 0.1
        colorize_completion_dialog && rerender unless _updating_dialogs?
      end
    end
  end
end