This commit is contained in:
Jorge Morante 2023-04-13 14:11:51 +02:00
parent 626ad26e43
commit 9a9a1bddcb
3 changed files with 20 additions and 10 deletions

View File

@ -116,7 +116,7 @@ module Fingers::Commands
Fingers::Hinter.new(
input: tmux.capture_pane(target_pane.pane_id),
width: target_pane.pane_width.to_i,
# state: state,
state: state,
output: pane_printer
)
end

View File

@ -16,7 +16,7 @@ module Fingers
def initialize(
input : String,
width : Int32,
# state,
state : Fingers::State,
output : Printer,
patterns = Fingers.config.patterns,
alphabet = Fingers.config.alphabet,
@ -27,7 +27,7 @@ module Fingers
@width = width
@hints_by_text = {} of String => String
@lookup_table = {} of String => String
# @state = state
@state = state
@output = output
@formatter = formatter
@huffman = huffman
@ -60,7 +60,7 @@ module Fingers
:input,
:lookup_table,
:width,
# :state,
:state,
:formatter,
:huffman,
:output,
@ -109,12 +109,10 @@ module Fingers
hints_by_text[captured_text] = hint
end
# TODO: this should be output hint without ansi escape sequences
formatter.format(
hint: hint,
highlight: text,
# selected: state.selected_hints.include?(hint),
selected: false,
selected: state.selected_hints.includes?(hint),
offset: capture_offset
)
end

View File

@ -33,11 +33,12 @@ module Fingers
case command
when "hint"
char, modifier = args
hint(char, modifier)
process_hint(char, modifier)
when "exit"
request_exit!
when "toggle-help"
when "toggle-toggle-multi-mode"
when "toggle-multi-mode"
process_multimode
when "fzf"
# soon
end
@ -60,7 +61,7 @@ module Fingers
output.print CLEAR_SEQ
end
private def hint(char, modifier)
private def process_hint(char, modifier)
state.input += char
state.modifier = modifier
match = hinter.lookup(state.input)
@ -70,6 +71,17 @@ module Fingers
handle_match(match) if match
end
private def process_multimode
prev_state = state.multi_mode
state.multi_mode = !state.multi_mode
current_state = state.multi_mode
if prev_state == true && current_state == false
state.result = state.multi_matches.join(' ')
request_exit!
end
end
private getter :output, :hinter, :original_pane, :state
private def handle_match(match)