lib/scryglass/lens_panel.rb in scryglass-1.1.0 vs lib/scryglass/lens_panel.rb in scryglass-2.0.0

- old
+ new

@@ -49,33 +49,34 @@ split_lines = uncut_body_string.split("\n") ## Here we cut down the (rectangular) display array in both dimensions (into a smaller rectangle), as needed, to fit the view. sliced_lines = split_lines.map do |string| - ansi_length = string.length - string.ansiless_length # Escape codes make `length` different from display length! - slice_length = screen_width + ansi_length - string[current_view_coords[:x], slice_length] || '' # If I don't want to - # opacify here, I need to account for nils when the view is fully - # beyond the shorter lines. + string.ansi_slice(current_view_coords[:x], screen_width) || '' # If I + # don't want to opacify here, I need to account for nils when the view + # is fully beyond the shorter lines. end sliced_list = sliced_lines[current_view_coords[:y], non_header_view_size] - sliced_list.join("\n") + sliced_list end def recalculate_y_boundaries - self.y_boundaries = 0...(uncut_body_string.count("\n") + 1) + number_of_lines = uncut_body_string.count("\n") + 1 + preview_row = 1 + self.y_boundaries = 0...(number_of_lines + preview_row) end def recalculate_x_boundaries _screen_height, screen_width = $stdout.winsize split_lines = uncut_body_string.split("\n") - length_of_longest_line = split_lines.map(&:length).max || 0 + length_of_longest_line = split_lines.map(&:ansiless_length).max || 0 max_line_length = [length_of_longest_line, screen_width].max + preview_column = 1 - self.x_boundaries = 0...max_line_length + self.x_boundaries = 0...(max_line_length + preview_column) end def current_ro_subheader current_ro = scry_session.current_ro last_keypress = scry_session.last_keypress @@ -83,14 +84,33 @@ row_above_string = current_ro.next_visible_ro_up.to_s if current_ro.next_visible_ro_up row_below_string = current_ro.next_visible_ro_down.to_s if current_ro.next_visible_ro_down - tree_preview_related_commands = ['A', 'B', 'C', 'D', - '@', '.', '(', '*', '|', '-'] + tree_preview_related_keys = ::Scryglass::Session::KEY_MAP.slice( + :move_cursor_up, + :move_cursor_down, + :homerow_move_cursor_up, + :homerow_move_cursor_down, + :homerow_move_cursor_up_fast, + :homerow_move_cursor_down_fast, + :open_bucket, + :close_bucket, + :homerow_open_bucket, + :homerow_close_bucket, + :build_instance_variables, + :build_ar_relations, + :build_enum_children, + :smart_open, + :select_siblings, + :select_all, + :select_current, + :continue_search, + ).values + ro_view_label = - if tree_preview_related_commands.include?(last_keypress) + if tree_preview_related_keys.include?(last_keypress) "\e[7mVIEWING:\e[00m" # Color reversed else 'VIEWING:' end @@ -107,33 +127,37 @@ current_lens = scry_session.current_lens current_subject_type = scry_session.current_subject_type current_subject = scry_session.current_ro.current_subject last_keypress = scry_session.last_keypress + key_map = ::Scryglass::Session::KEY_MAP lens_count = LensPanel.lenses.count lens_id = current_lens % lens_count lens = LensPanel.lenses[lens_id] longest_lens_name_length = LensPanel.lenses.map do |lens| lens[:name].length end.max - lens_type_header_length = 9 + (lens_count.to_s.length * 2) + lens_type_header_length = 13 + (lens_count.to_s.length * 2) + longest_lens_name_length - subject_type_header = "SUBJECT: #{current_subject_type}".ljust(14, ' ') + subject_type_header = "[<] SUBJECT: #{current_subject_type}".ljust(18, ' ') subject_class_header = " CLASS: #{current_subject.class}" - lens_type_header = " LENS #{lens_id + 1}/#{lens_count}: #{lens[:name]}" + lens_type_header = " [>] LENS #{lens_id + 1}/#{lens_count}: #{lens[:name]}" .ljust(lens_type_header_length, ' ') + user_just_switched_lens = last_keypress == key_map[:switch_lens] + user_just_switched_subject_type = last_keypress == key_map[:switch_subject_type] + + if user_just_switched_lens + lens_type_header = "\e[7m#{lens_type_header}\e[00m" # Color reversed + elsif user_just_switched_subject_type + subject_type_header = "\e[7m#{subject_type_header}\e[00m" # Color reversed + end + fit_lens_header = [ subject_type_header, subject_class_header, lens_type_header ].fit_to(screen_width) - - if last_keypress == 'l' - fit_lens_header[4] = "\e[7m#{fit_lens_header[4]}" # Format to be ended by Hexes.opacify_screen_string() (using \e[00m) - elsif last_keypress == 'L' - fit_lens_header[0] = "\e[7m#{fit_lens_header[0]}\e[00m" - end fit_lens_header.join('') end end end