tiqbi 0.0.1 → 0.0.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/README.md +4 -0
- data/lib/tiqbi.rb +10 -7
- data/lib/tiqbi/qiita.rb +26 -0
- data/lib/tiqbi/version.rb +1 -1
- data/lib/tiqbi/{window → view}/base.rb +3 -3
- data/lib/tiqbi/{window → view}/collection.rb +1 -1
- data/lib/tiqbi/{window/command_window.rb → view/command_view.rb} +3 -3
- data/lib/tiqbi/{window → view}/cursor.rb +1 -1
- data/lib/tiqbi/{window/detail_window.rb → view/detail_view.rb} +3 -3
- data/lib/tiqbi/{window/main_window.rb → view/main_view.rb} +3 -3
- data/lib/tiqbi/view_controller.rb +94 -0
- data/tiqbi.gemspec +1 -0
- metadata +26 -9
- data/lib/tiqbi/view.rb +0 -93
data/README.md
CHANGED
data/lib/tiqbi.rb
CHANGED
@@ -3,16 +3,16 @@
|
|
3
3
|
require 'logger'
|
4
4
|
require 'curses'
|
5
5
|
require 'sanitize'
|
6
|
-
require '
|
6
|
+
require 'active_support/cache'
|
7
7
|
|
8
8
|
require 'tiqbi/version'
|
9
9
|
require 'tiqbi/utils'
|
10
|
-
require 'tiqbi/
|
10
|
+
require 'tiqbi/view_controller'
|
11
11
|
|
12
12
|
module Tiqbi
|
13
13
|
extend self
|
14
14
|
extend Utils
|
15
|
-
attr_accessor :
|
15
|
+
attr_accessor :view_controller, :options
|
16
16
|
|
17
17
|
F_YELLOW_B_BLACK = 1
|
18
18
|
F_RED_B_BLACK = 2
|
@@ -22,15 +22,14 @@ module Tiqbi
|
|
22
22
|
# initialize console
|
23
23
|
self.options = options
|
24
24
|
configure_curses
|
25
|
-
# get default window
|
26
25
|
curses_screen = Curses.stdscr
|
27
|
-
self.
|
26
|
+
self.view_controller = ViewController.new(curses_screen)
|
28
27
|
|
29
28
|
# event loop
|
30
29
|
begin
|
31
30
|
loop {
|
32
|
-
ch =
|
33
|
-
|
31
|
+
ch = view_controller.current_view.getch
|
32
|
+
view_controller.on_input(ch)
|
34
33
|
}
|
35
34
|
ensure
|
36
35
|
Curses.close_screen
|
@@ -41,6 +40,10 @@ module Tiqbi
|
|
41
40
|
Pathname.new(File.dirname(__FILE__)).join("..")
|
42
41
|
end
|
43
42
|
|
43
|
+
def cache
|
44
|
+
@cache ||= ActiveSupport::Cache::MemoryStore.new
|
45
|
+
end
|
46
|
+
|
44
47
|
def logger
|
45
48
|
@logger ||= Logger.new root.join('logs/app.log')
|
46
49
|
end
|
data/lib/tiqbi/qiita.rb
ADDED
@@ -0,0 +1,26 @@
|
|
1
|
+
# -*- coding: utf-8 -*-
|
2
|
+
require 'qiita'
|
3
|
+
|
4
|
+
module Tiqbi
|
5
|
+
module Qiita
|
6
|
+
extend self
|
7
|
+
|
8
|
+
def get(method, *args)
|
9
|
+
cache_key = "#{method}_#{args.join('_')}"
|
10
|
+
unless Tiqbi.cache.exist?(cache_key)
|
11
|
+
data = ::Qiita.send(method, *args) rescue nil
|
12
|
+
Tiqbi.cache.write(cache_key, data.dup) if data
|
13
|
+
else
|
14
|
+
data = Tiqbi.cache.read(cache_key).dup
|
15
|
+
end
|
16
|
+
data
|
17
|
+
end
|
18
|
+
|
19
|
+
def items
|
20
|
+
get(:item, "") || []
|
21
|
+
end
|
22
|
+
def item(uuid)
|
23
|
+
get(:item, uuid) || {}
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
data/lib/tiqbi/version.rb
CHANGED
@@ -1,11 +1,11 @@
|
|
1
1
|
# -*- coding: utf-8 -*-
|
2
2
|
|
3
3
|
require 'forwardable'
|
4
|
-
require 'tiqbi/
|
5
|
-
require 'tiqbi/
|
4
|
+
require 'tiqbi/view/collection'
|
5
|
+
require 'tiqbi/view/cursor'
|
6
6
|
|
7
7
|
module Tiqbi
|
8
|
-
module
|
8
|
+
module View
|
9
9
|
class Base
|
10
10
|
attr_accessor :c_window, :cursor, :top_statement
|
11
11
|
attr_reader :collection
|
@@ -0,0 +1,94 @@
|
|
1
|
+
# -*- coding: utf-8 -*-
|
2
|
+
|
3
|
+
require 'tiqbi/qiita'
|
4
|
+
require 'tiqbi/view/main_view'
|
5
|
+
require 'tiqbi/view/detail_view'
|
6
|
+
require 'tiqbi/view/command_view'
|
7
|
+
|
8
|
+
module Tiqbi
|
9
|
+
class ViewController
|
10
|
+
MAIN_VIEW = 1
|
11
|
+
DETAIL_VIEW = 2
|
12
|
+
COMMAND_VIEW = 3
|
13
|
+
|
14
|
+
include Utils
|
15
|
+
attr_accessor :views
|
16
|
+
|
17
|
+
def initialize(c_scr)
|
18
|
+
# calc size
|
19
|
+
scr_x = c_scr.maxx - c_scr.begx
|
20
|
+
scr_y = c_scr.maxy - c_scr.begy
|
21
|
+
main_h = scr_y / 2
|
22
|
+
cmd_h = 1
|
23
|
+
detail_h = main_h - cmd_h
|
24
|
+
# initialize all views
|
25
|
+
@views = {
|
26
|
+
MAIN_VIEW => View::MainView.new(c_scr, main_h, scr_x, 0, 0),
|
27
|
+
DETAIL_VIEW => View::DetailView.new(c_scr, detail_h, scr_x, main_h, 0),
|
28
|
+
COMMAND_VIEW => View::CommandView.new(c_scr, cmd_h, scr_x, main_h + detail_h, 0)
|
29
|
+
}
|
30
|
+
|
31
|
+
items = Qiita.items
|
32
|
+
@views[MAIN_VIEW].collection = items
|
33
|
+
@views[MAIN_VIEW].print
|
34
|
+
end
|
35
|
+
|
36
|
+
def on_input(input)
|
37
|
+
case input
|
38
|
+
when ?j
|
39
|
+
current_view.cursor_down
|
40
|
+
when ?k
|
41
|
+
current_view.cursor_up
|
42
|
+
when 10
|
43
|
+
if current_view == view(MAIN_VIEW)
|
44
|
+
index = current_view.cursor.y
|
45
|
+
item = current_view.collection.at(index)
|
46
|
+
return unless item
|
47
|
+
item_detail = Qiita.item(item.uuid)
|
48
|
+
view(DETAIL_VIEW).item_loaded item_detail
|
49
|
+
switch_to_next_view view(DETAIL_VIEW)
|
50
|
+
end
|
51
|
+
when ?q
|
52
|
+
switch_to_previous_view
|
53
|
+
end
|
54
|
+
end
|
55
|
+
|
56
|
+
def view(view_id)
|
57
|
+
views[view_id]
|
58
|
+
end
|
59
|
+
|
60
|
+
def current_view
|
61
|
+
@current_view ||= view(MAIN_VIEW)
|
62
|
+
end
|
63
|
+
|
64
|
+
def current_view=(v)
|
65
|
+
@current_view = v
|
66
|
+
end
|
67
|
+
|
68
|
+
def view_history
|
69
|
+
@view_history ||= []
|
70
|
+
end
|
71
|
+
|
72
|
+
def switch_to_next_view(v)
|
73
|
+
view_history << current_view
|
74
|
+
self.current_view = v
|
75
|
+
switch_to(current_view)
|
76
|
+
end
|
77
|
+
|
78
|
+
def switch_to_previous_view
|
79
|
+
previous_view = view_history.shift
|
80
|
+
unless previous_view
|
81
|
+
exit
|
82
|
+
else
|
83
|
+
current_view.virtual_close
|
84
|
+
switch_to(previous_view)
|
85
|
+
end
|
86
|
+
end
|
87
|
+
|
88
|
+
def switch_to(v)
|
89
|
+
self.current_view = v
|
90
|
+
v.setpos(v.cursor.y, v.cursor.x)
|
91
|
+
v.refresh
|
92
|
+
end
|
93
|
+
end
|
94
|
+
end
|
data/tiqbi.gemspec
CHANGED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: tiqbi
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.2
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2012-10-
|
12
|
+
date: 2012-10-20 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: slop
|
@@ -27,6 +27,22 @@ dependencies:
|
|
27
27
|
- - ! '>='
|
28
28
|
- !ruby/object:Gem::Version
|
29
29
|
version: '0'
|
30
|
+
- !ruby/object:Gem::Dependency
|
31
|
+
name: activesupport
|
32
|
+
requirement: !ruby/object:Gem::Requirement
|
33
|
+
none: false
|
34
|
+
requirements:
|
35
|
+
- - ! '>='
|
36
|
+
- !ruby/object:Gem::Version
|
37
|
+
version: '0'
|
38
|
+
type: :runtime
|
39
|
+
prerelease: false
|
40
|
+
version_requirements: !ruby/object:Gem::Requirement
|
41
|
+
none: false
|
42
|
+
requirements:
|
43
|
+
- - ! '>='
|
44
|
+
- !ruby/object:Gem::Version
|
45
|
+
version: '0'
|
30
46
|
- !ruby/object:Gem::Dependency
|
31
47
|
name: qiita
|
32
48
|
requirement: !ruby/object:Gem::Requirement
|
@@ -75,15 +91,16 @@ files:
|
|
75
91
|
- bin/tiqbi
|
76
92
|
- cache/.gitkeep
|
77
93
|
- lib/tiqbi.rb
|
94
|
+
- lib/tiqbi/qiita.rb
|
78
95
|
- lib/tiqbi/utils.rb
|
79
96
|
- lib/tiqbi/version.rb
|
80
|
-
- lib/tiqbi/view.rb
|
81
|
-
- lib/tiqbi/
|
82
|
-
- lib/tiqbi/
|
83
|
-
- lib/tiqbi/
|
84
|
-
- lib/tiqbi/
|
85
|
-
- lib/tiqbi/
|
86
|
-
- lib/tiqbi/
|
97
|
+
- lib/tiqbi/view/base.rb
|
98
|
+
- lib/tiqbi/view/collection.rb
|
99
|
+
- lib/tiqbi/view/command_view.rb
|
100
|
+
- lib/tiqbi/view/cursor.rb
|
101
|
+
- lib/tiqbi/view/detail_view.rb
|
102
|
+
- lib/tiqbi/view/main_view.rb
|
103
|
+
- lib/tiqbi/view_controller.rb
|
87
104
|
- tiqbi.gemspec
|
88
105
|
homepage: https://github.com/ToQoz/tiqbi
|
89
106
|
licenses: []
|
data/lib/tiqbi/view.rb
DELETED
@@ -1,93 +0,0 @@
|
|
1
|
-
# -*- coding: utf-8 -*-
|
2
|
-
|
3
|
-
require 'tiqbi/window/main_window'
|
4
|
-
require 'tiqbi/window/detail_window'
|
5
|
-
require 'tiqbi/window/command_window'
|
6
|
-
|
7
|
-
module Tiqbi
|
8
|
-
class View
|
9
|
-
MAIN_WINDOW = 1
|
10
|
-
DETAIL_WINDOW = 2
|
11
|
-
COMMAND_WINDOW = 3
|
12
|
-
|
13
|
-
include Utils
|
14
|
-
attr_accessor :windows
|
15
|
-
|
16
|
-
def initialize(c_screen)
|
17
|
-
# calc size
|
18
|
-
scr_x = c_screen.maxx - c_screen.begx
|
19
|
-
scr_y = c_screen.maxy - c_screen.begy
|
20
|
-
main_h = scr_y / 2
|
21
|
-
cmd_h = 1
|
22
|
-
detail_h = main_h - cmd_h
|
23
|
-
# initialize all windows
|
24
|
-
@windows = {
|
25
|
-
MAIN_WINDOW => Window::MainWindow.new(c_screen, main_h, scr_x, 0, 0),
|
26
|
-
DETAIL_WINDOW => Window::DetailWindow.new(c_screen, detail_h, scr_x, main_h, 0),
|
27
|
-
COMMAND_WINDOW => Window::CommandWindow.new(c_screen, cmd_h, scr_x, main_h + detail_h, 0)
|
28
|
-
}
|
29
|
-
|
30
|
-
items = Qiita.item("") rescue []
|
31
|
-
@windows[MAIN_WINDOW].collection = items
|
32
|
-
@windows[MAIN_WINDOW].print
|
33
|
-
end
|
34
|
-
|
35
|
-
def on_input(input)
|
36
|
-
case input
|
37
|
-
when ?j
|
38
|
-
current_window.cursor_down
|
39
|
-
when ?k
|
40
|
-
current_window.cursor_up
|
41
|
-
when 10
|
42
|
-
if current_window == window(MAIN_WINDOW)
|
43
|
-
index = current_window.cursor.y
|
44
|
-
item = current_window.collection.at(index)
|
45
|
-
return unless item
|
46
|
-
item_detail = Qiita.item(item.uuid) rescue {}
|
47
|
-
window(DETAIL_WINDOW).item_loaded item_detail
|
48
|
-
switch_to_next_window window(DETAIL_WINDOW)
|
49
|
-
end
|
50
|
-
when ?q
|
51
|
-
switch_to_previous_window
|
52
|
-
end
|
53
|
-
end
|
54
|
-
|
55
|
-
def window(window_id)
|
56
|
-
windows[window_id]
|
57
|
-
end
|
58
|
-
|
59
|
-
def current_window
|
60
|
-
@current_window ||= window(MAIN_WINDOW)
|
61
|
-
end
|
62
|
-
|
63
|
-
def current_window=(win)
|
64
|
-
@current_window = win
|
65
|
-
end
|
66
|
-
|
67
|
-
def window_history
|
68
|
-
@window_history ||= []
|
69
|
-
end
|
70
|
-
|
71
|
-
def switch_to_next_window(win)
|
72
|
-
window_history << current_window
|
73
|
-
self.current_window = win
|
74
|
-
switch_to(current_window)
|
75
|
-
end
|
76
|
-
|
77
|
-
def switch_to_previous_window
|
78
|
-
previous_win = window_history.shift
|
79
|
-
unless previous_win
|
80
|
-
exit
|
81
|
-
else
|
82
|
-
current_window.virtual_close
|
83
|
-
switch_to(previous_win)
|
84
|
-
end
|
85
|
-
end
|
86
|
-
|
87
|
-
def switch_to(win)
|
88
|
-
self.current_window = win
|
89
|
-
win.setpos(win.cursor.y, win.cursor.x)
|
90
|
-
win.refresh
|
91
|
-
end
|
92
|
-
end
|
93
|
-
end
|