Skip to content

Commit

Permalink
reorganization
Browse files Browse the repository at this point in the history
  • Loading branch information
toothrot committed Feb 16, 2009
1 parent 7754af2 commit fa9c4ba
Show file tree
Hide file tree
Showing 5 changed files with 240 additions and 6 deletions.
7 changes: 4 additions & 3 deletions gutter.rb
Expand Up @@ -5,8 +5,9 @@
require 'httparty'
require 'yaml'
require 'htmlentities'
require 'lib/gutter'
require 'lib/gutter_ui'
require 'lib/config'
require 'lib/ui/timeline_ui'
require 'lib/ui/gutter_ui'
require 'lib/post'
require 'lib/accounts/twitter'
require 'lib/notify'
Expand All @@ -28,7 +29,7 @@
stroke white

## -- setup
@gtter = Gutter.get_conf || Gutter.new
@config = GutterConfig.get_conf || GutterConfig.new

@content = stack
get_login
Expand Down
6 changes: 3 additions & 3 deletions lib/gutter.rb → lib/config.rb
@@ -1,4 +1,4 @@
class Gutter
class GutterConfig
FILENAME = File.join("#{ENV['HOME'] || ENV['USERPROFILE'] || ENV['HOMEPATH']}",'.gutter.yml')
attr_accessor :user, :password, :ignores

Expand All @@ -7,13 +7,13 @@ def initialize
end

def save
File.open(Gutter::FILENAME, 'w') do |out|
File.open(GutterConfig::FILENAME, 'w') do |out|
YAML::dump(self, out)
end
end

def self.get_conf
YAML::load_file(Gutter::FILENAME)
YAML::load_file(GutterConfig::FILENAME)
rescue
nil
end
Expand Down
Empty file modified lib/tiny_url_support.rb 100755 → 100644
Empty file.
127 changes: 127 additions & 0 deletions lib/ui/gutter_ui.rb
@@ -0,0 +1,127 @@
require 'hpricot'
module GutterUI
include TimelineUI

def gray_button(text, click_proc)
stack :width => 40, :margin_left => 4, :margin_right => 4, :scroll => false, :height => 15 do
dark = rect(:width => 30, :height => 14, :curve => 4,
:fill => gray(0.3), :stroke => gray(0.6))
light = rect(:width => 30, :height => 14, :curve => 4,
:fill => gray(0.3), :stroke => gray(0.9))
light.hide
inscription text, :font => '9', :stroke => gray(0.8), :margin_top => 0
dark.click { click_proc.call }
dark.hover { light.show }
dark.leave { light.hide }
end
end

def get_login
@content.clear do
@login = stack(:width => 290, :margin => [40,40,0,0]) do
background gray(0.2), :curve => 10
border gray(0.6), :curve => 10
failed = para('', :stroke => red).hide
logo = image "http://assets1.twitter.com/images/twitter_logo_s.png"
stack :margin => [20]*4 do
user_input = edit_line(:text => @config.user)
password_input = edit_line(:secret => true, :text => @config.password)
button "Log In" do
@config.user = user_input.text
@config.password = password_input.text
@config.save
if get_auth.authorized
ui_start
else
failed.text = 'Failed...'
failed.show
end
end
end
end
end
end

def get_auth
@user = @config.user
@twit = TwitterAccount.new(
:user => @config.user, :password => @config.password)
end

def draw_settings
@content.clear do
stack(:margin => [4]*4) do
background gray(0.2), :curve => 10
border gray(0.6), :curve => 10
tagline "Settings", :stroke => white
get_login
stack(:margin => [8]*4) do
para 'Ignore: ', :stroke => white
flow do
list_box(:items => @twit.friends.map(&:name), :margin_left => 10) do |friend_name|
@config.ignores << friend_name.text
@ignores.text = @config.ignores.join(", ")
end
button("clear") { @config.ignores = []; @ignores.text = "" }
end
@ignores = para(@config.ignores.join(", "), :stroke => white, :margin_left => 10)
button("Go Back") { @config.save; ui_start }
end
end
end
end

def ui_start
@content.clear do
background black
stroke white

send_tweet = lambda do
@twit.post(tinify_urls_in_text(@tweet_text.text))
@tweet_text.text = ''
timer(5) { @timeline.clear { draw_timeline } }
end

@timeline = stack :margin_top => 50 do
displace(0, -8)
para "loading"
end

