Class: Exfuz::Screen
- Inherits:
-
Object
- Object
- Exfuz::Screen
- Defined in:
- lib/exfuz/screen.rb
Instance Attribute Summary collapse
-
#query ⇒ Object
readonly
Returns the value of attribute query.
Instance Method Summary collapse
-
#changed_state? ⇒ Boolean
表示内容の変更検知を判定する.
- #close ⇒ Object
- #closed? ⇒ Boolean
- #delete_char ⇒ Object
- #finish ⇒ Object
- #init ⇒ Object
-
#initialize(status = nil, key_map = nil, candidates = nil) ⇒ Screen
constructor
A new instance of Screen.
- #insert_char(char) ⇒ Object
- #move_left ⇒ Object
- #move_next_page ⇒ Object
- #move_prev_page ⇒ Object
- #move_right ⇒ Object
- #refresh ⇒ Object
- #rerender ⇒ Object
-
#start_cmd ⇒ Object
event.
- #status ⇒ Object
- #wait_input ⇒ Object
Constructor Details
#initialize(status = nil, key_map = nil, candidates = nil) ⇒ Screen
Returns a new instance of Screen.
9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 |
# File 'lib/exfuz/screen.rb', line 9 def initialize(status = nil, key_map = nil, candidates = nil) @conf = Exfuz::Configuration.instance @status = status @prev_loaded = @status.loaded @key_map = key_map @prompt = '>' @query = Exfuz::Query.new([0, @prompt.size]) @cmd = Exfuz::FuzzyFinderCommand.new(command_type: @conf.fuzzy_finder_command_type) @candidates = candidates @description = Exfuz::Body.new(top: 1, bottom: 1, texts: ['please input query']) @list = Exfuz::Body.new(top: 2, bottom: 4) register_event end |
Instance Attribute Details
#query ⇒ Object (readonly)
Returns the value of attribute query.
7 8 9 |
# File 'lib/exfuz/screen.rb', line 7 def query @query end |
Instance Method Details
#changed_state? ⇒ Boolean
表示内容の変更検知を判定する
61 62 63 |
# File 'lib/exfuz/screen.rb', line 61 def changed_state? @prev_loaded < @status.loaded end |
#close ⇒ Object
69 70 71 |
# File 'lib/exfuz/screen.rb', line 69 def close Curses.close_screen end |
#closed? ⇒ Boolean
65 66 67 |
# File 'lib/exfuz/screen.rb', line 65 def closed? Curses.closed? end |
#delete_char ⇒ Object
106 107 108 109 |
# File 'lib/exfuz/screen.rb', line 106 def delete_char @query.delete refresh end |
#finish ⇒ Object
131 132 133 |
# File 'lib/exfuz/screen.rb', line 131 def finish close end |
#init ⇒ Object
30 31 32 33 34 35 36 37 38 39 40 |
# File 'lib/exfuz/screen.rb', line 30 def init Curses.init_screen # キー入力の文字を画面に反映させない Curses.noecho # 入力の待機時間(milliseconds) Curses.timeout = 100 @list.bottom = Curses.lines - @list.top + 1 draw Curses.refresh end |
#insert_char(char) ⇒ Object
135 136 137 138 |
# File 'lib/exfuz/screen.rb', line 135 def insert_char(char) @query.add(char) refresh end |
#move_left ⇒ Object
111 112 113 114 |
# File 'lib/exfuz/screen.rb', line 111 def move_left @query.left refresh end |
#move_next_page ⇒ Object
126 127 128 129 |
# File 'lib/exfuz/screen.rb', line 126 def move_next_page @list.move_next refresh end |
#move_prev_page ⇒ Object
121 122 123 124 |
# File 'lib/exfuz/screen.rb', line 121 def move_prev_page @list.move_prev refresh end |
#move_right ⇒ Object
116 117 118 119 |
# File 'lib/exfuz/screen.rb', line 116 def move_right @query.right refresh end |
#refresh ⇒ Object
47 48 49 50 |
# File 'lib/exfuz/screen.rb', line 47 def refresh draw Curses.refresh end |
#rerender ⇒ Object
42 43 44 45 |
# File 'lib/exfuz/screen.rb', line 42 def rerender @prev_loaded = @status.loaded refresh end |
#start_cmd ⇒ Object
event
74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 |
# File 'lib/exfuz/screen.rb', line 74 def start_cmd filtered = @candidates.filter({ textable: @query.text }) @cmd.run do |fiber| filtered.positions.each_with_index do |position, idx| value_text = position.textable.value.to_s line = [ idx, position.book_name.relative_path, position.sheet_name.name, position.textable.position_s(format: @conf.cell_position_format), @conf.split_new_line ? value_text : value_text.gsub(/\R+/) { '\n' } ].join(@conf.line_sep) fiber.resume(line) end end selected_positions = @cmd.selected.map do |s| idx = s.split(@conf.line_sep).first.to_i filtered.positions[idx] end if Exfuz::Util.wsl? && @conf.jump_positions? jump = Exfuz::Jump.new(selected_positions) jump.run end @list.change_all(@cmd.selected) Curses.clear init end |
#status ⇒ Object
26 27 28 |
# File 'lib/exfuz/screen.rb', line 26 def status @status.to_s end |
#wait_input ⇒ Object
52 53 54 55 56 57 58 |
# File 'lib/exfuz/screen.rb', line 52 def wait_input @ch = Curses.getch # 待機時間内に入力されない場合 return unless @ch handle_event(@ch) end |