Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- FIFO = File.expand_path('~/.osd')
- `mkfifo "#{FIFO}"` unless test(?e, FIFO)
- require 'optparse'
- require 'ostruct'
- require 'xosd_scroll'
- def parse(args)
- options = OpenStruct.new
- options.pos = XOSD::TOP
- options.offset = 50
- options.align = XOSD::LEFT
- options.indent = 30
- options.font = "-*-terminus-medium-*-*-*-20-*-*-*-*-*-*-15"
- options.color = "black"
- options.delay = 5
- options.lines = 10
- options.shadow = 1
- options.shadowcolour = "orange"
- options.outline = 1
- options.outlinecolour = "black"
- options.age = 0
- options.wait = 0
- opts = OptionParser.new do |opts|
- opts.banner = "Usage: #$0 [options]"
- opts.separator ""
- opts.separator "Specific options:"
- opts.on("-p", "--pos POS",
- "The vertical position of the text. POS can be top, middle, or bottom. The default is top.") do |p|
- case p
- when /top/i
- options.pos = XOSD::TOP
- when /middle/i
- options.pos = XOSD::MIDDLE
- when /bottom/i
- options.pos = XOSD::BOTTOM
- end
- end
- opts.on("-o", "--offset OFFSET") do |o|
- options.offset = o.to_i
- end
- opts.on("-A", "--align ALIGN") do |a|
- case a
- when /left/i
- options.align = XOSD::LEFT
- when /center/i
- options.align = XOSD::CENTER
- when /right/i
- options.align = XOSD::RIGHT
- end
- end
- opts.on("-i", "--indent OFFSET") do |o|
- options.indent = o.to_i
- end
- opts.on("-f", "--font FONT") do |f|
- options.font = f
- end
- opts.on("-c", "--colour COLOUR") do |o|
- options.color = o
- end
- opts.on("-d", "--delay SECONDS") do |o|
- options.delay = o.to_i
- end
- opts.on("-l", "--lines LINES") do |o|
- options.lines = o.to_i
- end
- opts.on("-O", "--outline OFFSET") do |o|
- options.outline = o.to_i
- end
- opts.on("-u", "--outlinecolour OFFSET") do |o|
- options.outline_color = o
- end
- end
- opts.parse!(args)
- options
- end
- options = parse(ARGV)
- osd = XOSD::XosdScroll.new(options.lines)
- osd.position = options.pos
- osd.vertical_offset = options.offset
- osd.align = options.align
- osd.horizontal_offset = options.indent
- osd.font = options.font
- osd.color = options.color
- osd.shadow_offset = options.shadow
- osd.shadow_color = options.shadowcolour
- osd.outline_offset = options.outline
- osd.outline_color = options.outlinecolour
- osd.timeout = options.delay
- def listen_fifo(fifo_file = FIFO)
- File.open(fifo_file, File::NONBLOCK | File::RDONLY) do |fifo|
- loop do
- sleep 1
- while !fifo.eof
- yield fifo.gets("\n").strip
- end
- end
- end
- end
- listen_fifo do |fifo|
- puts fifo
- osd << fifo
- end
- osd.wait(osd.timeout)
Add Comment
Please, Sign In to add comment