Skip to content

Commit 5d44c8b

Browse files
committed
Merge pull request #11 from Expez/ui
Merge initial UI roughout
2 parents f14e2e3 + fbbb674 commit 5d44c8b

File tree

17 files changed

+399
-41
lines changed

17 files changed

+399
-41
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
.rbx

.rvmrc

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
# First we specify our desired <ruby>[@<gemset>], the @gemset name is optional,
77
# Only full ruby name is supported here, for short names use:
88
# echo "rvm use 1.9.3" > .rvmrc
9-
environment_id="ruby-1.9.3-p374@hatter"
9+
environment_id="rbx-head@hatter"
1010

1111
# Uncomment the following lines if you want to verify rvm version per project
1212
# rvmrc_rvm_version="1.18.3 (stable)" # 1.10.1 seams as a safe start
@@ -46,3 +46,6 @@ fi
4646
# then
4747
# bundle install | GREP_OPTIONS= \grep -vE '^Using|Your bundle is complete'
4848
# fi
49+
50+
DIR=$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )
51+
export RUBYLIB="$DIR/lib"

Gemfile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ group :development, :test do
55
gem 'pry'
66
gem 'rake'
77
gem 'mail'
8-
gem 'rbcurse'
8+
gem 'rb_termbox'
99
gem 'configtoolkit'
1010
end
1111

Gemfile.lock

Lines changed: 3 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -14,11 +14,6 @@ GEM
1414
diff-lcs (1.1.3)
1515
ffi (1.3.1)
1616
ffi (1.3.1-x86-mingw32)
17-
ffi-locale (1.0.1)
18-
ffi (>= 1.0.9)
19-
ffi-ncurses (0.4.0)
20-
ffi (>= 1.0.9)
21-
ffi-locale (>= 1.0.0)
2217
i18n (0.6.1)
2318
mail (2.5.3)
2419
i18n (>= 0.4.0)
@@ -37,13 +32,8 @@ GEM
3732
slop (~> 3.4)
3833
win32console (~> 1.3)
3934
rake (10.0.3)
40-
rbcurse (1.5.2)
41-
rbcurse-core (>= 0.0)
42-
rbcurse-extras (>= 0.0)
43-
rbcurse-core (0.0.3)
44-
ffi-ncurses (>= 0.4.0)
45-
rbcurse-extras (0.0.0)
46-
rbcurse-core (>= 0.0.3)
35+
rb_termbox (0.1.0)
36+
ffi
4737
relative (1.0.3)
4838
rspec (2.12.0)
4939
rspec-core (~> 2.12.0)
@@ -69,5 +59,5 @@ DEPENDENCIES
6959
mail
7060
pry
7161
rake
72-
rbcurse
62+
rb_termbox
7363
rspec

.hatterrc renamed to hatterrc

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,3 +8,9 @@ maildir = /path/to/maildir
88

99
# The format of the maildir, e.g maildir or mbox
1010
maildir_format = maildir
11+
12+
# Hatter relies on Termbox for the terminal UI
13+
termbox_library_path = /usr/lib/libtermbox.so
14+
15+
# All the colors i Hatter can be customized:
16+
colors = {foreground => green, background => black}

lib/configuration.rb

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,25 @@
11
require 'configtoolkit'
22
require 'configtoolkit/keyvaluereader'
3+
require 'relative'
34

45
class Configuration < ConfigToolkit::BaseConfig
56

6-
# Reads a configuration from file.
7-
#
8-
# @param [String] configPath the path to a configuration file.
9-
#
10-
# @return [Configuration] with values loaded from file.
11-
def self.from_file configPath
12-
reader = ConfigToolkit::KeyValueReader.new configPath
7+
include Singleton
8+
9+
CONFIG_FILE = File.expand_path_relative_to_caller("../hatterrc")
10+
11+
def initialize(config_file = CONFIG_FILE)
12+
reader = ConfigToolkit::KeyValueReader.new config_file
1313
load reader
1414
end
1515

16+
class Colors < ConfigToolkit::BaseConfig
17+
add_required_param(:foreground, String)
18+
add_required_param(:background, String)
19+
end
20+
1621
add_required_param(:maildir, String)
1722
add_required_param(:maildir_format, String)
23+
add_required_param(:termbox_library_path, String)
24+
add_required_param(:colors, Colors)
1825
end

lib/hatter.rb

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1 +1,9 @@
1+
require 'terminal'
12

3+
terminal = Terminal.new
4+
begin
5+
terminal.draw
6+
sleep(10)
7+
ensure
8+
terminal.shutdown
9+
end

lib/mailbox/maildir_mailbox.rb

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
require 'mail'
2+
3+
class MaildirMailbox
4+
5+
def initialize(maildir_path)
6+
@maildir_path = maildir_path
7+
@maildir_path = "spec/fixtures/maildir"
8+
end
9+
10+
def mail(where={label: nil, folder: nil, from: nil, to: nil, date: nil})
11+
Mail.read(@maildir_path + "/INBOX/cur/TRAIN_00001.eml")
12+
end
13+
14+
def most_recent
15+
mail
16+
end
17+
18+
def labels
19+
["work", "cat pictures", "news"]
20+
end
21+
22+
def folders
23+
%w{ inbox archived spam trash }
24+
end
25+
end

lib/terminal.rb

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
require 'termbox'
2+
require 'views/mail_view'
3+
require 'views/label_view'
4+
require 'views/folder_view'
5+
6+
module Termbox
7+
TB_INPUT_ESCAPE = 1
8+
TB_INPUT_ALT = 2
9+
end
10+
11+
class Terminal
12+
13+
def initialize
14+
initialize_termbox
15+
initialize_views
16+
end
17+
18+
def draw
19+
Termbox.tb_clear
20+
@views.each {|view| view.draw}
21+
Termbox.tb_present
22+
end
23+
24+
def shutdown
25+
Termbox.tb_shutdown
26+
end
27+
28+
private
29+
30+
def initialize_views
31+
folder_view_location = {x0: 0, y0: 0, x1: 19, y1: 40}
32+
label_view_location = {x0: 0, y0: 41, x1: 19, y1: 79}
33+
mail_view_location = {x0: 20, y0: 0, x1: 79, y1: 79}
34+
@views = [MailView.new(mail_view_location),
35+
LabelView.new(label_view_location),
36+
FolderView.new(folder_view_location)]
37+
end
38+
39+
def initialize_termbox
40+
libtermbox_path = Configuration.instance.termbox_library_path
41+
Termbox.initialize_library libtermbox_path
42+
unless Termbox.tb_init
43+
raise "Failed failed to start UI"
44+
end
45+
@event = Termbox::Event.new
46+
Termbox.tb_select_input_mode Termbox::TB_INPUT_ESCAPE
47+
end
48+
49+
end

lib/views/folder_view.rb

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
class FolderView < View
2+
3+
def draw
4+
draw_folders
5+
draw_horizontal_line @end_y
6+
end
7+
8+
private
9+
10+
def draw_folders
11+
x = @start_x
12+
y = @start_y
13+
y = draw_text("Folders:", x, y)
14+
@mailbox.folders.each do |folder|
15+
y = draw_text folder, x, y + 1
16+
end
17+
end
18+
end

0 commit comments

Comments
 (0)