class Flumtter::Window::Buf::Screen
Constants
- EnableKey
Public Class Methods
new(buf, title, body="")
click to toggle source
# File lib/flumtter/app/core/windows/buf_window.rb, line 91 def initialize(buf, title, body="") @title, @body = title, body @commands = [] @buf = buf @range = 0...0 end
Public Instance Methods
call(str)
click to toggle source
# File lib/flumtter/app/core/windows/buf_window.rb, line 98 def call(str) if str == "?" Window::Popup.new("Command List", <<~EOF).show #{Command.list(@commands)} EOF move(:keep) raise Dispel::Recall elsif str == :left move(:page) raise Dispel::Recall elsif str == :right raise Dispel::Recall elsif str == :up || str == :down move(str) raise Dispel::Recall else move(:keep) @commands.each do |command| if m = str.match(command.command) command.call(m) raise Dispel::Recall end end raise Dispel::NoCommandError end end
id2obj(id)
click to toggle source
# File lib/flumtter/app/core/windows/buf_window.rb, line 125 def id2obj(id) obj = @buf[id.to_i] raise IndexError if obj.nil? obj.object end
move(type)
click to toggle source
# File lib/flumtter/app/core/windows/buf_window.rb, line 131 def move(type) case type when :up @buf.cursor = @range.min - 1 when :down @buf.cursor = @range.min + 1 when :page i, count = 0, 0 begin elem = @buf[@range.min-i].element while (count += elem.size_of_lines + 2) < @lines i -= 1 elem = @buf[@range.min-i].element end @buf.cursor = @range.min+i rescue Buf::NoMoreData @buf.cursor = @buf.size - 1 end when :keep @buf.cursor = @range.min end end
show()
click to toggle source
# File lib/flumtter/app/core/windows/buf_window.rb, line 154 def show Dispel::Screen.open do |screen| Dispel::Window.open(screen.lines, screen.columns, 0, 0) do |win| win.box(?|,?-,?*) win.setpos(win.cury+2, win.curx+1) win.addstr @title.title win.setpos(win.cury+1, 1) win.addstr "¯"*(@title.title.size+2) add_multiline_str(win, @body) start = @buf.cursor begin loop do elem = @buf.get.element if (@lines = screen.lines) > win.cury + elem.size_of_lines + 4 add_multiline_str(win, elem) win.setpos(win.cury+1,1) else @buf.prev break end end rescue Buf::NoMoreData end @range = start...@buf.cursor win.setpos(win.cury+2, 1) win.addstr "help: ?".rjust(win.maxx - 2) win.setpos(win.cury+1, 1) call getstr(win, EnableKey) end end rescue Dispel::Recall show rescue Dispel::NoCommandError => e Window::Popup::Error.new(e.class.to_s).show show end