diff --git a/.gitignore b/.gitignore index a4fee73..fdafc09 100644 --- a/.gitignore +++ b/.gitignore @@ -10,7 +10,7 @@ tests/* !tests/.keep -builds/* -!builds/.keep +build/* +bin/* -src/cpp/__tmp__ +__old__ diff --git a/__old__/builds/.keep b/__old__/builds/.keep deleted file mode 100644 index e69de29..0000000 diff --git a/__old__/crib.rb b/__old__/crib.rb deleted file mode 100755 index 650d9fd..0000000 --- a/__old__/crib.rb +++ /dev/null @@ -1,54 +0,0 @@ -#!/usr/bin/env ruby - -require "ffi" -require "zlib" - -require_relative "../src/ruby/utils" -require_relative "../src/ruby/mod" -require_relative "../src/ruby/ts_rb" -require_relative "../src/ruby/fm" -require_relative "../src/ruby/editor" -require_relative "../src/ruby/ide" - -$rows, $cols = C.start_screen -$running = true -$event_queue = Queue.new -$folder = Dir.new File.dirname(ARGV[0] || Dir.pwd) -$threads = [] - -at_exit do - IDE.close - C.end_screen - puts "Exiting crib.rb" -end - -IDE.start - -$threads << Thread.new do - loop do - sleep 1.0 / 64 - break unless $running - IDE.handle_event $event_queue.pop timeout: 0 until $event_queue.empty? - IDE.render - C.render - end -end - -$threads << Thread.new do - loop do - sleep 1.0 / 64 - break unless $running - IDE.work! - end -end - -$threads << Thread.new do - loop do - break unless $running - event = C.read_key # read_key is blocking - $running = false if KEY_TYPE[event[:key_type]] == :char && event[:c] == ctrl_key('q') - $event_queue << event - end -end - -$threads.each &:join diff --git a/__old__/editor.rb b/__old__/editor.rb deleted file mode 100644 index 70a9087..0000000 --- a/__old__/editor.rb +++ /dev/null @@ -1,329 +0,0 @@ -class Editor - attr_accessor :text, :cursor, :selection_start, :filename - - def initialize(filename, x, y, width, height) - contents = File.exist?(filename) ? File.read(filename) : "dddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddd" - @text = contents.grapheme_clusters - @cursor = @text.size - @selection_start = 0 - @scroll = 0 - @x = x - @y = y - @width = width - @height = height - @filename = filename - @folds = [] - @highlights = Array.new(@text.size) - @highlight_generation = 0 - @tree = nil - @num_width = (@text.count("\n") + 1).to_s.size + 3 - - @parser = C.ts_parser_new - @lang_ts = C.tree_sitter_ruby - C.ts_parser_set_language @parser, @lang_ts - @cached_tree = nil - C.load_query "/home/syed/main/crib/grammar/ruby.scm" - - highlight! - - rebuild_folded_lines! - end - - def save! - File.write @filename, @text.join - end - - def highlight! - gen = @highlight_generation - src = @text.join - text_bytes = [] - byte_offset = 0 - @text.each do |cluster| - text_bytes << byte_offset - byte_offset += cluster.bytesize - end - text_bytes << byte_offset - line_map = [] - line = 0 - @text.each_with_index do |ch, i| - line_map[i] = line - line += 1 if ch == "\n" - end - # TODO: add ts_tree_edit calls in erase/insert - count_ptr = FFI::MemoryPointer.new :uint32 - @cached_tree = C.ts_parser_parse_string @parser, nil, src, src.bytesize - root = C.ts_tree_root_node @cached_tree - ptr = C.ts_collect_tokens root, count_ptr, @lang_ts, src - count = count_ptr.read_uint32 - ints = ptr.read_array_of_uint32 count - C.free_tokens ptr - count_ptr.free - C.ts_tree_delete @cached_tree - return if gen != @highlight_generation - @highlight_generation = 0 - @highlights = Array.new(@text.size) - done_folds = [] - ints.each_slice(3).map do |start_byte, end_byte, sym_i| - start_cluster = byte_to_cluster start_byte, text_bytes - end_cluster = byte_to_cluster end_byte - 1, text_bytes - next if start_cluster.nil? || end_cluster.nil? - sym = TS_SYMBOL_MAP[sym_i] - if sym == "@fold" - start_row = line_map[start_cluster] - end_row = line_map[end_cluster] - next if start_row == end_row - hash_value = Zlib.crc32 @text[start_cluster...end_cluster].join - done_folds << hash_value - if (f = @folds.find { |f| f.crc32 == hash_value }) - f.start = start_row - f.end = end_row - else - @folds << Fold.new(start_row, end_row, false, hash_value) - end - next - end - hl = TS_RUBY[sym] - next unless hl - (start_cluster..end_cluster).each do |i| - @highlights[i] = hl if @highlights[i].nil? || @highlights[i].priority < hl.priority - end - end - @folds.select! { |f| done_folds.include? f.crc32 } - rebuild_folded_lines! - end - - def byte_to_cluster(byte, byte_starts) - left = 0 - right = byte_starts.size - 2 - while left <= right - mid = (left + right) / 2 - if byte_starts[mid] <= byte && byte < byte_starts[mid + 1] - return mid - elsif byte < byte_starts[mid] - right = mid - 1 - else - left = mid + 1 - end - end - nil - end - - def erase(x0, x1) - return if x0 < 0 || x1 < x0 - lines_deleted = @text[x0...x1].count "\n" - @text[x0...x1] = [] - @highlights[x0...x1] = [] - @highlight_generation += 1 - @folds.map! do |f| - if f.start >= @text[...x0].count("\n") - f.start -= lines_deleted - f.end -= lines_deleted - end - f - end - rebuild_folded_lines! - @num_width = (@text.count("\n") + 1).to_s.size + 3 - end - - def insert(x, str) - @text.insert x, *str.grapheme_clusters - @highlights.insert x, *Array.new(str.grapheme_clusters.size) - lines_added = str.count "\n" - @folds.map! do |f| - if f.start >= @text[...x].count("\n") - f.start += lines_added - f.end += lines_added - end - f - end - rebuild_folded_lines! - @highlight_generation += 1 - @num_width = (@text.count("\n") + 1).to_s.size + 3 - end - - def move_up! - precursor_text = @text[...@cursor] - last_newline = precursor_text.rindex "\n" - return unless last_newline - @preferred_col ||= @cursor - last_newline - prev_start = precursor_text[...last_newline].rindex("\n") || -1 - @cursor = [ - prev_start + @preferred_col, - @text[prev_start + 1..].index("\n")&.+(prev_start + 1) || @text.size - ].min - end - - def move_down! - next_newline = @text[@cursor..].index("\n")&.+(@cursor) - return unless next_newline - @preferred_col ||= (@cursor - (@text[...@cursor].rindex("\n") || -1)).abs - @cursor = [ - next_newline + @preferred_col, - @text[next_newline + 1..].index("\n")&.+(next_newline + 1) || @text.size - ].min - end - - def move_left! - @cursor = [@cursor - 1, 0].max - @preferred_col = nil - end - - def move_right! - @cursor = [@cursor + 1, @text.size].min - @preferred_col = nil - end - - def cursor_valid? - !@folded_lines.include? @text[0...@cursor].count("\n") - end - - def handle_event(event) - return if event.nil? - case KEY_TYPE[event[:key_type]] - when :char - ch = event[:c].chr - ch = "\n" if ch == "\r" - if ch == "'" - cr = @text[0...@cursor].count("\n") - @folds.find { |f| f.active = !f.active if f.start <= cr && f.end >= cr } - rebuild_folded_lines! - elsif ch == ctrl_key('s').chr - save! - elsif ch =~ /[[:print:]]|\n/ - insert @cursor, ch - @cursor += 1 - elsif ch == "\b" || ch == "\x7f" - erase @cursor - 1, @cursor - @cursor = [@cursor - 1, 0].max - end - @preferred_col = nil - when :special - return unless MODIFIER[event[:special_modifier]] == :none - case SPECIAL_KEY[event[:special_key]] - when :up - move_up! - move_up! until cursor_valid? - when :down - move_down! - move_down! until cursor_valid? - when :left - move_left! - move_left! until cursor_valid? - when :right - move_right! - move_right! until cursor_valid? - when :delete - erase @cursor, @cursor + 1 - @cursor = [@cursor, @text.size].min - @preferred_col = nil - end - end - move_right! until cursor_valid? - adjust_scroll! - end - - def adjust_scroll! - cr = cursor_row_visual - start = @scroll - last = @scroll + @height - 1 - if cr < start - @scroll = cr - elsif cr > last - @scroll = cr - @height + 1 - end - end - - def cursor_row_visual - row = col = 0 - nc = 0 - @text.each_with_index do |ch, i| - return row if i == @cursor - if @folded_lines.include? nc - nc += 1 if ch == "\n" - next - end - if ch == "\n" - row += 1 - nc += 1 - col = 0 - next - end - w = C.display_width(ch) - if col + w > @width - @num_width - row += 1 - col = 0 - end - col += w - end - row - end - - def rebuild_folded_lines! - @folded_lines = Set.new - @folds.each do |f| - (f.start + 1..f.end).each { |line_num| @folded_lines.add(line_num) } if f.active - end - end - - def render - (0...@height).each { |h| (0...@width).each { |w| - C.update @y + h, @x + w, ' ', 0x000000, 0x000000, 0 - } } - row = col = nc = 0 - cursor_row = cursor_col = nil - @text.each_with_index do |ch, i| - if @folded_lines.include? nc - nc += 1 if ch == "\n" - next - end - if i == @cursor - cursor_row = row - cursor_col = col - end - if col == 0 - color = 0x666666 - color = 0xFFFFFF if cursor_row == row - num = (nc + 1).to_s.rjust @num_width - 1, '👪👩‍💻👨🏿‍🚀🏳️‍🌈🔥🛠️🌍🥶✅❌💡⏰🚀'#ddasasdasda - num.each_char.with_index do |c, j| - C.update @y + row - @scroll, @x + j, c, color, 0x000000, 0 - end - if (fold = @folds.find { |f| nc == f.start }) - icon = fold.active ? "" : "" # "" : "" "" : "" "" : "" "" : "" "" : "" "" : "" "" : "" "" : "" "" : "" "" : "" "" : "" "" : "" "" : "" "" : "" "" : "" "" : "" "" : "" "" : "" "" : "" "" : "" "" : "" "" : "" "" : "" "" : "" "" : "" "" : "" "" : "" "" : "" "" : "" "" : "" "" : "" "" : "" "" : "" "" : "" "" : "" "" : "" "" : "" "" : "" "" : "" "" : "" "" : "" "" : "" "" : "" "" : "" "" : "" "" : "" "" : "" "" : "" "" : "" "" : "" "" : "" "" : "" "" : "" "" : "" - C.update @y + row - @scroll, @x, icon, 0xFF0000, 0x000000, 0 - end - end - if ch == "\n" - row += 1 - nc += 1 - col = 0 - next - end - w = C.display_width(ch) - if col + w > @width - @num_width - row += 1 - col = 0 - end - col += w - next if row < @scroll - break if row - @scroll >= @height - fg = 0xFFFFFF - bg = 0x000000 - fl = 0 - if (h = @highlights[i]) - fg = h.color_fg - bg = h.color_bg - fl = h.flags - end - C.update @y + row - @scroll, @x + @num_width + col - w, ch, fg, bg, fl - end - if @text[-1] == "\n" || @text.size == 0 - num = (nc + 1).to_s.rjust @num_width - 1, ' ' - color = 0x666666 - color = 0xFFFFFF if (cursor_row || row) == row - num.each_char.with_index do |c, j| - C.update @y + row - @scroll, @x + j, c, color, 0x000000, 0 - end - end - C.set_cursor @y - @scroll + (cursor_row || row), @x + @num_width + (cursor_col || col), 1 - end -end diff --git a/__old__/fm.rb b/__old__/fm.rb deleted file mode 100644 index 897b478..0000000 --- a/__old__/fm.rb +++ /dev/null @@ -1,30 +0,0 @@ -module FileManager - @hidden = true - - module_function - - def start(x, y, width, height) - @hidden = false - @x = x - @y = y - @width = width - @height = height - end - - def toggle! - @hidden = !@hidden - end - - def render - return if @hidden - (0...@height).each { |h| (0...@width).each { |w| - C.update @y + h, @x + w, ' ', 0x000000, 0x000000, 0 - } } - files = $folder.children - files.each_with_index do |f, i| - f.each_char.with_index do |c, j| - C.update @y + i, @x + j, c, 0xFFFFFF, 0x000000, 0 - end - end - end -end diff --git a/__old__/ide.rb b/__old__/ide.rb deleted file mode 100644 index e61e9d2..0000000 --- a/__old__/ide.rb +++ /dev/null @@ -1,36 +0,0 @@ -module IDE - FM_WIDTH = 20 - - module_function - - def start - @editors = {} - @u_c = 0 - editor = Editor.new (ARGV[0] || ""), FM_WIDTH, 0, $cols - FM_WIDTH, $rows - @editors[editor.filename || "untitled #{@u_c += 1}"] = editor - @selected_editor = @editors.keys.first - @focus = :editor - FileManager.start 0, 0, FM_WIDTH, $rows - end - - def handle_event(event) - if @focus == :editor - @editors[@selected_editor].handle_event event if @editors.key? @selected_editor - elsif @focus == :file_manager - # TODO - end - end - - def render - @editors[@selected_editor].render if @editors.key? @selected_editor - FileManager.render - end - - def work! - @editors[@selected_editor].highlight! if @editors.key? @selected_editor - end - - def close - # TODO - end -end diff --git a/__old__/mod.rb b/__old__/mod.rb deleted file mode 100644 index ed56916..0000000 --- a/__old__/mod.rb +++ /dev/null @@ -1,126 +0,0 @@ -module C - extend FFI::Library - ffi_lib File.join(__dir__, "../../libs/tree-sitter/libtree-sitter.so") - - # TSTree and TSParser are opaque pointers - typedef :pointer, :tstree - typedef :pointer, :tsparser - - # Define TSNode struct - class TSNode < FFI::Struct - layout :context, [:uint32, 4], - :id, :pointer, - :tree, :tstree - end - - class TSPoint < FFI::Struct - layout :row, :uint32, - :column, :uint32 - end - - class TSInputEdit < FFI::Struct - layout :start_byte, :uint32, - :old_end_byte, :uint32, - :new_end_byte, :uint32, - :start_point, TSPoint.by_value, - :old_end_point, TSPoint.by_value, - :new_end_point, TSPoint.by_value - end - - class TSTreeCursor < FFI::Struct - layout :tree, :pointer, - :id, :pointer, - :context, [:uint32, 3] - end - - attach_function :ts_parser_new, [], :tsparser - attach_function :ts_parser_set_language, [:tsparser, :pointer], :bool - attach_function :ts_parser_parse_string, [:tsparser, :tstree, :string, :size_t], :tstree, blocking: true - attach_function :ts_tree_delete, [:tstree], :void - - attach_function :ts_node_start_byte, [TSNode.by_value], :uint32 - attach_function :ts_node_end_byte, [TSNode.by_value], :uint32 - attach_function :ts_node_symbol, [TSNode.by_value], :uint16 - - attach_function :ts_tree_edit, [:tstree, TSInputEdit.by_ref], :void - - attach_function :ts_tree_root_node, [:tstree], TSNode.by_value, blocking: true - - attach_function :ts_node_child_count, [TSNode.by_value], :uint32 - attach_function :ts_node_child, [TSNode.by_value, :uint32], TSNode.by_value - - - - # Ruby grammar - ffi_lib File.join(__dir__, "../../libs/tree-sitter-ruby/libtree-sitter-ruby.so") - attach_function :tree_sitter_ruby, [], :pointer - - - ffi_lib File.join(__dir__, "../../builds/C-crib.so") - - class KeyEvent < FFI::Struct - layout :key_type, :uint8, - :c, :char, - :special_key, :uint8, - :special_modifier, :uint8, - :mouse_x, :uint8, - :mouse_y, :uint8, - :mouse_button, :uint8, - :mouse_state, :uint8, - :mouse_direction, :uint8, - :mouse_modifier, :uint8 - - def to_s - case KEY_TYPE[self[:key_type]] - when :char - "#" - when :special - "#" - when :mouse - "#" - else - "#" - end - end - end - - class Coords < FFI::Struct - layout :x, :int, - :y, :int - - def to_ary - [self[:x], self[:y]] - end - - def to_s - "#" - end - end - - class Size < FFI::Struct - layout :rows, :int, - :cols, :int - - def to_ary - [self[:rows], self[:cols]] - end - - def to_s - "#" - end - end - - attach_function :load_query, [:string], :void - attach_function :ts_collect_tokens, [TSNode.by_value, :pointer, :pointer, :string], :pointer, blocking: true - attach_function :free_tokens, [:pointer], :void, blocking: true - attach_function :start_screen, [], Size.by_value - attach_function :end_screen, [], :void - attach_function :update, [:int, :int, :string, :uint32, :uint32, :uint8], :void - attach_function :render, [], :void, blocking: true - attach_function :set_cursor, [:int, :int, :int], :void - attach_function :read_key, [], KeyEvent.by_value, blocking: true - attach_function :get_size, [], Coords.by_value - attach_function :display_width, [:string], :int, blocking: true -end diff --git a/__old__/ts_rb.rb b/__old__/ts_rb.rb deleted file mode 100644 index f9556c2..0000000 --- a/__old__/ts_rb.rb +++ /dev/null @@ -1,57 +0,0 @@ -query = File.read "/home/syed/main/crib/grammar/ruby.scm" - -raw = query.scan(/@[a-zA-Z0-9_.]+/) - -seen = {} -ordered = [] - -raw.each do |c| - next if seen[c] - seen[c] = true - ordered << c -end - -TS_SYMBOL_MAP = ordered.freeze - -spawn "echo \"#{TS_SYMBOL_MAP.sort.join "\n"}\" > /tmp/gg" - -TS_RUBY = { - "@string.special.symbol" => Highlight.new(0xbd9ae6, 0x000000, CF_NONE, 2), - "@comment" => Highlight.new(0xAAAAAA, 0x000000, CF_ITALIC, 1), - "@boolean.true" => Highlight.new(0x51eeba, 0x000000, CF_NONE, 1), - "@boolean.false" => Highlight.new(0xee513a, 0x000000, CF_NONE, 1), - "@constant.nil" => Highlight.new(0xee8757, 0x000000, CF_NONE, 1), - "@constant" => Highlight.new(0xebda8c, 0x000000, CF_NONE, 1), - "@number" => Highlight.new(0xebda8c, 0x000000, CF_NONE, 2), - "@number.float" => Highlight.new(0xebda8c, 0x000000, CF_NONE, 2), - "@constant.builtin" => Highlight.new(0xfbb152, 0x000000, CF_NONE, 2), - "@punctuation.bracket" => Highlight.new(0xbd9ae6, 0x000000, CF_NONE, 1), - "@operator.ligature" => Highlight.new(0xffffff, 0x000000, CF_ITALIC, 1), - "@operator" => Highlight.new(0xffffff, 0x000000, CF_NONE, 1), - "@punctuation.delimiter" => Highlight.new(0xbd9ae6, 0x000000, CF_NONE, 1), - "@punctuation.special" => Highlight.new(0xe6a24c, 0x000000, CF_NONE, 1), - "@function" => Highlight.new(0xaad84c, 0x000000, CF_NONE, 1), - "@function.builtin" => Highlight.new(0xaad84c, 0xFF0000, CF_NONE, 1), - "@keyword.import" => Highlight.new(0xfbb152, 0x000000, CF_NONE, 1), - "@function.call" => Highlight.new(0xff5689, 0x000000, CF_NONE, 1), - - "@keyword" => Highlight.new(0xfbb152, 0x000000, CF_NONE, 1), - "@keyword.conditional" => Highlight.new(0xfbb152, 0x000000, CF_NONE, 1), - "@keyword.control" => Highlight.new(0xfbb152, 0x000000, CF_NONE, 1), - "@keyword.directive" => Highlight.new(0xfbb152, 0x000000, CF_NONE, 1), - "@keyword.exception" => Highlight.new(0xfbb152, 0x000000, CF_NONE, 1), - "@keyword.function" => Highlight.new(0xfbb152, 0x000000, CF_NONE, 1), - "@keyword.operator" => Highlight.new(0xfbb152, 0x000000, CF_NONE, 1), - "@keyword.repeat" => Highlight.new(0xfbb152, 0x000000, CF_NONE, 1), - "@keyword.return" => Highlight.new(0xfbb152, 0x000000, CF_NONE, 1), - "@keyword.type" => Highlight.new(0xfbb152, 0x000000, CF_NONE, 1), - "@label" => Highlight.new(0xfbb152, 0x000000, CF_NONE, 1), - "@string" => Highlight.new(0xaad84c, 0x000000, CF_NONE, 1), - "@string.escape" => Highlight.new(0xe6a24c, 0x000000, CF_NONE, 2), - "@string.regexp" => Highlight.new(0xe6a24c, 0x000000, CF_NONE, 2), - "@type" => Highlight.new(0xaad84c, 0x000000, CF_NONE, 1), - "@variable" => Highlight.new(0xffffff, 0x000000, CF_NONE, 1), - "@variable.builtin" => Highlight.new(0xffffff, 0x000000, CF_NONE, 1), - "@variable.member" => Highlight.new(0xffffff, 0x000000, CF_NONE, 1), - "@variable.parameter" => Highlight.new(0xffffff, 0x000000, CF_NONE, 1), -} diff --git a/__old__/utils.rb b/__old__/utils.rb deleted file mode 100644 index 09ac361..0000000 --- a/__old__/utils.rb +++ /dev/null @@ -1,67 +0,0 @@ -Fold = Struct.new(:start, :end, :active, :crc32) -Highlight = Struct.new(:color_fg, :color_bg, :flags, :priority) -Token = Struct.new(:start, :end, :sym) - -CF_NONE = 0b00000000 -CF_ITALIC = 0b00000001 -CF_BOLD = 0b00000010 -CF_UNDERLINE = 0b00000100 - -def ctrl_key(k) - k.ord & 0x1F -end - -# Key types -KEY_TYPE = { - 0 => :char, - 1 => :special, - 2 => :mouse, - 3 => :none -}.freeze - -# Special keys -SPECIAL_KEY = { - 0 => :up, - 1 => :down, - 2 => :left, - 3 => :right, - 4 => :delete -}.freeze - -# Control key -KEY_ESC = "\x1b".freeze - -# Mouse states -MOUSE_STATE = { - 0 => :press, - 1 => :release, - 2 => :drag, - 3 => :scroll -}.freeze - -# Mouse buttons -MOUSE_BUTTON = { - 0 => :left, - 1 => :middle, - 2 => :right, - 3 => :scroll, - 4 => :none -}.freeze - -# Scroll directions -SCROLL_DIR = { - 0 => :up, - 1 => :down, - 2 => :left, - 3 => :right, - 4 => :none -}.freeze - -# Modifiers -MODIFIER = { - 0 => :none, - 1 => :alt, - 2 => :cntrl, - 3 => :cntrl_alt, - 4 => :shift -}.freeze diff --git a/bin/crib b/bin/crib deleted file mode 100755 index a56937b..0000000 Binary files a/bin/crib and /dev/null differ diff --git a/bin/crib-dbg b/bin/crib-dbg deleted file mode 100755 index e9757f3..0000000 Binary files a/bin/crib-dbg and /dev/null differ diff --git a/build/debug/editor.d b/build/debug/editor.d deleted file mode 100644 index d8e4993..0000000 --- a/build/debug/editor.d +++ /dev/null @@ -1,14 +0,0 @@ -build/debug/editor.o: src/editor.cc src/../libs/libgrapheme/grapheme.h \ - src/../include/editor.h \ - src/../include/../libs/tree-sitter/lib/include/tree_sitter/api.h \ - src/../include/./rope.h src/../include/./ui.h src/../include/./utils.h \ - src/../include/ts.h \ - src/../libs/tree-sitter-ruby/bindings/c/tree-sitter-ruby.h -src/../libs/libgrapheme/grapheme.h: -src/../include/editor.h: -src/../include/../libs/tree-sitter/lib/include/tree_sitter/api.h: -src/../include/./rope.h: -src/../include/./ui.h: -src/../include/./utils.h: -src/../include/ts.h: -src/../libs/tree-sitter-ruby/bindings/c/tree-sitter-ruby.h: diff --git a/build/debug/editor.dwo b/build/debug/editor.dwo deleted file mode 100644 index b145722..0000000 Binary files a/build/debug/editor.dwo and /dev/null differ diff --git a/build/debug/input.d b/build/debug/input.d deleted file mode 100644 index b303603..0000000 --- a/build/debug/input.d +++ /dev/null @@ -1,2 +0,0 @@ -build/debug/input.o: src/input.cc src/../include/ui.h -src/../include/ui.h: diff --git a/build/debug/input.dwo b/build/debug/input.dwo deleted file mode 100644 index 6f347ed..0000000 Binary files a/build/debug/input.dwo and /dev/null differ diff --git a/build/debug/main.d b/build/debug/main.d deleted file mode 100644 index 54d87f6..0000000 --- a/build/debug/main.d +++ /dev/null @@ -1,12 +0,0 @@ -build/debug/main.o: src/main.cc src/../include/editor.h \ - src/../include/../libs/tree-sitter/lib/include/tree_sitter/api.h \ - src/../include/./rope.h src/../include/./ui.h src/../include/./utils.h \ - src/../include/ts.h \ - src/../libs/tree-sitter/lib/include/tree_sitter/api.h -src/../include/editor.h: -src/../include/../libs/tree-sitter/lib/include/tree_sitter/api.h: -src/../include/./rope.h: -src/../include/./ui.h: -src/../include/./utils.h: -src/../include/ts.h: -src/../libs/tree-sitter/lib/include/tree_sitter/api.h: diff --git a/build/debug/main.dwo b/build/debug/main.dwo deleted file mode 100644 index 9e84348..0000000 Binary files a/build/debug/main.dwo and /dev/null differ diff --git a/build/debug/renderer.d b/build/debug/renderer.d deleted file mode 100644 index 2f43f44..0000000 --- a/build/debug/renderer.d +++ /dev/null @@ -1,6 +0,0 @@ -build/debug/renderer.o: src/renderer.cc \ - src/../libs/libgrapheme/grapheme.h \ - src/../libs/unicode_width/unicode_width.h src/../include/ui.h -src/../libs/libgrapheme/grapheme.h: -src/../libs/unicode_width/unicode_width.h: -src/../include/ui.h: diff --git a/build/debug/renderer.dwo b/build/debug/renderer.dwo deleted file mode 100644 index d1f2c82..0000000 Binary files a/build/debug/renderer.dwo and /dev/null differ diff --git a/build/debug/rope.d b/build/debug/rope.d deleted file mode 100644 index d4d0598..0000000 --- a/build/debug/rope.d +++ /dev/null @@ -1,2 +0,0 @@ -build/debug/rope.o: src/rope.cc src/../include/rope.h -src/../include/rope.h: diff --git a/build/debug/rope.dwo b/build/debug/rope.dwo deleted file mode 100644 index 33bd675..0000000 Binary files a/build/debug/rope.dwo and /dev/null differ diff --git a/build/debug/ts.d b/build/debug/ts.d deleted file mode 100644 index 00c3c7a..0000000 --- a/build/debug/ts.d +++ /dev/null @@ -1,11 +0,0 @@ -build/debug/ts.o: src/ts.cc src/../include/ts.h src/../include/./editor.h \ - src/../include/./../libs/tree-sitter/lib/include/tree_sitter/api.h \ - src/../include/././rope.h src/../include/././ui.h \ - src/../include/././utils.h src/../include/rope.h -src/../include/ts.h: -src/../include/./editor.h: -src/../include/./../libs/tree-sitter/lib/include/tree_sitter/api.h: -src/../include/././rope.h: -src/../include/././ui.h: -src/../include/././utils.h: -src/../include/rope.h: diff --git a/build/debug/ts.dwo b/build/debug/ts.dwo deleted file mode 100644 index c0b5d24..0000000 Binary files a/build/debug/ts.dwo and /dev/null differ diff --git a/build/debug/unicode_width/unicode_width.d b/build/debug/unicode_width/unicode_width.d deleted file mode 100644 index f460fc9..0000000 --- a/build/debug/unicode_width/unicode_width.d +++ /dev/null @@ -1,3 +0,0 @@ -build/debug/unicode_width/unicode_width.o: \ - libs/unicode_width/unicode_width.c libs/unicode_width/unicode_width.h -libs/unicode_width/unicode_width.h: diff --git a/build/debug/unicode_width/unicode_width.dwo b/build/debug/unicode_width/unicode_width.dwo deleted file mode 100644 index 88f29da..0000000 Binary files a/build/debug/unicode_width/unicode_width.dwo and /dev/null differ diff --git a/build/debug/utils.d b/build/debug/utils.d deleted file mode 100644 index 222be35..0000000 --- a/build/debug/utils.d +++ /dev/null @@ -1,4 +0,0 @@ -build/debug/utils.o: src/utils.cc src/../libs/libgrapheme/grapheme.h \ - src/../include/utils.h -src/../libs/libgrapheme/grapheme.h: -src/../include/utils.h: diff --git a/build/debug/utils.dwo b/build/debug/utils.dwo deleted file mode 100644 index 16fcbf1..0000000 Binary files a/build/debug/utils.dwo and /dev/null differ diff --git a/build/release/editor.d b/build/release/editor.d deleted file mode 100644 index 7cb6e09..0000000 --- a/build/release/editor.d +++ /dev/null @@ -1,15 +0,0 @@ -build/release/editor.o: src/editor.cc src/../libs/libgrapheme/grapheme.h \ - src/../include/editor.h \ - src/../include/../libs/tree-sitter/lib/include/tree_sitter/api.h \ - src/../include/./rope.h src/../include/./ui.h src/../include/./utils.h \ - src/../include/ts.h src/../include/./editor.h \ - src/../libs/tree-sitter-ruby/bindings/c/tree-sitter-ruby.h -src/../libs/libgrapheme/grapheme.h: -src/../include/editor.h: -src/../include/../libs/tree-sitter/lib/include/tree_sitter/api.h: -src/../include/./rope.h: -src/../include/./ui.h: -src/../include/./utils.h: -src/../include/ts.h: -src/../include/./editor.h: -src/../libs/tree-sitter-ruby/bindings/c/tree-sitter-ruby.h: diff --git a/build/release/input.d b/build/release/input.d deleted file mode 100644 index 65c4661..0000000 --- a/build/release/input.d +++ /dev/null @@ -1,2 +0,0 @@ -build/release/input.o: src/input.cc src/../include/ui.h -src/../include/ui.h: diff --git a/build/release/main.d b/build/release/main.d deleted file mode 100644 index a8f40c6..0000000 --- a/build/release/main.d +++ /dev/null @@ -1,14 +0,0 @@ -build/release/main.o: src/main.cc src/../include/editor.h \ - src/../include/../libs/tree-sitter/lib/include/tree_sitter/api.h \ - src/../include/./rope.h src/../include/./ui.h src/../include/./utils.h \ - src/../include/ts.h src/../include/./editor.h src/../include/ui.h \ - src/../libs/tree-sitter/lib/include/tree_sitter/api.h -src/../include/editor.h: -src/../include/../libs/tree-sitter/lib/include/tree_sitter/api.h: -src/../include/./rope.h: -src/../include/./ui.h: -src/../include/./utils.h: -src/../include/ts.h: -src/../include/./editor.h: -src/../include/ui.h: -src/../libs/tree-sitter/lib/include/tree_sitter/api.h: diff --git a/build/release/renderer.d b/build/release/renderer.d deleted file mode 100644 index 607ea14..0000000 --- a/build/release/renderer.d +++ /dev/null @@ -1,6 +0,0 @@ -build/release/renderer.o: src/renderer.cc \ - src/../libs/libgrapheme/grapheme.h \ - src/../libs/unicode_width/unicode_width.h src/../include/ui.h -src/../libs/libgrapheme/grapheme.h: -src/../libs/unicode_width/unicode_width.h: -src/../include/ui.h: diff --git a/build/release/rope.d b/build/release/rope.d deleted file mode 100644 index c7fba23..0000000 --- a/build/release/rope.d +++ /dev/null @@ -1,2 +0,0 @@ -build/release/rope.o: src/rope.cc src/../include/rope.h -src/../include/rope.h: diff --git a/build/release/ts.d b/build/release/ts.d deleted file mode 100644 index 2654aa3..0000000 --- a/build/release/ts.d +++ /dev/null @@ -1,14 +0,0 @@ -build/release/ts.o: src/ts.cc src/../include/ts.h \ - src/../include/./editor.h \ - src/../include/./../libs/tree-sitter/lib/include/tree_sitter/api.h \ - src/../include/././rope.h src/../include/././ui.h \ - src/../include/././utils.h src/../include/editor.h \ - src/../include/rope.h -src/../include/ts.h: -src/../include/./editor.h: -src/../include/./../libs/tree-sitter/lib/include/tree_sitter/api.h: -src/../include/././rope.h: -src/../include/././ui.h: -src/../include/././utils.h: -src/../include/editor.h: -src/../include/rope.h: diff --git a/build/release/unicode_width/unicode_width.d b/build/release/unicode_width/unicode_width.d deleted file mode 100644 index 819ffce..0000000 --- a/build/release/unicode_width/unicode_width.d +++ /dev/null @@ -1,3 +0,0 @@ -build/release/unicode_width/unicode_width.o: \ - libs/unicode_width/unicode_width.c libs/unicode_width/unicode_width.h -libs/unicode_width/unicode_width.h: diff --git a/build/release/utils.d b/build/release/utils.d deleted file mode 100644 index 349d977..0000000 --- a/build/release/utils.d +++ /dev/null @@ -1,4 +0,0 @@ -build/release/utils.o: src/utils.cc src/../libs/libgrapheme/grapheme.h \ - src/../include/utils.h -src/../libs/libgrapheme/grapheme.h: -src/../include/utils.h: diff --git a/src/main.cc b/src/main.cc index a1c42cd..fa8c224 100644 --- a/src/main.cc +++ b/src/main.cc @@ -105,6 +105,7 @@ void handle_editor_event(Editor *editor, KeyEvent event) { lock_1.unlock(); std::unique_lock lock_2(editor->knot_mtx); editor->root = insert(editor->root, pos, (char *)"\n", 1); + editor->folded = (int *)calloc(editor->root->line_count + 2, sizeof(int)); lock_2.unlock(); if (editor->tree) { TSInputEdit edit = {