fancy_buff 3.0.0 → 4.0.0
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/lib/fancy_buff.rb +70 -27
- 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: 8a2c28ecbc28c73489bf537ebb9ced7249aca3d1b6b09f22f9fba97980e7752d
|
4
|
+
data.tar.gz: 73db0f4d103f6449b89ef74d84ab2c37f5948f10da2067747ae2146c42dbf482
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 48beaba19e87d9adb7d9221a9e0784c15a27e7c3e3629ae313f283eb1e7175f09acd621564e5e9255009d85fdd76532296d0b845d01208487563bb000160edf5
|
7
|
+
data.tar.gz: 9f92dbb97a4b8ff2ead342b1de305d3df60a1bbddfa7b8c82fb22f70f507bf02a092ee61dee8493c928ead773b60bd39c1a0b6068eb59c9508675aedc040d8ed
|
data/lib/fancy_buff.rb
CHANGED
@@ -40,10 +40,30 @@ class FancyBuff
|
|
40
40
|
def win=(coords)
|
41
41
|
@win = coords
|
42
42
|
|
43
|
-
|
43
|
+
adjust_caret!
|
44
44
|
end
|
45
45
|
|
46
|
-
|
46
|
+
# index of first visible column
|
47
|
+
def c
|
48
|
+
@win[0]
|
49
|
+
end
|
50
|
+
|
51
|
+
# index of first visible row
|
52
|
+
def r
|
53
|
+
@win[1]
|
54
|
+
end
|
55
|
+
|
56
|
+
# width of the buffer window
|
57
|
+
def w
|
58
|
+
@win[2]
|
59
|
+
end
|
60
|
+
|
61
|
+
# height of the buffer window
|
62
|
+
def h
|
63
|
+
@win[3]
|
64
|
+
end
|
65
|
+
|
66
|
+
def adjust_caret!
|
47
67
|
cx, cy = @caret
|
48
68
|
new_cx = if cx < c
|
49
69
|
c
|
@@ -64,33 +84,56 @@ class FancyBuff
|
|
64
84
|
@caret = [new_cx, new_cy]
|
65
85
|
end
|
66
86
|
|
67
|
-
def
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
87
|
+
def adjust_win!
|
88
|
+
cx, cy = visual_caret
|
89
|
+
wx, wy = @win[0], @win[1]
|
90
|
+
|
91
|
+
new_wx = if cx > (c + w - 1)
|
92
|
+
wx + 1
|
93
|
+
elsif cx < 0
|
94
|
+
wx - 1
|
95
|
+
else
|
96
|
+
wx
|
97
|
+
end
|
98
|
+
|
99
|
+
new_wy = if cy > (r + h - 1)
|
100
|
+
wy + 1
|
101
|
+
elsif cy < 0
|
102
|
+
wy - 1
|
103
|
+
else
|
104
|
+
wy
|
105
|
+
end
|
106
|
+
|
107
|
+
@win[0] = wx
|
108
|
+
@win[1] = wy
|
72
109
|
end
|
73
110
|
|
74
|
-
|
75
|
-
|
76
|
-
|
111
|
+
def caret_down!
|
112
|
+
@caret[1] = [caret[1] + 1, @lines.length - 1].min
|
113
|
+
adjust_win!
|
77
114
|
end
|
78
115
|
|
79
|
-
|
80
|
-
|
81
|
-
|
116
|
+
def caret_up!
|
117
|
+
@caret[1] = [caret[1] - 1, 0].max
|
118
|
+
adjust_win!
|
82
119
|
end
|
83
120
|
|
84
|
-
|
85
|
-
|
86
|
-
|
121
|
+
def caret_left!
|
122
|
+
@caret[0] = [caret[0] - 1, 0].max
|
123
|
+
adjust_win!
|
87
124
|
end
|
88
125
|
|
89
|
-
|
90
|
-
|
91
|
-
|
126
|
+
def caret_right!
|
127
|
+
@caret[0] = [caret[0] + 1, @lines[caret[1]].length - 1].min
|
128
|
+
adjust_win!
|
92
129
|
end
|
93
130
|
|
131
|
+
def visual_caret
|
132
|
+
[
|
133
|
+
caret[0] - c + line_no_width + 1, # '+ 1' is to account for a space between line numbers and caret
|
134
|
+
caret[1] - r
|
135
|
+
]
|
136
|
+
end
|
94
137
|
# returns an array of strings representing the visible characters from this
|
95
138
|
# FancyBuffer's @rect
|
96
139
|
def win_s
|
@@ -153,27 +196,27 @@ class FancyBuff
|
|
153
196
|
end
|
154
197
|
|
155
198
|
# scrolls the visible window up
|
156
|
-
def
|
199
|
+
def buff_up!(n=1)
|
157
200
|
@win[1] = [@win[1] - n, 0].max
|
158
|
-
|
201
|
+
adjust_caret!
|
159
202
|
end
|
160
203
|
|
161
204
|
# scrolls the visible window down
|
162
|
-
def
|
205
|
+
def buff_down!(n=1)
|
163
206
|
@win[1] = [@win[1] + n, @lines.length - 1].min
|
164
|
-
|
207
|
+
adjust_caret!
|
165
208
|
end
|
166
209
|
|
167
210
|
# scrolls the visible window left
|
168
|
-
def
|
211
|
+
def buff_left!(n=1)
|
169
212
|
@win[0] = [@win[0] - n, 0].max
|
170
|
-
|
213
|
+
adjust_caret!
|
171
214
|
end
|
172
215
|
|
173
216
|
# scrolls the visible window right
|
174
|
-
def
|
217
|
+
def buff_right!(n=1)
|
175
218
|
@win[0] = [@win[0] + n, max_char_width - 1].min
|
176
|
-
|
219
|
+
adjust_caret!
|
177
220
|
end
|
178
221
|
|
179
222
|
# set a mark, as in the Vim sense
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: fancy_buff
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version:
|
4
|
+
version: 4.0.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Jeff Lunt
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2025-03-26 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rouge
|