vice-editor 0.0.5 → 0.0.6
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.
- checksums.yaml +4 -4
- data/README.md +5 -0
- data/lib/vice.rb +22 -3
- data/lib/vice/blitter.rb +2 -2
- data/lib/vice/buffer.rb +14 -6
- data/lib/vice/parser.rb +8 -4
- data/lib/vice/prompt.rb +1 -1
- data/lib/vice/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 8ea87ed282ee2df96d0a3f32c74f18a55b90a87d991d47327c30559b9deed763
|
4
|
+
data.tar.gz: 355574c2017cbf634fb8f7b98d8c02a87c95be41403c60992a0c4b4fce10bff1
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: b03be081c958647a1251d9054db4a6e2cfa8314e67a9a6709049cb0b7f55c8d74349be728458c58088aabb11e37296dec71949c0a0858c0a6f8a39f86430f6db
|
7
|
+
data.tar.gz: 7a8ee61a59e5c8809e8ce69c05026b42d0b7ba04a83bb34c62a787b9e72ab5fc2ca5262a90c831d0f462134b68e475c6263e9dc31739249a3ee0cf2e3c78a4ae
|
data/README.md
CHANGED
@@ -7,7 +7,12 @@ vice (**vi**sual **c**ode **e**ditor) is a small vi-like editor. It is currently
|
|
7
7
|
## Installation
|
8
8
|
Simply running `gem install vice-editor` should be sufficient to install vice. You can then execute `vice` to start the editor.
|
9
9
|
|
10
|
+
## Configuration
|
11
|
+
vice can be configured by creating a file at `~/.vicerc`. Your `.vicerc` should be a YAML file containing keys and fitting values as found in [constants.rb](https://github.com/knarka/vice/blob/master/lib/vice/constants.rb#L2). For an example, please look at [the example .vicerc files](https://github.com/knarka/vice/blob/master/extras) in this repository.
|
12
|
+
|
10
13
|
## Development
|
11
14
|
Running: `rake`.
|
15
|
+
|
12
16
|
Tests: `rake test`.
|
17
|
+
|
13
18
|
Style: `rake style`.
|
data/lib/vice.rb
CHANGED
@@ -22,10 +22,10 @@ module Vice
|
|
22
22
|
|
23
23
|
@current_buffer = 0
|
24
24
|
if filenames.nil? || filenames.empty?
|
25
|
-
@buffers.push Buffer.new nil
|
25
|
+
@buffers.push Buffer.new(self, nil)
|
26
26
|
else
|
27
27
|
filenames.each do |f|
|
28
|
-
@buffers.push Buffer.new(f)
|
28
|
+
@buffers.push Buffer.new(self, f)
|
29
29
|
next_buffer
|
30
30
|
end
|
31
31
|
end
|
@@ -35,9 +35,28 @@ module Vice
|
|
35
35
|
defaults = DEFAULTS.clone
|
36
36
|
|
37
37
|
configfile = "#{Dir.home}/.vicerc"
|
38
|
+
|
39
|
+
unless File.file? configfile
|
40
|
+
@config = defaults
|
41
|
+
return
|
42
|
+
end
|
43
|
+
|
38
44
|
user_defined = File.open(configfile) { |f| YAML.safe_load(f.read) } if File.file? configfile
|
39
45
|
|
40
|
-
|
46
|
+
# merge the hashes, to up to two levels of depth.
|
47
|
+
# positive side-effect: our keys are symbols now
|
48
|
+
@config = {}
|
49
|
+
defaults.each do |dk, dv|
|
50
|
+
uv = user_defined[dk.to_s]
|
51
|
+
@config[dk] = if uv.nil?
|
52
|
+
dv
|
53
|
+
elsif uv.is_a? Hash
|
54
|
+
uv = Hash[uv.map { |k, v| [k, v.to_sym] }]
|
55
|
+
dv.merge(uv)
|
56
|
+
else
|
57
|
+
uv
|
58
|
+
end
|
59
|
+
end
|
41
60
|
end
|
42
61
|
|
43
62
|
def start
|
data/lib/vice/blitter.rb
CHANGED
@@ -82,7 +82,7 @@ class Vice::Blitter
|
|
82
82
|
|
83
83
|
(0..buffer.cursor.col - 1).each do |i|
|
84
84
|
visual_cursor.col += if buffer.currentline[i] == "\t"
|
85
|
-
vice.config[
|
85
|
+
vice.config[:tab_width]
|
86
86
|
else
|
87
87
|
1
|
88
88
|
end
|
@@ -112,7 +112,7 @@ class Vice::Blitter
|
|
112
112
|
i = r - 1 + buffer.v_scroll
|
113
113
|
window.setpos r, 0
|
114
114
|
if i < buffer.lines
|
115
|
-
line = pad buffer.getline(i).gsub(/(\t)/, ' ' * vice.config[
|
115
|
+
line = pad buffer.getline(i).gsub(/(\t)/, ' ' * vice.config[:tab_width])
|
116
116
|
window.addstr formatnumber(i + 1) + line
|
117
117
|
else
|
118
118
|
window.addstr pad(formatnumber('~'))
|
data/lib/vice/buffer.rb
CHANGED
@@ -5,20 +5,28 @@ class Vice::Buffer
|
|
5
5
|
attr_accessor :cursor
|
6
6
|
attr_accessor :v_scroll
|
7
7
|
|
8
|
-
def initialize(filename)
|
8
|
+
def initialize(vice, filename)
|
9
9
|
@buffer = []
|
10
10
|
@marks = {}
|
11
|
+
|
12
|
+
@cursor = Vice::Cursor.new
|
13
|
+
@modified = false
|
14
|
+
@v_scroll = 0
|
15
|
+
|
11
16
|
if filename
|
12
17
|
@filename = filename
|
13
|
-
|
14
|
-
|
18
|
+
|
19
|
+
if File.file? filename
|
20
|
+
File.open(filename, 'r') do |f| # TODO: don't assume file exists
|
21
|
+
f.each_line { |line| @buffer.push line.chomp }
|
22
|
+
end
|
23
|
+
else
|
24
|
+
vice.alert 'new file'
|
25
|
+
@buffer.push ''
|
15
26
|
end
|
16
27
|
else
|
17
28
|
@buffer.push ''
|
18
29
|
end
|
19
|
-
@cursor = Vice::Cursor.new
|
20
|
-
@modified = false
|
21
|
-
@v_scroll = 0
|
22
30
|
end
|
23
31
|
|
24
32
|
def writef(filename)
|
data/lib/vice/parser.rb
CHANGED
@@ -36,8 +36,10 @@ class Vice::Parser
|
|
36
36
|
end
|
37
37
|
|
38
38
|
def parsechar_command(vice, current_buffer, char)
|
39
|
-
buffer = vice.buffers[current_buffer]
|
40
39
|
raise 'command parser called from wrong mode' unless vice.mode == :command
|
40
|
+
return if char.is_a? Integer
|
41
|
+
|
42
|
+
buffer = vice.buffers[current_buffer]
|
41
43
|
|
42
44
|
if %i[mark_set mark_jump].include? @current_command
|
43
45
|
Vice::KeyPress.public_send(@current_command, vice, buffer, char)
|
@@ -51,21 +53,23 @@ class Vice::Parser
|
|
51
53
|
if %i[mark_set mark_jump].include? command
|
52
54
|
@current_command = command
|
53
55
|
else
|
54
|
-
Vice::KeyPress.public_send(command, vice, buffer)
|
56
|
+
Vice::KeyPress.public_send(command, vice, buffer) if Vice::KeyPress.respond_to? command.to_sym
|
55
57
|
@current_command = ''
|
56
58
|
end
|
57
59
|
else
|
58
60
|
keep_current = false
|
59
61
|
vice.config[:keys].each do |k|
|
60
|
-
keep_current = true if k[0].start_with? @current_command
|
62
|
+
keep_current = true if k[0].to_s.start_with? @current_command
|
61
63
|
end
|
62
64
|
@current_command = '' unless keep_current
|
63
65
|
end
|
64
66
|
end
|
65
67
|
|
66
68
|
def parsechar_insert(vice, current_buffer, char)
|
67
|
-
buffer = vice.buffers[current_buffer]
|
68
69
|
raise 'insert parser called from wrong mode' unless vice.mode == :insert
|
70
|
+
|
71
|
+
buffer = vice.buffers[current_buffer]
|
72
|
+
|
69
73
|
case char
|
70
74
|
when 9
|
71
75
|
buffer.insert "\t"
|
data/lib/vice/prompt.rb
CHANGED
data/lib/vice/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: vice-editor
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.6
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- knarka
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2018-06-
|
11
|
+
date: 2018-06-22 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: curses
|