Skip to content

Instantly share code, notes, and snippets.

@madx
Created December 10, 2008 16:05
Show Gist options
  • Save madx/34355 to your computer and use it in GitHub Desktop.
Save madx/34355 to your computer and use it in GitHub Desktop.
str, t = "", nil
b, bt = "", nil
c = nil
vc = 0
Shoes.app :height => 500, :width => 450 do
background rgb(77, 77, 77)
stack :margin => 10 do
para span("TEXT EDITOR", :stroke => red, :fill => white), " * USE ALT-Q TO QUIT", :stroke => white
bt = para "Select: ", :margin => 1, :font => "10px", :stroke => white
c = para "Cursors (r|v): ", :margin => 1, :font => "10px", :stroke => white
end
stack :margin => 10 do
t = para "", :font => "Monospace 12px", :stroke => white
t.cursor = 0
end
keypress do |k|
case k
when String
str += k
vc = t.cursor += 1
when :backspace
str.slice!(t.cursor - 1, 1)
vc = t.cursor -= 1
when :delete
str.slice!(t.cursor, 1)
when :tab
str += " "
when :alt_q
quit
when :alt_c
self.clipboard = b
when :alt_v
str += self.clipboard
when :left
vc = t.cursor -= 1
when :right
vc = t.cursor += 1
when :shift_left
b = "%s#{b}" % str.slice(vc - 1).chr
bt.replace "Select: #{b}"
vc -= 1
when :shift_right
b << str.slice(vc).chr
bt.replace "Select: #{b}"
vc += 1
end
t.replace str
c.replace "Cursors (r|v): #{t.cursor}|#{vc}"
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment