textbringer 16 → 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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 0b838b91740f3985ebcdc6987e72ea7fe9daa28ad0b273a6f6e0f309818778a6
4
- data.tar.gz: 51a55425c1cdaefb69b74451c3c9091f85138549a27a60e8ebb23161b4530847
3
+ metadata.gz: afebafd9a22024be2bc3c4c5c2140ac9ad3b7fa7a1efc25e0ae9bf4d38c3da10
4
+ data.tar.gz: 53841ecd93d7b63e9d33a07d39721f90bf0d39e6803406287518601d67d4a59c
5
5
  SHA512:
6
- metadata.gz: 128afb2fe777b9847ace11badce3121391576a98b7caba7f5bdb93faf4383e00b15db4ae23e263e8f1a26fc79ef1b3fa5b12d02e6ae8b590533088c680ef3532
7
- data.tar.gz: 4e082735768a0d2647abf67ca9c7a5268ba6607fe59462de26dff2e59caca272c68224e061791cad58d6f81648bb17c9031b880361a56ce93912b3e27c487457
6
+ metadata.gz: 469ef80d72998003e1d5ca9e6c499b70debc5d1c2c09b43b9b79311e94ce15c22adbd766bf31cafaa20a5ac11a19c8b12d9c8392d166cec5a617305c4a50e43f
7
+ data.tar.gz: 6908288f0debd4001c131327071962fda1392ff0310f26fc72b9f0391b01e281b22824c78e78d2be69cd89b5fc768c7239d116bd35699d1483c4fa944aae76be
@@ -2,4 +2,5 @@ module Textbringer
2
2
  Face.define :mode_line, reverse: true
3
3
  Face.define :link, foreground: "blue", bold: true
4
4
  Face.define :control
5
+ Face.define :region, background: "blue"
5
6
  end
@@ -1,3 +1,3 @@
1
1
  module Textbringer
2
- VERSION = "16"
2
+ VERSION = "17"
3
3
  end
@@ -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(Curses::A_REVERSE)
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
- @window.attroff(attrs)
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
- @window.attron(attrs)
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
- @window.clrtoeol
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
- @window.clrtoeol
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(Curses::A_REVERSE)
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(Curses::A_REVERSE)
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(Curses::A_REVERSE)
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(Curses::A_REVERSE)
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(Curses::A_REVERSE)
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
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: textbringer
3
3
  version: !ruby/object:Gem::Version
4
- version: '16'
4
+ version: '17'
5
5
  platform: ruby
6
6
  authors:
7
7
  - Shugo Maeda