textbringer 15 → 17
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/exe/txtb +2 -0
- data/lib/textbringer/buffer.rb +18 -5
- data/lib/textbringer/faces/basic.rb +1 -0
- data/lib/textbringer/global_minor_mode.rb +18 -5
- data/lib/textbringer/minor_mode.rb +5 -2
- data/lib/textbringer/version.rb +1 -1
- data/lib/textbringer/window.rb +58 -10
- metadata +1 -1
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: afebafd9a22024be2bc3c4c5c2140ac9ad3b7fa7a1efc25e0ae9bf4d38c3da10
|
|
4
|
+
data.tar.gz: 53841ecd93d7b63e9d33a07d39721f90bf0d39e6803406287518601d67d4a59c
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 469ef80d72998003e1d5ca9e6c499b70debc5d1c2c09b43b9b79311e94ce15c22adbd766bf31cafaa20a5ac11a19c8b12d9c8392d166cec5a617305c4a50e43f
|
|
7
|
+
data.tar.gz: 6908288f0debd4001c131327071962fda1392ff0310f26fc72b9f0391b01e281b22824c78e78d2be69cd89b5fc768c7239d116bd35699d1483c4fa944aae76be
|
data/exe/txtb
CHANGED
data/lib/textbringer/buffer.rb
CHANGED
|
@@ -1300,15 +1300,28 @@ module Textbringer
|
|
|
1300
1300
|
Utils.run_hooks(mode_class.hook_name)
|
|
1301
1301
|
end
|
|
1302
1302
|
|
|
1303
|
-
def
|
|
1303
|
+
def set_minor_mode(mode_class, arg = nil)
|
|
1304
1304
|
mode = @minor_modes.find { |mode| mode.instance_of?(mode_class) }
|
|
1305
|
-
|
|
1306
|
-
|
|
1307
|
-
|
|
1308
|
-
|
|
1305
|
+
enabled = !!mode
|
|
1306
|
+
|
|
1307
|
+
enable =
|
|
1308
|
+
case arg
|
|
1309
|
+
when true, false
|
|
1310
|
+
return if enabled == arg
|
|
1311
|
+
arg
|
|
1312
|
+
when nil
|
|
1313
|
+
!enabled
|
|
1314
|
+
else
|
|
1315
|
+
raise ArgumentError, "wrong argument #{arg.inspect} (expected true, false, or nil)"
|
|
1316
|
+
end
|
|
1317
|
+
|
|
1318
|
+
if enable
|
|
1309
1319
|
mode = mode_class.new(self)
|
|
1310
1320
|
@minor_modes.push(mode)
|
|
1311
1321
|
mode.enable
|
|
1322
|
+
else
|
|
1323
|
+
mode.disable
|
|
1324
|
+
@minor_modes.delete(mode)
|
|
1312
1325
|
end
|
|
1313
1326
|
end
|
|
1314
1327
|
|
|
@@ -35,13 +35,26 @@ module Textbringer
|
|
|
35
35
|
child.command_name = command
|
|
36
36
|
|
|
37
37
|
# Define the toggle command
|
|
38
|
-
define_command(command
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
38
|
+
define_command(command, doc: "Enable or disable #{command_name}. " \
|
|
39
|
+
"Toggle the mode if arg is nil. " \
|
|
40
|
+
"Enable the mode if arg is true. " \
|
|
41
|
+
"Disable the mode if arg is false") do |arg = nil|
|
|
42
|
+
enable =
|
|
43
|
+
case arg
|
|
44
|
+
when true, false
|
|
45
|
+
return if child.enabled? == arg
|
|
46
|
+
arg
|
|
47
|
+
when nil
|
|
48
|
+
!child.enabled?
|
|
49
|
+
else
|
|
50
|
+
raise ArgumentError, "wrong argument #{arg.inspect} (expected true, false, or nil)"
|
|
51
|
+
end
|
|
52
|
+
if enable
|
|
43
53
|
child.enable
|
|
44
54
|
child.enabled = true
|
|
55
|
+
else
|
|
56
|
+
child.disable
|
|
57
|
+
child.enabled = false
|
|
45
58
|
end
|
|
46
59
|
end
|
|
47
60
|
end
|
|
@@ -17,8 +17,11 @@ module Textbringer
|
|
|
17
17
|
}
|
|
18
18
|
command = command_name.intern
|
|
19
19
|
child.command_name = command
|
|
20
|
-
define_command(command
|
|
21
|
-
|
|
20
|
+
define_command(command, doc: "Enable or disable #{command_name}. " \
|
|
21
|
+
"Toggle the mode if arg is nil. " \
|
|
22
|
+
"Enable the mode if arg is true. " \
|
|
23
|
+
"Disable the mode if arg is false") do |arg = nil|
|
|
24
|
+
Buffer.current.set_minor_mode(child, arg)
|
|
22
25
|
end
|
|
23
26
|
end
|
|
24
27
|
|
data/lib/textbringer/version.rb
CHANGED
data/lib/textbringer/window.rb
CHANGED
|
@@ -236,6 +236,8 @@ module Textbringer
|
|
|
236
236
|
@raw_key_buffer = []
|
|
237
237
|
@key_buffer = []
|
|
238
238
|
@cursor = Cursor.new(0, 0)
|
|
239
|
+
@in_region = false
|
|
240
|
+
@current_highlight_attrs = 0
|
|
239
241
|
end
|
|
240
242
|
|
|
241
243
|
def echo_area?
|
|
@@ -405,23 +407,44 @@ module Textbringer
|
|
|
405
407
|
@window.erase
|
|
406
408
|
@window.setpos(0, 0)
|
|
407
409
|
@window.attrset(0)
|
|
410
|
+
@in_region = false
|
|
411
|
+
@current_highlight_attrs = 0
|
|
408
412
|
if current? && @buffer.visible_mark &&
|
|
409
413
|
@buffer.point_after_mark?(@buffer.visible_mark)
|
|
410
|
-
@window.attron(
|
|
414
|
+
@window.attron(region_attr)
|
|
415
|
+
@in_region = true
|
|
411
416
|
end
|
|
412
417
|
while !@buffer.end_of_buffer?
|
|
413
418
|
cury = @window.cury
|
|
414
419
|
curx = @window.curx
|
|
415
420
|
update_cursor_and_attr(point, cury, curx)
|
|
416
421
|
if attrs = @highlight_off[@buffer.point]
|
|
417
|
-
@
|
|
422
|
+
if @in_region
|
|
423
|
+
# In region: only turn off non-color attributes (bold, underline, etc.)
|
|
424
|
+
@window.attroff(attrs & ~Curses::A_COLOR)
|
|
425
|
+
else
|
|
426
|
+
@window.attroff(attrs)
|
|
427
|
+
end
|
|
428
|
+
@current_highlight_attrs = 0
|
|
418
429
|
end
|
|
419
430
|
if attrs = @highlight_on[@buffer.point]
|
|
420
|
-
@
|
|
431
|
+
if @in_region
|
|
432
|
+
# In region: only turn on non-color attributes (preserve region background)
|
|
433
|
+
@window.attron(attrs & ~Curses::A_COLOR)
|
|
434
|
+
else
|
|
435
|
+
@window.attron(attrs)
|
|
436
|
+
end
|
|
437
|
+
@current_highlight_attrs = attrs
|
|
421
438
|
end
|
|
422
439
|
c = @buffer.char_after
|
|
423
440
|
if c == "\n"
|
|
424
|
-
|
|
441
|
+
# Fill to end of line with region background if in region
|
|
442
|
+
if @in_region
|
|
443
|
+
remaining = columns - curx
|
|
444
|
+
@window.addstr(" " * remaining) if remaining > 0
|
|
445
|
+
else
|
|
446
|
+
@window.clrtoeol
|
|
447
|
+
end
|
|
425
448
|
break if cury == lines - 2 # lines include mode line
|
|
426
449
|
@window.setpos(cury + 1, 0)
|
|
427
450
|
@buffer.forward_char
|
|
@@ -441,7 +464,13 @@ module Textbringer
|
|
|
441
464
|
if cury == lines - 2
|
|
442
465
|
break
|
|
443
466
|
else
|
|
444
|
-
|
|
467
|
+
# Fill to end of line with region background if in region
|
|
468
|
+
if @in_region
|
|
469
|
+
remaining = columns - curx
|
|
470
|
+
@window.addstr(" " * remaining) if remaining > 0
|
|
471
|
+
else
|
|
472
|
+
@window.clrtoeol
|
|
473
|
+
end
|
|
445
474
|
@window.setpos(cury + 1, 0)
|
|
446
475
|
end
|
|
447
476
|
end
|
|
@@ -451,7 +480,7 @@ module Textbringer
|
|
|
451
480
|
@buffer.forward_char
|
|
452
481
|
end
|
|
453
482
|
if current? && @buffer.visible_mark
|
|
454
|
-
@window.attroff(
|
|
483
|
+
@window.attroff(region_attr)
|
|
455
484
|
end
|
|
456
485
|
@buffer.mark_to_point(@bottom_of_window)
|
|
457
486
|
if @buffer.point_at_mark?(point)
|
|
@@ -681,18 +710,30 @@ module Textbringer
|
|
|
681
710
|
@cursor.x = curx
|
|
682
711
|
if current? && @buffer.visible_mark
|
|
683
712
|
if @buffer.point_after_mark?(@buffer.visible_mark)
|
|
684
|
-
@window.attroff(
|
|
713
|
+
@window.attroff(region_attr)
|
|
714
|
+
@in_region = false
|
|
715
|
+
# Restore syntax highlighting colors after exiting region
|
|
716
|
+
if @current_highlight_attrs != 0
|
|
717
|
+
@window.attron(@current_highlight_attrs)
|
|
718
|
+
end
|
|
685
719
|
elsif @buffer.point_before_mark?(@buffer.visible_mark)
|
|
686
|
-
@window.attron(
|
|
720
|
+
@window.attron(region_attr)
|
|
721
|
+
@in_region = true
|
|
687
722
|
end
|
|
688
723
|
end
|
|
689
724
|
end
|
|
690
725
|
if current? && @buffer.visible_mark &&
|
|
691
726
|
@buffer.point_at_mark?(@buffer.visible_mark)
|
|
692
727
|
if @buffer.point_after_mark?(point)
|
|
693
|
-
@window.attroff(
|
|
728
|
+
@window.attroff(region_attr)
|
|
729
|
+
@in_region = false
|
|
730
|
+
# Restore syntax highlighting colors after exiting region
|
|
731
|
+
if @current_highlight_attrs != 0
|
|
732
|
+
@window.attron(@current_highlight_attrs)
|
|
733
|
+
end
|
|
694
734
|
elsif @buffer.point_before_mark?(point)
|
|
695
|
-
@window.attron(
|
|
735
|
+
@window.attron(region_attr)
|
|
736
|
+
@in_region = true
|
|
696
737
|
end
|
|
697
738
|
end
|
|
698
739
|
end
|
|
@@ -870,6 +911,10 @@ module Textbringer
|
|
|
870
911
|
@key_buffer.shift
|
|
871
912
|
end
|
|
872
913
|
end
|
|
914
|
+
|
|
915
|
+
def region_attr
|
|
916
|
+
@@has_colors ? Face[:region].attributes : Curses::A_REVERSE
|
|
917
|
+
end
|
|
873
918
|
end
|
|
874
919
|
|
|
875
920
|
class EchoArea < Window
|
|
@@ -916,6 +961,9 @@ module Textbringer
|
|
|
916
961
|
@window.addstr(@buffer.input_method_status)
|
|
917
962
|
end
|
|
918
963
|
@window.setpos(0, 0)
|
|
964
|
+
@window.attrset(0)
|
|
965
|
+
@in_region = false
|
|
966
|
+
@current_highlight_attrs = 0
|
|
919
967
|
if @message
|
|
920
968
|
@window.addstr(escape(@message))
|
|
921
969
|
else
|