reline 0.2.8.pre.3 → 0.2.8.pre.4

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 92eb26edb27bc79f95c9f54a4396b86e764acb928a4d704db8b8d1016331aa67
4
- data.tar.gz: 04b7af1f6107bc8cd302494a057e6cfd812c60ec3768b3cd475105d8e119d20c
3
+ metadata.gz: 5e7c5785424de4deda942cdd54cab39bc7d96fd79b1451095626996b875a32d9
4
+ data.tar.gz: 3afcf3fc84d2b3d4dd48481bca613a8fc08de049983619772e9fcd502caffa83
5
5
  SHA512:
6
- metadata.gz: 40503d95634408feb981bcb3448679ed6c847123465b5b965399c75c4bbc9ac0ddbb5422386d209613e45b34a85f2ecb275fac7587272da88de7a16b2feb40b0
7
- data.tar.gz: '030383e1c77101f296344c794443439af32c6fd7f2f86f0230666287df901e5aea9f25d78242ab9ea16253ab17faa97c02fc234137e166a71edbac2de2f44f16'
6
+ metadata.gz: c1be959cdf8fc499ec71184bc3768964dbc1eb078085bbd8303a6d9b4b0ade3ccd25a8d90486c620316b38c4dfe7b7fb224d99912ff855bd8bc3fc64946f1d5d
7
+ data.tar.gz: cfe31c94298208f8cda2c7fddeba8940e71589c60b06167fcb81e8c0d278055ffd94261713d1aa3a2d6031d6572c3dc9194412d15e57f83d0fb81e87361496c0
@@ -499,6 +499,14 @@ class Reline::LineEditor
499
499
  @line_editor.call_completion_proc_with_checking_args(pre, target, post)
500
500
  end
501
501
 
502
+ def set_dialog(dialog)
503
+ @dialog = dialog
504
+ end
505
+
506
+ def dialog
507
+ @dialog
508
+ end
509
+
502
510
  def set_cursor_pos(col, row)
503
511
  @cursor_pos.x = col
504
512
  @cursor_pos.y = row
@@ -531,11 +539,12 @@ class Reline::LineEditor
531
539
 
532
540
  class Dialog
533
541
  attr_reader :name
534
- attr_accessor :column, :vertical_offset, :contents, :lines_backup
542
+ attr_accessor :scroll_top, :column, :vertical_offset, :contents, :lines_backup
535
543
 
536
544
  def initialize(name, proc_scope)
537
545
  @name = name
538
546
  @proc_scope = proc_scope
547
+ @scroll_top = 0
539
548
  end
540
549
 
541
550
  def set_cursor_pos(col, row)
@@ -543,6 +552,7 @@ class Reline::LineEditor
543
552
  end
544
553
 
545
554
  def call
555
+ @proc_scope.set_dialog(self)
546
556
  @proc_scope.call
547
557
  end
548
558
  end
@@ -566,13 +576,28 @@ class Reline::LineEditor
566
576
  return
567
577
  end
568
578
  dialog.set_cursor_pos(cursor_column, @first_line_started_from + @started_from)
569
- pos, result, pointer, bg = dialog.call
579
+ dialog_render_info = dialog.call
570
580
  old_dialog_contents = dialog.contents
571
581
  old_dialog_column = dialog.column
572
582
  old_dialog_vertical_offset = dialog.vertical_offset
573
- if result and not result.empty?
574
- dialog.contents = result
575
- dialog.contents = dialog.contents[0...DIALOG_HEIGHT] if dialog.contents.size > DIALOG_HEIGHT
583
+ start = 0
584
+ if dialog_render_info and dialog_render_info.contents and not dialog_render_info.contents.empty?
585
+ height = dialog_render_info.height || DIALOG_HEIGHT
586
+ pointer = dialog_render_info.pointer
587
+ dialog.contents = dialog_render_info.contents
588
+ if dialog.contents.size > height
589
+ if dialog_render_info.pointer
590
+ if dialog_render_info.pointer < 0
591
+ dialog.scroll_top = 0
592
+ elsif (dialog_render_info.pointer - dialog.scroll_top) >= (height - 1)
593
+ dialog.scroll_top = dialog_render_info.pointer - (height - 1)
594
+ elsif (dialog_render_info.pointer - dialog.scroll_top) < 0
595
+ dialog.scroll_top = dialog_render_info.pointer
596
+ end
597
+ pointer = dialog_render_info.pointer - dialog.scroll_top
598
+ end
599
+ dialog.contents = dialog.contents[dialog.scroll_top, height]
600
+ end
576
601
  else
