zashoku 1.2.2 → 1.3.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/config/view.yml +3 -0
- data/lib/core/config/config.rb +14 -8
- data/lib/core/config/daemon_config.rb +4 -1
- data/lib/core/config/view_config.rb +4 -1
- data/lib/core/item.rb +1 -1
- data/lib/core/modules/conf/lib/conf.rb +16 -0
- data/lib/core/modules/conf/lib/conf/config_view.rb +21 -0
- data/lib/core/net/client.rb +1 -1
- data/lib/core/options.rb +41 -39
- data/lib/core/statusline/statusline.rb +9 -7
- data/lib/core/statusline/widget.rb +3 -3
- data/lib/core/util/readline.rb +123 -0
- data/lib/core/util/util.rb +12 -24
- data/lib/core/view.rb +1 -0
- data/lib/viewer.rb +65 -28
- data/lib/zashoku.rb +1 -1
- metadata +5 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: d711517f1114c2ab894274ee55ec0f1b77b5f14e
|
4
|
+
data.tar.gz: 425fe6cd0aa648c76dadb70beb16f9ade10109e2
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 2903f26cff66c1dbc0515f66a89f5a1e35ec09af22adab661e754c1660feb083ad5f97112ac5d9bfbfb798898cb28b9641a69bd49ca0333d6da9efc2d967ac50
|
7
|
+
data.tar.gz: e9ff48aa435939b22b27ae07c7472a4c8cf8109d97984fb8b8f72eadea52ed0acb53a7b8a5010aae1bf9756e2d1d5459b6defd5b7ec6d5ba2c179392d985ce05
|
data/config/view.yml
CHANGED
data/lib/core/config/config.rb
CHANGED
@@ -2,6 +2,7 @@
|
|
2
2
|
|
3
3
|
require 'yaml'
|
4
4
|
require 'fileutils'
|
5
|
+
require 'pp'
|
5
6
|
|
6
7
|
module Zashoku
|
7
8
|
class Config < Controller
|
@@ -16,6 +17,7 @@ module Zashoku
|
|
16
17
|
|
17
18
|
def reload
|
18
19
|
@conf = merge!(default_conf, user_conf)
|
20
|
+
save
|
19
21
|
end
|
20
22
|
|
21
23
|
def merge!(this, that)
|
@@ -43,23 +45,27 @@ module Zashoku
|
|
43
45
|
end
|
44
46
|
|
45
47
|
def pref_model(title, value, trail)
|
46
|
-
|
48
|
+
Item.new('title' => title, 'value' => value, 'trail' => trail)
|
47
49
|
end
|
48
50
|
|
49
|
-
def items
|
50
|
-
|
51
|
-
|
51
|
+
def items(c = @conf, pre = '', path = [])
|
52
|
+
return pref_model(pre, c, path) unless c.respond_to?(:map)
|
53
|
+
c.map do |title, pref|
|
54
|
+
# next if IGNORE.key? title
|
55
|
+
t = "#{pre}_#{title}"
|
56
|
+
pth = path + [title]
|
52
57
|
case pref
|
53
58
|
when Hash
|
54
59
|
pref.map do |subt, subpref|
|
55
|
-
|
60
|
+
items(subpref, "#{pre}_#{title}_#{subt}", [title, subt])
|
61
|
+
#pref_model("#{title}_#{subt}", subpref, [title, subt])
|
56
62
|
end
|
57
63
|
when Array
|
58
|
-
pref_model(
|
64
|
+
pref_model(t, pref.join(':'), pth)
|
59
65
|
else
|
60
|
-
pref_model(
|
66
|
+
pref_model(t, pref, pth)
|
61
67
|
end
|
62
|
-
end.flatten
|
68
|
+
end.flatten #.compact
|
63
69
|
end
|
64
70
|
|
65
71
|
def parse_dir(path)
|
@@ -13,7 +13,10 @@ module Zashoku
|
|
13
13
|
end
|
14
14
|
|
15
15
|
def base_conf
|
16
|
-
|
16
|
+
merge!(
|
17
|
+
Util.get_yaml(File.join(Zashoku::Root, 'config/daemon.yml')),
|
18
|
+
Util.get_yaml(File.join(Zashoku::AppRoot, 'config/daemon.yml')),
|
19
|
+
)
|
17
20
|
end
|
18
21
|
end
|
19
22
|
end
|
@@ -13,7 +13,10 @@ module Zashoku
|
|
13
13
|
end
|
14
14
|
|
15
15
|
def base_conf
|
16
|
-
|
16
|
+
merge!(
|
17
|
+
Util.get_yaml(File.join(Zashoku::Root, 'config/view.yml')),
|
18
|
+
Util.get_yaml(File.join(Zashoku::AppRoot, 'config/view.yml')),
|
19
|
+
)
|
17
20
|
end
|
18
21
|
end
|
19
22
|
end
|
data/lib/core/item.rb
CHANGED
@@ -0,0 +1,16 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Zashoku
|
4
|
+
module Conf
|
5
|
+
extend Zashoku::Module
|
6
|
+
|
7
|
+
Version = [1, 0, 0].freeze
|
8
|
+
Root = File.expand_path('../', __dir__)
|
9
|
+
|
10
|
+
autoload :ConfigView, File.join(Root, 'lib/conf/config_view')
|
11
|
+
|
12
|
+
def self.view
|
13
|
+
ConfigView.new
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
@@ -0,0 +1,21 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Zashoku
|
4
|
+
module Conf
|
5
|
+
class ConfigView < Zashoku::View
|
6
|
+
def refresh_attributes
|
7
|
+
@attributes = {
|
8
|
+
't' => Zashoku.conf.get(%w[title conf]),
|
9
|
+
}
|
10
|
+
end
|
11
|
+
|
12
|
+
def refresh_items
|
13
|
+
@items = Zashoku.conf.items
|
14
|
+
end
|
15
|
+
|
16
|
+
def get_format
|
17
|
+
Zashoku.conf.get(%w[format conf])
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
data/lib/core/net/client.rb
CHANGED
data/lib/core/options.rb
CHANGED
@@ -2,49 +2,51 @@
|
|
2
2
|
|
3
3
|
require 'optparse'
|
4
4
|
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
5
|
+
module Zashoku
|
6
|
+
class Options
|
7
|
+
def self.parse(args)
|
8
|
+
options = {
|
9
|
+
daemon: false,
|
10
|
+
server: true,
|
11
|
+
server_command: nil,
|
12
|
+
generate: false,
|
13
|
+
template: nil,
|
14
|
+
generate_name: nil
|
15
|
+
}
|
16
|
+
|
17
|
+
parser = OptionParser.new do |opts|
|
18
|
+
opts.banner = 'Usage: zashoku [options]'
|
19
|
+
|
20
|
+
opts.on('-s [COMMAND]', '--server [COMMAND]', 'pass commands to the server') do |cmd|
|
21
|
+
options[:server] = true
|
22
|
+
options[:server_command] = cmd || 'start'
|
23
|
+
end
|
24
|
+
|
25
|
+
opts.on('-d', '--daemon', 'daemonize the server') do |d|
|
26
|
+
options[:daemonize] = true
|
27
|
+
end
|
28
|
+
|
29
|
+
opts.on('-g TEMPLATE', '--generate TEMPLATE', 'generate a template') do |template|
|
30
|
+
options[:template] = template
|
31
|
+
options[:generate] = true
|
32
|
+
end
|
33
|
+
|
34
|
+
opts.on_tail('-h', '--help', 'Show this message') do
|
35
|
+
puts opts
|
36
|
+
exit
|
37
|
+
end
|
38
|
+
|
39
|
+
opts.on_tail('--version', 'Show version') do
|
40
|
+
puts Zashoku::Version.join('.')
|
41
|
+
exit
|
42
|
+
end
|
22
43
|
end
|
23
44
|
|
24
|
-
|
25
|
-
options[:daemonize] = true
|
26
|
-
end
|
27
|
-
|
28
|
-
opts.on('-g TEMPLATE', '--generate TEMPLATE', 'generate a template') do |template|
|
29
|
-
options[:template] = template
|
30
|
-
options[:generate] = true
|
31
|
-
end
|
45
|
+
parser.parse!(args)
|
32
46
|
|
33
|
-
|
34
|
-
puts opts
|
35
|
-
exit
|
36
|
-
end
|
47
|
+
options[:generate_name] = args.pop if options[:template]
|
37
48
|
|
38
|
-
|
39
|
-
puts Zashoku::Version.join('.')
|
40
|
-
exit
|
41
|
-
end
|
49
|
+
options
|
42
50
|
end
|
43
|
-
|
44
|
-
parser.parse!(args)
|
45
|
-
|
46
|
-
options[:generate_name] = args.pop if options[:template]
|
47
|
-
|
48
|
-
options
|
49
51
|
end
|
50
52
|
end
|
@@ -13,11 +13,10 @@ module Zashoku
|
|
13
13
|
include Observable
|
14
14
|
|
15
15
|
def initialize
|
16
|
-
Zashoku.logger.debug('hhh')
|
17
16
|
@widgets = Zashoku.modules.keys.zip(Zashoku.modules.map do |_k, m|
|
18
17
|
m.widgets if m.respond_to?(:widgets)
|
19
18
|
end).to_h.compact
|
20
|
-
Zashoku.logger.debug(@widgets)
|
19
|
+
Zashoku.logger.debug("loaded widgets for #{@widgets.keys.join(', ')}")
|
21
20
|
refresh
|
22
21
|
end
|
23
22
|
|
@@ -36,15 +35,18 @@ module Zashoku
|
|
36
35
|
end
|
37
36
|
|
38
37
|
def refresh
|
39
|
-
@
|
40
|
-
|
41
|
-
|
38
|
+
@cl = Zashoku::conf.get(%w[color main])
|
39
|
+
@attrs = @widgets.map do |_k, m|
|
40
|
+
m.map { |j, w| w.attr }
|
41
|
+
end.flatten.reduce(&:merge)
|
42
42
|
|
43
|
-
|
43
|
+
format = Zashoku::conf.get(%w[format statusline])
|
44
|
+
|
45
|
+
@items_formatted = Zashoku::Formatter.format_line(format, @attrs)
|
44
46
|
end
|
45
47
|
|
46
48
|
def draw
|
47
|
-
print "\e[#{Util::Term.rows - 1};1H\e[0m#{@items_formatted}\e[K"
|
49
|
+
print "\e[#{Util::Term.rows - 1};1H\e[0m#{@cl}#{@items_formatted}\e[K"
|
48
50
|
end
|
49
51
|
end
|
50
52
|
end
|
@@ -0,0 +1,123 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'amatch'
|
4
|
+
|
5
|
+
module Zashoku
|
6
|
+
module Util
|
7
|
+
class Readline
|
8
|
+
attr_accessor :ac_index, :hy_index, :ac_sorted, :prompt, :x, :y, :history
|
9
|
+
|
10
|
+
def initialize(prompt = '', ac_tree: {}, history: [])
|
11
|
+
@prompt = prompt
|
12
|
+
@ac_index = 0
|
13
|
+
@history = history
|
14
|
+
@hy_index = 0
|
15
|
+
@ac_sorted = []
|
16
|
+
@tree = ac_tree
|
17
|
+
@y = Term.rows
|
18
|
+
end
|
19
|
+
|
20
|
+
def draw(string)
|
21
|
+
print "\e[#{y};0H#{prompt}#{string}\e[K\e[#{y};#{@x + 1}H"
|
22
|
+
end
|
23
|
+
|
24
|
+
def read(string = '')
|
25
|
+
@x = prompt.length
|
26
|
+
Curses.curs_set(1)
|
27
|
+
max = Term.cols
|
28
|
+
|
29
|
+
loop do
|
30
|
+
draw(string)
|
31
|
+
c = Curses.getch
|
32
|
+
@ac_index = 0 unless c == 9
|
33
|
+
case c
|
34
|
+
when Curses::KEY_LEFT
|
35
|
+
@x = [prompt.length, x-1].max
|
36
|
+
when Curses::KEY_RIGHT
|
37
|
+
@x = [prompt.length + string.length, x+1].min
|
38
|
+
when Curses::KEY_UP
|
39
|
+
@history.unshift(string) if hy_index == 0
|
40
|
+
@hy_index += 1
|
41
|
+
if hy_index >= history.length
|
42
|
+
@hy_index = history.length - 1
|
43
|
+
Curses.beep
|
44
|
+
end
|
45
|
+
string = history[hy_index]
|
46
|
+
@x = string.length + prompt.length
|
47
|
+
when Curses::KEY_DOWN
|
48
|
+
if hy_index == 1
|
49
|
+
@hy_index = 0
|
50
|
+
string = @history.shift
|
51
|
+
elsif hy_index > 1
|
52
|
+
string = history[@hy_index -= 1] || ''
|
53
|
+
else
|
54
|
+
@hy_index = 0
|
55
|
+
Curses.beep
|
56
|
+
end
|
57
|
+
@x = string.length + prompt.length
|
58
|
+
when 10, ?\n, ?\r
|
59
|
+
break
|
60
|
+
when 127 #backspace
|
61
|
+
print "\e[#{y};#{x}H "
|
62
|
+
@x -= 1
|
63
|
+
break if @x < prompt.length
|
64
|
+
rx = @x - prompt.length
|
65
|
+
string = string[0...rx] + string[rx..-1]
|
66
|
+
string[x - prompt.length] = ''
|
67
|
+
when 9 #tab
|
68
|
+
if @ac_index == 0
|
69
|
+
acl = ac_list(string)
|
70
|
+
@ac_sorted = sort_ac_list(acl, string)
|
71
|
+
end
|
72
|
+
string = @ac_sorted[@ac_index] || ''
|
73
|
+
@x = @prompt.length + string.length
|
74
|
+
@ac_index += 1
|
75
|
+
@ac_index = 0 if @ac_index >= ac_sorted.length
|
76
|
+
when /[[:print:]]/
|
77
|
+
if (@x < max)
|
78
|
+
rx = @x - prompt.length
|
79
|
+
string = string[0...rx] + c.chr + string[rx..-1]
|
80
|
+
@x += 1
|
81
|
+
else
|
82
|
+
Curses.beep
|
83
|
+
end
|
84
|
+
else
|
85
|
+
Curses.beep
|
86
|
+
end
|
87
|
+
@history[@hy_index] = string
|
88
|
+
end
|
89
|
+
|
90
|
+
Curses.curs_set(0)
|
91
|
+
print "\e[#{y};0H\e[2K"
|
92
|
+
|
93
|
+
@hy_index = 0
|
94
|
+
@history.unshift(string)
|
95
|
+
@history.reject! { |e| e.empty? }
|
96
|
+
string
|
97
|
+
end
|
98
|
+
|
99
|
+
def safe_dig(tree, path)
|
100
|
+
l = @tree.dig(path.shift)
|
101
|
+
return l if l.class != Hash || path.empty?
|
102
|
+
safe_dig(tree, path)
|
103
|
+
end
|
104
|
+
|
105
|
+
def ac_list(string)
|
106
|
+
path = string.split
|
107
|
+
path << '' if string[-1] == ' '
|
108
|
+
if path.length > 1
|
109
|
+
ac = safe_dig(@tree, path[0...-1])
|
110
|
+
return [string] unless ac
|
111
|
+
ac.map { |n| (path[0...-1] + [n]).join(' ') }
|
112
|
+
else
|
113
|
+
@tree.keys
|
114
|
+
end
|
115
|
+
end
|
116
|
+
|
117
|
+
def sort_ac_list(list, string)
|
118
|
+
m = Amatch::JaroWinkler.new(string)
|
119
|
+
list.map { |e| [m.match(e.to_s), e] }.sort.map { |a| a[1] }.reverse
|
120
|
+
end
|
121
|
+
end
|
122
|
+
end
|
123
|
+
end
|
data/lib/core/util/util.rb
CHANGED
@@ -1,30 +1,10 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
3
|
require 'base64'
|
4
|
-
|
4
|
+
require_relative 'readline'
|
5
5
|
|
6
6
|
module Zashoku
|
7
7
|
module Util
|
8
|
-
def self.readline(prompt = '', default = '')
|
9
|
-
Term.bold.echo_on
|
10
|
-
print "\033[" + String(Term.rows) + ';1H'
|
11
|
-
Term.show_cursor
|
12
|
-
Readline.completion_append_character = ''
|
13
|
-
Readline.pre_input_hook = lambda do
|
14
|
-
Readline.insert_text default.to_s
|
15
|
-
Readline.redisplay
|
16
|
-
Readline.pre_input_hook = nil
|
17
|
-
end
|
18
|
-
input = Readline.readline(prompt, false)
|
19
|
-
Term.hide_cursor.nobold.echo_off.clear
|
20
|
-
input
|
21
|
-
end
|
22
|
-
|
23
|
-
def self.error_message(message)
|
24
|
-
# use statusline to show error messages
|
25
|
-
print "\e[#{Term.rows - 1};1H\e[31m #{message}\e[K"
|
26
|
-
end
|
27
|
-
|
28
8
|
def self.encode_object(d)
|
29
9
|
Base64.strict_encode64(Marshal.dump(d))
|
30
10
|
end
|
@@ -37,10 +17,18 @@ module Zashoku
|
|
37
17
|
{}
|
38
18
|
end
|
39
19
|
|
40
|
-
def self.get_yaml(file)
|
41
|
-
YAML.safe_load(File.open(file, 'r', &:read)) ||
|
20
|
+
def self.get_yaml(file, nil_value = {})
|
21
|
+
YAML.safe_load(File.open(file, 'r', &:read)) || nil_value
|
42
22
|
rescue Errno::ENOENT
|
43
|
-
|
23
|
+
nil_value
|
24
|
+
end
|
25
|
+
|
26
|
+
def self.put_yaml(file, data)
|
27
|
+
File.open(file, 'w') { |f| f.puts YAML.dump(data) }
|
28
|
+
end
|
29
|
+
|
30
|
+
def self.alert(msg)
|
31
|
+
print "\e[#{Term.rows};0H\e[31m#{msg}\e[K"
|
44
32
|
end
|
45
33
|
end
|
46
34
|
end
|
data/lib/core/view.rb
CHANGED
data/lib/viewer.rb
CHANGED
@@ -6,6 +6,7 @@ require 'io/console'
|
|
6
6
|
require 'logger'
|
7
7
|
require 'observer'
|
8
8
|
require 'thread'
|
9
|
+
require 'json'
|
9
10
|
|
10
11
|
require_relative 'core/controller'
|
11
12
|
require_relative 'core/config/view_config'
|
@@ -18,6 +19,8 @@ require_relative 'core/item'
|
|
18
19
|
require_relative 'core/module'
|
19
20
|
require_relative 'core/view'
|
20
21
|
|
22
|
+
require_relative 'core/modules/conf/lib/conf'
|
23
|
+
|
21
24
|
$stdout.sync = true
|
22
25
|
|
23
26
|
module Zashoku
|
@@ -35,19 +38,19 @@ module Zashoku
|
|
35
38
|
modules[message[:mod]].send(message[:meth], *message[:args])
|
36
39
|
end
|
37
40
|
end
|
38
|
-
|
39
|
-
def alert(message)
|
40
|
-
print "\e[#{Util::Term.rows - 2};0H #{message}"
|
41
|
-
end
|
42
41
|
end
|
43
42
|
|
44
43
|
# Main class for the zashoku application
|
45
44
|
class Viewer
|
46
45
|
include Util
|
47
46
|
|
47
|
+
HISTORY = File.join(Zashoku::Config::CONF_DIR, 'cmd_history.yml')
|
48
|
+
|
48
49
|
COMMANDS = {
|
49
|
-
'quit'
|
50
|
-
'enter_command' => :get_user_command
|
50
|
+
'quit' => :cleanup,
|
51
|
+
'enter_command' => :get_user_command,
|
52
|
+
'change_view' => :change_view,
|
53
|
+
'map_key' => :map_key
|
51
54
|
}.freeze
|
52
55
|
|
53
56
|
def initialize
|
@@ -60,20 +63,35 @@ module Zashoku
|
|
60
63
|
Zashoku.conf = ViewConfig.new
|
61
64
|
|
62
65
|
Zashoku.modules = Zashoku::Module.load(Zashoku::ViewerModules)
|
66
|
+
Zashoku.modules.merge!('conf' => Conf)
|
63
67
|
Zashoku.conf.reload
|
64
68
|
|
65
69
|
# note: start daemon if not running
|
66
70
|
Zashoku.client = Net::Client.new(Zashoku::Port)
|
67
71
|
Zashoku.client.callbacks << method(:handle_event)
|
68
72
|
|
73
|
+
@server_modules = Zashoku.client.command('modules')
|
74
|
+
|
69
75
|
@views = Zashoku.modules.keys.zip(Zashoku.modules.map do |_k, m|
|
70
76
|
m.view
|
71
77
|
end).to_h
|
72
78
|
@view = @views.keys.first
|
73
79
|
|
80
|
+
Zashoku.logger.debug('initializing statusline')
|
74
81
|
@statusline = Statusline.new
|
82
|
+
Zashoku.logger.debug(@statusline)
|
75
83
|
@statusline.add_observer(self, :draw_statusline)
|
76
84
|
|
85
|
+
@cmdline = Util::Readline.new(
|
86
|
+
':',
|
87
|
+
ac_tree:
|
88
|
+
@views.map { |k, v| [k, v.methods - Object.methods] }.to_h
|
89
|
+
.merge(COMMANDS.map { |k, _v| [k, nil] }.to_h)
|
90
|
+
.merge({'conf' => Zashoku.conf.methods - Object.methods })
|
91
|
+
.merge(@server_modules.map { |m| ['remote::' + m, nil] }.to_h),
|
92
|
+
history: Util.get_yaml(HISTORY, [])
|
93
|
+
)
|
94
|
+
|
77
95
|
init_screen
|
78
96
|
lay_traps!
|
79
97
|
Thread.abort_on_exception = true
|
@@ -84,9 +102,19 @@ module Zashoku
|
|
84
102
|
sleep
|
85
103
|
end
|
86
104
|
|
105
|
+
def change_view(new_view)
|
106
|
+
Zashoku.logger.debug("Changing view to #{new_view}")
|
107
|
+
@views[@view].delete_observers
|
108
|
+
#@views[new_view].change_screen_size(redraw: false)
|
109
|
+
#@views[new_view].expand(-1)
|
110
|
+
@view = new_view
|
111
|
+
init_view(@view)
|
112
|
+
end
|
113
|
+
|
87
114
|
def init_view(view)
|
88
|
-
@views[
|
89
|
-
@views[
|
115
|
+
@views[view].add_observer(self, :draw_view)
|
116
|
+
@views[view].refresh
|
117
|
+
@views[view].dirty_all_lines
|
90
118
|
draw_view
|
91
119
|
end
|
92
120
|
|
@@ -103,6 +131,15 @@ module Zashoku
|
|
103
131
|
end
|
104
132
|
end
|
105
133
|
|
134
|
+
def cleanup
|
135
|
+
Zashoku.client.disconnect
|
136
|
+
@key_thread&.exit
|
137
|
+
Curses.close_screen
|
138
|
+
Util.put_yaml(HISTORY, @cmdline.history)
|
139
|
+
Term.show_cursor
|
140
|
+
exit
|
141
|
+
end
|
142
|
+
|
106
143
|
def init_screen
|
107
144
|
Curses.noecho
|
108
145
|
Curses.init_screen
|
@@ -119,7 +156,13 @@ module Zashoku
|
|
119
156
|
end
|
120
157
|
|
121
158
|
def get_user_command
|
122
|
-
|
159
|
+
cmd = @cmdline.read
|
160
|
+
return unless cmd
|
161
|
+
return builtin_command(*cmd.split) if COMMANDS.key?(cmd.split.first)
|
162
|
+
|
163
|
+
command(*cmd.split) unless cmd.empty?
|
164
|
+
rescue
|
165
|
+
Util.alert('Error')
|
123
166
|
end
|
124
167
|
|
125
168
|
def handle_event(event)
|
@@ -131,6 +174,15 @@ module Zashoku
|
|
131
174
|
end
|
132
175
|
end
|
133
176
|
|
177
|
+
def builtin_command(cmd, *args)
|
178
|
+
Zashoku.logger.debug("executing builtin #{cmd}(#{args})")
|
179
|
+
send(COMMANDS[cmd], *args)
|
180
|
+
end
|
181
|
+
|
182
|
+
def map_key(key, mod, command, *args)
|
183
|
+
Zashoku.conf.set(['keymaps', mod, key], "#{command} #{args.join(' ')}")
|
184
|
+
end
|
185
|
+
|
134
186
|
def scan_keyboard!
|
135
187
|
loop do
|
136
188
|
key = Curses.getch
|
@@ -144,7 +196,10 @@ module Zashoku
|
|
144
196
|
''
|
145
197
|
end
|
146
198
|
|
147
|
-
|
199
|
+
if COMMANDS.key?(cmd.split.first)
|
200
|
+
builtin_command(*cmd.split)
|
201
|
+
next
|
202
|
+
end
|
148
203
|
|
149
204
|
mod, meth, *args = cmd.split
|
150
205
|
mod = mod == 'current_view' ? @view : mod
|
@@ -163,24 +218,6 @@ module Zashoku
|
|
163
218
|
end
|
164
219
|
end
|
165
220
|
|
166
|
-
def cleanup
|
167
|
-
Zashoku.client.disconnect
|
168
|
-
@key_thread&.exit
|
169
|
-
Curses.close_screen
|
170
|
-
Term.show_cursor
|
171
|
-
exit
|
172
|
-
end
|
173
|
-
|
174
|
-
def change_view(new_view:)
|
175
|
-
@view.delete_observers
|
176
|
-
@view.pause
|
177
|
-
new_view.add_observer(self, :draw_view)
|
178
|
-
new_view.change_screen_size(redraw: false)
|
179
|
-
new_view.expand(-1)
|
180
|
-
new_view.unpause
|
181
|
-
@view = view
|
182
|
-
end
|
183
|
-
|
184
221
|
def draw_view
|
185
222
|
@views[@view].draw
|
186
223
|
end
|
data/lib/zashoku.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: zashoku
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.
|
4
|
+
version: 1.3.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- annacrombie
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2017-10-
|
11
|
+
date: 2017-10-17 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: curses
|
@@ -107,12 +107,15 @@ files:
|
|
107
107
|
- "./lib/core/formatter.rb"
|
108
108
|
- "./lib/core/item.rb"
|
109
109
|
- "./lib/core/module.rb"
|
110
|
+
- "./lib/core/modules/conf/lib/conf.rb"
|
111
|
+
- "./lib/core/modules/conf/lib/conf/config_view.rb"
|
110
112
|
- "./lib/core/net/client.rb"
|
111
113
|
- "./lib/core/net/server.rb"
|
112
114
|
- "./lib/core/options.rb"
|
113
115
|
- "./lib/core/statusline/statusline.rb"
|
114
116
|
- "./lib/core/statusline/widget.rb"
|
115
117
|
- "./lib/core/util/folder_listen.rb"
|
118
|
+
- "./lib/core/util/readline.rb"
|
116
119
|
- "./lib/core/util/term.rb"
|
117
120
|
- "./lib/core/util/util.rb"
|
118
121
|
- "./lib/core/view.rb"
|