lessの実装
Posted feedbacks - Ruby
環境に依存するかもしれませんが、書いてみました。
Gentoo Linuxで動作確認してます。
% ruby -v
ruby 1.8.6 (2008-06-20 patchlevel 230) [i686-linux]
less準拠でjk/qが使えます。
Gentoo Linuxで動作確認してます。
% ruby -v
ruby 1.8.6 (2008-06-20 patchlevel 230) [i686-linux]
less準拠でjk/qが使えます。
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 | #!/usr/bin/env ruby
require 'curses'
lines = ARGF.readlines
index = 0
LINES = 10
Curses::init_screen
def update(index, lines)
(index..index+LINES).each do |l|
Curses::stdscr.setpos(l - index, 0)
Curses::addstr lines[l]
end
end
def search(index, lines)
word = ''
while (ch = Curses::getch) != 0x0A do
word += ch.chr
end
(index..(lines.size)).each do |l|
if lines[l].match(word) then
return l
end
end
return nil
end
update(index, lines)
while ch = Curses::getch do
case ch
when ?j
index += 1 if index < lines.length - LINES
when ?k
index -= 1 if 0 < index
when ?/
index = search(index, lines) || index
when ?q
break
end
update(index, lines)
end
|

takeru #6817() Rating-7/7=-1.00
'less'を実装してください。
巨大なファイルでも効率的に動作するようにしてください。
最低限必要な機能は、
です。
[ reply ]