577
602
  dialog.lines_backup = {
578
603
  lines: modify_lines(whole_lines),
@@ -587,21 +612,21 @@ class Reline::LineEditor
587
612
  end
588
613
  upper_space = @first_line_started_from - @started_from
589
614
  lower_space = @highest_in_all - @first_line_started_from - @started_from - 1
590
- dialog.column = pos.x
615
+ dialog.column = dialog_render_info.pos.x
591
616
  diff = (dialog.column + DIALOG_WIDTH) - (@screen_size.last - 1)
592
617
  if diff > 0
593
618
  dialog.column -= diff
594
619
  end
595
- if (lower_space + @rest_height) >= DIALOG_HEIGHT
596
- dialog.vertical_offset = pos.y + 1
597
- elsif upper_space >= DIALOG_HEIGHT
598
- dialog.vertical_offset = pos.y + -(DIALOG_HEIGHT + 1)
620
+ if (lower_space + @rest_height - dialog_render_info.pos.y) >= height
621
+ dialog.vertical_offset = dialog_render_info.pos.y + 1
622
+ elsif upper_space >= height
623
+ dialog.vertical_offset = dialog_render_info.pos.y + -(height + 1)
599
624
  else
600
- if (lower_space + @rest_height) < DIALOG_HEIGHT
601
- scroll_down(DIALOG_HEIGHT)
602
- move_cursor_up(DIALOG_HEIGHT)
625
+ if (lower_space + @rest_height - dialog_render_info.pos.y) < height
626
+ scroll_down(height + dialog_render_info.pos.y)
627
+ move_cursor_up(height + dialog_render_info.pos.y)
603
628
  end
604
- dialog.vertical_offset = pos.y + 1
629
+ dialog.vertical_offset = dialog_render_info.pos.y + 1
605
630
  end
606
631
  Reline::IOGate.hide_cursor
607
632
  reset_dialog(dialog, old_dialog_contents, old_dialog_column, old_dialog_vertical_offset)
@@ -611,8 +636,8 @@ class Reline::LineEditor
611
636
  if i == pointer
612
637
  bg_color = '45'
613
638
  else
614
- if bg
615
- bg_color = bg
639
+ if dialog_render_info.bg_color
640
+ bg_color = dialog_render_info.bg_color
616
641
  else
617
642
  bg_color = '46'
618
643
  end
@@ -1,3 +1,3 @@
1
1
  module Reline
2
- VERSION = '0.2.8.pre.3'
2
+ VERSION = '0.2.8.pre.4'
3
3
  end
data/lib/reline.rb CHANGED
@@ -18,6 +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
22
 
22
23
  class Core
23
24
  ATTR_READER_NAMES = %i(
@@ -219,9 +220,9 @@ module Reline
219
220
  cursor_pos_to_render = Reline::CursorPos.new(x, y)
220
221
  if context and context.is_a?(Array)
221
222
  context.clear
222
- context.push(cursor_pos_to_render, result, pointer)
223
+ context.push(cursor_pos_to_render, result, pointer, dialog)
223
224
  end
224
- [cursor_pos_to_render, result, pointer, nil]
225
+ DialogRenderInfo.new(pos: cursor_pos_to_render, contents: result, pointer: pointer, height: 15)
225
226
  }
226
227
  Reline::DEFAULT_DIALOG_CONTEXT = Array.new
227
228
 
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.3
4
+ version: 0.2.8.pre.4
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-29 00:00:00.000000000 Z
11
+ date: 2021-08-30 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: io-console