Class: Glimmer::LibUI::CustomControl::CodeEntry
  
  
  
  
    
      Constant Summary
      collapse
    
    
      
        - REGEX_COLOR_HEX6 =
          
        
 
        /^#([0-9a-f]{2})([0-9a-f]{2})([0-9a-f]{2})$/ 
      
    
  
  Instance Attribute Summary collapse
  
  
  
  
  #args, #body_root, #content, #keyword, #libui, #options, #parent, #parent_proxy, #slot_controls
  
    
      Instance Method Summary
      collapse
    
    
  
  
  
  
  
  
  
  
  
  
  add_custom_control_namespaces_for, after_body, before_body, body, #can_handle_listener?, custom_control_namespaces, custom_controls_being_interpreted, def_option_attr_accessors, flyweight_custom_control_classes, for, #handle_listener, #has_instance_method?, #initialize, keyword, namespaces_for_class, #observer_registrations, option, options, #post_add_content, #post_initialize_child, reset_custom_control_namespaces, shortcut_keyword
  
  
  
    Instance Attribute Details
    
      
      
      
  
  
    #line  ⇒ Object  
  
  
  
  
    
TODO consider offering the option to autosave to a file upon changes
   
 
  
  
    
      
45
46
47 
     | 
    
      # File 'lib/glimmer/libui/custom_control/code_entry.rb', line 45
def line
  @line
end 
     | 
  
 
    
      
      
      
  
  
    #position  ⇒ Object  
  
  
  
  
    
TODO consider offering the option to autosave to a file upon changes
   
 
  
  
    
      
45
46
47 
     | 
    
      # File 'lib/glimmer/libui/custom_control/code_entry.rb', line 45
def position
  @position
end 
     | 
  
 
    
      
      
      
  
  
    #syntax_highlighter  ⇒ Object  
  
  
  
  
    
TODO consider offering the option to autosave to a file upon changes
   
 
  
  
    
      
45
46
47 
     | 
    
      # File 'lib/glimmer/libui/custom_control/code_entry.rb', line 45
def syntax_highlighter
  @syntax_highlighter
end 
     | 
  
 
    
   
  
    Instance Method Details
    
      
  
  
    #caret_index  ⇒ Object 
  
  
  
  
    
      
278
279
280 
     | 
    
      # File 'lib/glimmer/libui/custom_control/code_entry.rb', line 278
def caret_index
  code.lines[0..line].join.length - (current_code_line.length - @position)
end 
     | 
  
 
    
      
  
  
    #caret_layer  ⇒ Object 
  
  
  
  
    
      
260
261
262
263
264
265
266
267
268
269
270
271 
     | 
    
      # File 'lib/glimmer/libui/custom_control/code_entry.rb', line 260
def caret_layer
    text(padding - 4, padding) {
    default_font @font_default
      
        string(caret_text) {
      color :black
      background [0, 0, 0, 0]
    }
  }
end
     | 
  
 
    
      
  
  
    #caret_text  ⇒ Object 
  
  
  
  
    
      
273
274
275
276 
     | 
    
      # File 'lib/glimmer/libui/custom_control/code_entry.rb', line 273
def caret_text
    ("\n" * @line) + (' ' * @position) + '|'
end
     | 
  
 
    
      
  
  
    #code_layer  ⇒ Object 
  
  
  
  
    
      
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258 
     | 
    
      # File 'lib/glimmer/libui/custom_control/code_entry.rb', line 244
def code_layer
  text(padding, padding) {
    default_font @font_default
    
    syntax_highlighter.syntax_highlighting(code).each do |token|
      token_text = token[:token_text].start_with?("\n") ? " #{token[:token_text]}" : token[:token_text]
      
      string(token_text) {
        font @font_italic if token[:token_style][:italic]
        color token[:token_style][:fg] || :black
        background token[:token_style][:bg] || :white
      }
    end
  }
end
     | 
  
 
    
      
  
  
    #current_code_line  ⇒ Object 
  
  
  
  
    
      
282
283
284 
     | 
    
      # File 'lib/glimmer/libui/custom_control/code_entry.rb', line 282
def current_code_line
  code.lines[@line]
end 
     | 
  
 
    
      
  
  
    #current_code_line_max_position  ⇒ Object 
  
  
  
  
    
      
286
287
288 
     | 
    
      # File 'lib/glimmer/libui/custom_control/code_entry.rb', line 286
def current_code_line_max_position
  (current_code_line && current_code_line.length > 0) ? (current_code_line.length - 1) : 0
end 
     | 
  
 
    
      
  
  
    #line_count  ⇒ Object 
  
  
  
  
    
      
294
295
296 
     | 
    
      # File 'lib/glimmer/libui/custom_control/code_entry.rb', line 294
def line_count
  code&.lines&.size || 1
end 
     | 
  
 
    
      
  
  
    #longest_line_size  ⇒ Object 
  
  
  
  
    
      
290
291
292 
     | 
    
      # File 'lib/glimmer/libui/custom_control/code_entry.rb', line 290
def longest_line_size
  code&.lines&.map(&:size)&.max || 1
end 
     |