Other rxvt font selector

It is bit complicated to get the parameters right for terminal fonts, so I wrote small ruby script.

Save as font.rb, give it +x flag, execute in urxvt.

Code:
#!/usr/bin/env ruby

require 'io/console'

fontsraw = `fc-list :mono family style | sort`.split("\n")
$fonts = []
fontsraw.each do |fontraw|
  font = fontraw.split(":")
  family = font[0].split(",")
  style  = font[1].split(",")
  $fonts.push([family[0],style[0]])
end

puts "-----------------------------------------------------------------------------"
puts "[Q = Quit]  [Left,Right = Select Font]  [Up,Down = Select Size] [Enter = Set]"
puts "-----------------------------------------------------------------------------"

$setfontindex = -1
$fontindex = 0
$setfontsize = -1
$fontsize = 12

def buildXFT()
  return "xft:" + $fonts[$fontindex][0] + ":" + $fonts[$fontindex][1] + ":pixelsize=" + $fontsize.to_s
end

def showStat()
  print "\e[200D"
  if (($setfontindex != $fontindex) || ($setfontsize != $fontsize)) then
    print "[*]  "
  end
  print buildXFT
  print "\e[K"
end

showStat

while ((ch = STDIN.getch) != "q") do
  if (ch == "\e") then
    ch = ch + STDIN.getch
    ch = ch + STDIN.getch
  end
  if (ch == "\e[D") then
    $fontindex = [$fontindex - 1, 0].max
  end
  if (ch == "\e[C") then
    $fontindex = [$fontindex + 1, $fonts.size - 1].min
  end
  if (ch == "\e[B") then
    $fontsize = [$fontsize - 1, 6].max
  end
  if (ch == "\e[A") then
    $fontsize = [$fontsize + 1, 40].min
  end
  if (ch == "\r") then
    $setfontindex = $fontindex
    $setfontsize = $fontsize
    print "\e]710;" + buildXFT + "\007"
  end
  showStat
end
 
Back
Top