reline 0.2.8.pre.4 → 0.2.8.pre.5
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/reline/line_editor.rb +55 -45
- data/lib/reline/unicode.rb +6 -5
- data/lib/reline/version.rb +1 -1
- data/lib/reline.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: fca2b6f76f8c59a18589d6d730f7f159e25b95e639ae7d6866f772e9bb2655ab
|
4
|
+
data.tar.gz: 61b69c3d01f74b957c6a2d646e58021cad4b49031d4fdf6437f2303d417d5f36
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 561ffdbf39c095852f0a642178d5328329cea072fdc91c32bd11edfdcecb4846414006961b6fe7adbf63c825022a8634d5a563fdeb574d127088b536967e1f9c
|
7
|
+
data.tar.gz: 07e62e55ca7a45d3b747724823b26af09d109f9620ba82914cfaf7e6100251bb76bd0de7b01b9829b51e41248a32b028bbbb3617c7d4eedfc2c1d05ab701a236
|
data/lib/reline/line_editor.rb
CHANGED
@@ -538,12 +538,13 @@ class Reline::LineEditor
|
|
538
538
|
end
|
539
539
|
|
540
540
|
class Dialog
|
541
|
-
attr_reader :name
|
542
|
-
attr_accessor :scroll_top, :column, :vertical_offset, :
|
541
|
+
attr_reader :name, :contents, :width
|
542
|
+
attr_accessor :scroll_top, :column, :vertical_offset, :lines_backup
|
543
543
|
|
544
544
|
def initialize(name, proc_scope)
|
545
545
|
@name = name
|
546
546
|
@proc_scope = proc_scope
|
547
|
+
@width = nil
|
547
548
|
@scroll_top = 0
|
548
549
|
end
|
549
550
|
|
@@ -551,6 +552,17 @@ class Reline::LineEditor
|
|
551
552
|
@proc_scope.set_cursor_pos(col, row)
|
552
553
|
end
|
553
554
|
|
555
|
+
def width=(v)
|
556
|
+
@width = v
|
557
|
+
end
|
558
|
+
|
559
|
+
def contents=(contents)
|
560
|
+
@contents = contents
|
561
|
+
if contents and @width.nil?
|
562
|
+
@width = contents.map{ |line| Reline::Unicode.calculate_width(line, true) }.max
|
563
|
+
end
|
564
|
+
end
|
565
|
+
|
554
566
|
def call
|
555
567
|
@proc_scope.set_dialog(self)
|
556
568
|
@proc_scope.call
|
@@ -577,10 +589,8 @@ class Reline::LineEditor
|
|
577
589
|
end
|
578
590
|
dialog.set_cursor_pos(cursor_column, @first_line_started_from + @started_from)
|
579
591
|
dialog_render_info = dialog.call
|
580
|
-
|
581
|
-
|
582
|
-
old_dialog_vertical_offset = dialog.vertical_offset
|
583
|
-
start = 0
|
592
|
+
dialog.width = dialog_render_info.width if dialog_render_info and dialog_render_info.width
|
593
|
+
old_dialog = dialog.clone
|
584
594
|
if dialog_render_info and dialog_render_info.contents and not dialog_render_info.contents.empty?
|
585
595
|
height = dialog_render_info.height || DIALOG_HEIGHT
|
586
596
|
pointer = dialog_render_info.pointer
|
@@ -613,7 +623,7 @@ class Reline::LineEditor
|
|
613
623
|
upper_space = @first_line_started_from - @started_from
|
614
624
|
lower_space = @highest_in_all - @first_line_started_from - @started_from - 1
|
615
625
|
dialog.column = dialog_render_info.pos.x
|
616
|
-
diff = (dialog.column +
|
626
|
+
diff = (dialog.column + dialog.width) - (@screen_size.last - 1)
|
617
627
|
if diff > 0
|
618
628
|
dialog.column -= diff
|
619
629
|
end
|
@@ -629,7 +639,7 @@ class Reline::LineEditor
|
|
629
639
|
dialog.vertical_offset = dialog_render_info.pos.y + 1
|
630
640
|
end
|
631
641
|
Reline::IOGate.hide_cursor
|
632
|
-
reset_dialog(dialog,
|
642
|
+
reset_dialog(dialog, old_dialog)
|
633
643
|
move_cursor_down(dialog.vertical_offset)
|
634
644
|
Reline::IOGate.move_cursor_column(dialog.column)
|
635
645
|
dialog.contents.each_with_index do |item, i|
|
@@ -642,7 +652,7 @@ class Reline::LineEditor
|
|
642
652
|
bg_color = '46'
|
643
653
|
end
|
644
654
|
end
|
645
|
-
@output.write "\e[#{bg_color}m%-#{
|
655
|
+
@output.write "\e[#{bg_color}m%-#{dialog.width}s\e[49m" % Reline::Unicode.take_range(item, 0, dialog.width)
|
646
656
|
Reline::IOGate.move_cursor_column(dialog.column)
|
647
657
|
move_cursor_down(1) if i < (dialog.contents.size - 1)
|
648
658
|
end
|
@@ -658,8 +668,8 @@ class Reline::LineEditor
|
|
658
668
|
}
|
659
669
|
end
|
660
670
|
|
661
|
-
private def reset_dialog(dialog,
|
662
|
-
return if dialog.lines_backup.nil? or
|
671
|
+
private def reset_dialog(dialog, old_dialog)
|
672
|
+
return if dialog.lines_backup.nil? or old_dialog.contents.nil?
|
663
673
|
prompt, prompt_width, prompt_list = check_multiline_prompt(dialog.lines_backup[:lines], prompt)
|
664
674
|
visual_lines = []
|
665
675
|
visual_start = nil
|
@@ -675,76 +685,76 @@ class Reline::LineEditor
|
|
675
685
|
old_y = dialog.lines_backup[:first_line_started_from] + dialog.lines_backup[:started_from]
|
676
686
|
y = @first_line_started_from + @started_from
|
677
687
|
y_diff = y - old_y
|
678
|
-
if (old_y +
|
688
|
+
if (old_y + old_dialog.vertical_offset) < (y + dialog.vertical_offset)
|
679
689
|
# rerender top
|
680
|
-
move_cursor_down(
|
681
|
-
start = visual_start +
|
682
|
-
line_num = dialog.vertical_offset -
|
690
|
+
move_cursor_down(old_dialog.vertical_offset - y_diff)
|
691
|
+
start = visual_start + old_dialog.vertical_offset
|
692
|
+
line_num = dialog.vertical_offset - old_dialog.vertical_offset
|
683
693
|
line_num.times do |i|
|
684
|
-
Reline::IOGate.move_cursor_column(
|
694
|
+
Reline::IOGate.move_cursor_column(old_dialog.column)
|
685
695
|
if visual_lines[start + i].nil?
|
686
|
-
s = ' ' *
|
696
|
+
s = ' ' * dialog.width
|
687
697
|
else
|
688
|
-
s = Reline::Unicode.take_range(visual_lines[start + i],
|
698
|
+
s = Reline::Unicode.take_range(visual_lines[start + i], old_dialog.column, dialog.width)
|
689
699
|
end
|
690
|
-
@output.write "\e[39m\e[49m%-#{
|
700
|
+
@output.write "\e[39m\e[49m%-#{dialog.width}s\e[39m\e[49m" % s
|
691
701
|
move_cursor_down(1) if i < (line_num - 1)
|
692
702
|
end
|
693
|
-
move_cursor_up(
|
703
|
+
move_cursor_up(old_dialog.vertical_offset + line_num - 1 - y_diff)
|
694
704
|
end
|
695
|
-
if (old_y +
|
705
|
+
if (old_y + old_dialog.vertical_offset + old_dialog.contents.size) > (y + dialog.vertical_offset + dialog.contents.size)
|
696
706
|
# rerender bottom
|
697
707
|
move_cursor_down(dialog.vertical_offset + dialog.contents.size - y_diff)
|
698
708
|
start = visual_start + dialog.vertical_offset + dialog.contents.size
|
699
|
-
line_num = (
|
709
|
+
line_num = (old_dialog.vertical_offset + old_dialog.contents.size) - (dialog.vertical_offset + dialog.contents.size)
|
700
710
|
line_num.times do |i|
|
701
|
-
Reline::IOGate.move_cursor_column(
|
711
|
+
Reline::IOGate.move_cursor_column(old_dialog.column)
|
702
712
|
if visual_lines[start + i].nil?
|
703
|
-
s = ' ' *
|
713
|
+
s = ' ' * dialog.width
|
704
714
|
else
|
705
|
-
s = Reline::Unicode.take_range(visual_lines[start + i],
|
715
|
+
s = Reline::Unicode.take_range(visual_lines[start + i], old_dialog.column, dialog.width)
|
706
716
|
end
|
707
|
-
@output.write "\e[39m\e[49m%-#{
|
717
|
+
@output.write "\e[39m\e[49m%-#{dialog.width}s\e[39m\e[49m" % s
|
708
718
|
move_cursor_down(1) if i < (line_num - 1)
|
709
719
|
end
|
710
720
|
move_cursor_up(dialog.vertical_offset + dialog.contents.size + line_num - 1 - y_diff)
|
711
721
|
end
|
712
|
-
if
|
722
|
+
if old_dialog.column < dialog.column
|
713
723
|
# rerender left
|
714
|
-
move_cursor_down(
|
715
|
-
width = dialog.column -
|
716
|
-
start = visual_start +
|
717
|
-
line_num =
|
724
|
+
move_cursor_down(old_dialog.vertical_offset - y_diff)
|
725
|
+
width = dialog.column - old_dialog.column
|
726
|
+
start = visual_start + old_dialog.vertical_offset
|
727
|
+
line_num = old_dialog.contents.size
|
718
728
|
line_num.times do |i|
|
719
|
-
Reline::IOGate.move_cursor_column(
|
729
|
+
Reline::IOGate.move_cursor_column(old_dialog.column)
|
720
730
|
if visual_lines[start + i].nil?
|
721
731
|
s = ' ' * width
|
722
732
|
else
|
723
|
-
s = Reline::Unicode.take_range(visual_lines[start + i],
|
733
|
+
s = Reline::Unicode.take_range(visual_lines[start + i], old_dialog.column, width)
|
724
734
|
end
|
725
735
|
@output.write "\e[39m\e[49m%-#{width}s\e[39m\e[49m" % s
|
726
736
|
move_cursor_down(1) if i < (line_num - 1)
|
727
737
|
end
|
728
|
-
move_cursor_up(
|
738
|
+
move_cursor_up(old_dialog.vertical_offset + line_num - 1 - y_diff)
|
729
739
|
end
|
730
|
-
if (
|
740
|
+
if (old_dialog.column + old_dialog.width) > (dialog.column + dialog.width)
|
731
741
|
# rerender right
|
732
|
-
move_cursor_down(
|
733
|
-
width = (
|
734
|
-
start = visual_start +
|
735
|
-
line_num =
|
742
|
+
move_cursor_down(old_dialog.vertical_offset + y_diff)
|
743
|
+
width = (old_dialog.column + old_dialog.width) - (dialog.column + dialog.width)
|
744
|
+
start = visual_start + old_dialog.vertical_offset
|
745
|
+
line_num = old_dialog.contents.size
|
736
746
|
line_num.times do |i|
|
737
|
-
Reline::IOGate.move_cursor_column(
|
747
|
+
Reline::IOGate.move_cursor_column(old_dialog.column + dialog.width)
|
738
748
|
if visual_lines[start + i].nil?
|
739
749
|
s = ' ' * width
|
740
750
|
else
|
741
|
-
s = Reline::Unicode.take_range(visual_lines[start + i],
|
751
|
+
s = Reline::Unicode.take_range(visual_lines[start + i], old_dialog.column + dialog.width, width)
|
742
752
|
end
|
743
|
-
Reline::IOGate.move_cursor_column(dialog.column +
|
753
|
+
Reline::IOGate.move_cursor_column(dialog.column + dialog.width)
|
744
754
|
@output.write "\e[39m\e[49m%-#{width}s\e[39m\e[49m" % s
|
745
755
|
move_cursor_down(1) if i < (line_num - 1)
|
746
756
|
end
|
747
|
-
move_cursor_up(
|
757
|
+
move_cursor_up(old_dialog.vertical_offset + line_num - 1 + y_diff)
|
748
758
|
end
|
749
759
|
Reline::IOGate.move_cursor_column((prompt_width + @cursor) % @screen_size.last)
|
750
760
|
end
|
@@ -778,10 +788,10 @@ class Reline::LineEditor
|
|
778
788
|
dialog_vertical_size.times do |i|
|
779
789
|
if i < visual_lines_under_dialog.size
|
780
790
|
Reline::IOGate.move_cursor_column(0)
|
781
|
-
@output.write "\e[39m\e[49m%-#{
|
791
|
+
@output.write "\e[39m\e[49m%-#{dialog.width}s\e[39m\e[49m" % visual_lines_under_dialog[i]
|
782
792
|
else
|
783
793
|
Reline::IOGate.move_cursor_column(dialog.column)
|
784
|
-
@output.write "\e[39m\e[49m#{' ' *
|
794
|
+
@output.write "\e[39m\e[49m#{' ' * dialog.width}\e[39m\e[49m"
|
785
795
|
end
|
786
796
|
Reline::IOGate.erase_after_cursor
|
787
797
|
move_cursor_down(1) if i < (dialog_vertical_size - 1)
|
data/lib/reline/unicode.rb
CHANGED
@@ -186,9 +186,9 @@ class Reline::Unicode
|
|
186
186
|
end
|
187
187
|
|
188
188
|
# Take a chunk of a String with escape sequences.
|
189
|
-
def self.take_range(str,
|
189
|
+
def self.take_range(str, start_col, max_width, encoding = str.encoding)
|
190
190
|
chunk = String.new(encoding: encoding)
|
191
|
-
|
191
|
+
total_width = 0
|
192
192
|
rest = str.encode(Encoding::UTF_8)
|
193
193
|
in_zero_width = false
|
194
194
|
rest.scan(WIDTH_SCANNER) do |gc|
|
@@ -206,9 +206,10 @@ class Reline::Unicode
|
|
206
206
|
if in_zero_width
|
207
207
|
chunk << gc
|
208
208
|
else
|
209
|
-
|
210
|
-
|
211
|
-
|
209
|
+
mbchar_width = get_mbchar_width(gc)
|
210
|
+
total_width += mbchar_width
|
211
|
+
break if (start_col + max_width) < total_width
|
212
|
+
chunk << gc if start_col < total_width
|
212
213
|
end
|
213
214
|
end
|
214
215
|
end
|
data/lib/reline/version.rb
CHANGED
data/lib/reline.rb
CHANGED
@@ -18,7 +18,7 @@ module Reline
|
|
18
18
|
|
19
19
|
Key = Struct.new('Key', :char, :combined_char, :with_meta)
|
20
20
|
CursorPos = Struct.new(:x, :y)
|
21
|
-
DialogRenderInfo = Struct.new(:pos, :contents, :pointer, :bg_color, :height, keyword_init: true)
|
21
|
+
DialogRenderInfo = Struct.new(:pos, :contents, :pointer, :bg_color, :width, :height, keyword_init: true)
|
22
22
|
|
23
23
|
class Core
|
24
24
|
ATTR_READER_NAMES = %i(
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: reline
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.2.8.pre.
|
4
|
+
version: 0.2.8.pre.5
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- aycabta
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2021-08-
|
11
|
+
date: 2021-08-31 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: io-console
|