#header
flow(:attach => Window, :top => 0, :left => 0, :height => 42, :margin_right => gutter) do
background gray(0.2, 0.8)
border dimgray
flow :margin => [5,5,5,0] do

# Input
@tweet_text = edit_line("", :width => width - 140 - gutter) do |e|
@counter.text = 140 - (e.text.size || 0)
end

# blag/counter
stack :width => 40 do
@blag = gray_button('blag', send_tweet)
@counter = strong("140")
inscription @counter, :stroke => white, :margin => [8,0,0,0]
end
para "| ", :stroke => gray

# controls
image('http://toothrot.nfshost.com/gutter/icons/arrow_refresh.png', :click => lambda { @timeline.clear { draw_timeline } }, :margin => [5,5,5,5] )
image('http://toothrot.nfshost.com/gutter/icons/cog.png', :click => lambda { @timeline.clear { draw_settings } }, :margin => [5,5,5,5] )
end
end # - header

keypress do |k|
send_tweet.call if (k == :enter) || (k == "\n")
@timeline.scroll_top -= 50 if k == :up
@timeline.scroll_top += 50 if k == :down
end

@timeline.clear { draw_timeline }
every(60*6) do
@timeline.clear { draw_timeline }
end
end
end
end
106 changes: 106 additions & 0 deletions lib/ui/timeline_ui.rb
@@ -0,0 +1,106 @@
module TimelineUI
def do_twitpic(url)
window(:title => 'twitpic') do
background black
@loading = title 'Loading...', :stroke => white
download url do |dump|
image("http://twitpic.com/#{Hpricot(dump.response.body).at('#pic').get_attribute('src')}")
@loading.remove
end
end
end

def link_to_profile(reply_to_user)
user_id = reply_to_user.delete("@:")
link(reply_to_user, :underline => 'none').click("http://twitter.com/#{user_id}")
end

def reply(status)
@tweet_text.text = "@#{status.user.screen_name} "
end

def insert_links(str)
decoded = HTMLEntities.new.decode(str)

decoded.split.inject([]) do |a,e|
result = if(e =~ %r[https?://twitpic.com.*])
link(e) { do_twitpic(e.delete(',')) }
elsif(e =~ %r[https?://\S*])
link(e, :click => e)
elsif(e =~ %r[@\w])
link_to_profile(e)
else
e
end
a << result
a << ' '
end
end

def status_background(status)
if status.text =~ %r[@#{@user}]
background '#303030', :curve => 10
border gray, :curve => 10, :strokewidth => 2
else
background '#202020', :curve => 10
border (status.user.screen_name == @user) ? darkslateblue : '#303030', :curve => 10, :strokewidth => 2
end
end

def status_image(status)
stack :width => 50, :margin => [6,6,2,6] do
image status.user.image_url if status.user
end
end

def status_time(status)
Time.parse(status.created_at).strftime("at %I:%M%p").downcase.chop
end

def status_text(status)
stack :width => -77 do
flow do
para(status.user.name, :stroke => darkorange, :margin => [10,5,5,0], :font => 'Coolvetica')
inscription(status_time(status), :stroke => gray, :margin => [10,8,0,0])
end
inscription(insert_links(status.text), ' ', :margin => [10,0,0,6], :stroke => white, :leading => 0)
end
end

def status_controls(status)
stack :width => 22, :margin => [7,5,7,5] do
image('http://toothrot.nfshost.com/gutter/icons/arrow_undo.png',
:click => lambda { reply(status) })
end
end

def draw_timeline
statuses = @twit.timeline(:friends)
notify(@which,statuses)
statuses.each do |status|
unless @config.ignores.include? status.user.name
tweet = flow :margin => [5,4,gutter + 5,4] do
status_background(status)
status_image(status)
status_text(status)
control = status_controls(status)
end # end tweet
end
end # end twit
end

def gray_button(text, click_proc)
stack :width => 40, :margin_left => 4, :margin_right => 4, :scroll => false, :height => 15 do
dark = rect(:width => 30, :height => 14, :curve => 4,
:fill => gray(0.3), :stroke => gray(0.6))
light = rect(:width => 30, :height => 14, :curve => 4,
:fill => gray(0.3), :stroke => gray(0.9))
light.hide
inscription text, :font => '9', :stroke => gray(0.8), :margin_top => 0
dark.click { click_proc.call }
dark.hover { light.show }
dark.leave { light.hide }
end
end

end

0 comments on commit fa9c4ba

Please sign in to comment.