rcurses 3.0 → 3.1
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/rcurses/pane.rb +70 -53
- data/lib/rcurses.rb +1 -1
- metadata +3 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 07bf042dcaa49e65d87441e77e32cb04f6d8738abe081979bc8589966b2ec65f
|
4
|
+
data.tar.gz: 234ad19f3e79216d0dd0561e2cfbb43318d7f308c596ab2a847eeda6fefe9563
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: d8d764879351431d6057dd1fa573ca2bba3134c207c8c4f1ad4f511d1d12ca93c392e163401a9592c18b6af48f590d7509e510592f4191bf156c89c1c89d644a
|
7
|
+
data.tar.gz: 8ffe0551b49238aa84ef6811d140c398a96736c92f77afd10afd0116431d6856d6472f619345b96827391a9b83d152965704f586119bcd56410b626100da71e1
|
data/lib/rcurses/pane.rb
CHANGED
@@ -8,22 +8,25 @@ module Rcurses
|
|
8
8
|
attr_accessor :moreup, :moredown
|
9
9
|
|
10
10
|
def initialize(x = 1, y = 1, w = 1, h = 1, fg = nil, bg = nil)
|
11
|
+
@max_h, @max_w = IO.console.winsize
|
11
12
|
@x = x
|
12
13
|
@y = y
|
13
14
|
@w = w
|
14
15
|
@h = h
|
15
16
|
@fg, @bg = fg, bg
|
16
|
-
@text = ""
|
17
|
-
@align = "l"
|
18
|
-
@scroll = true
|
19
|
-
@prompt = ""
|
20
|
-
@ix = 0
|
21
|
-
@
|
17
|
+
@text = "" # Initialize text variable
|
18
|
+
@align = "l" # Default alignment
|
19
|
+
@scroll = true # Enable scroll indicators
|
20
|
+
@prompt = "" # Prompt for editline
|
21
|
+
@ix = 0 # Starting text line index
|
22
|
+
@prev_frame = nil # Holds the previously rendered frame (array of lines)
|
23
|
+
@line = 0 # For cursor tracking during editing:
|
24
|
+
@pos = 0 # For cursor tracking during editing:
|
22
25
|
end
|
23
26
|
|
24
|
-
def move(
|
25
|
-
@x +=
|
26
|
-
@y +=
|
27
|
+
def move(dx, dy)
|
28
|
+
@x += dx
|
29
|
+
@y += dy
|
27
30
|
refresh
|
28
31
|
end
|
29
32
|
|
@@ -74,11 +77,13 @@ module Rcurses
|
|
74
77
|
refresh
|
75
78
|
end
|
76
79
|
|
77
|
-
#
|
80
|
+
# Diff-based refresh that minimizes flicker.
|
81
|
+
# Building a frame (an array of lines) that includes borders (if enabled).
|
82
|
+
# Content lines are wrapped in vertical border characters when @border is true.
|
78
83
|
def refresh(cont = @text)
|
79
84
|
@max_h, @max_w = IO.console.winsize
|
80
85
|
|
81
|
-
# Adjust pane dimensions
|
86
|
+
# Adjust pane dimensions and positions.
|
82
87
|
if @border
|
83
88
|
@w = @max_w - 2 if @w > @max_w - 2
|
84
89
|
@h = @max_h - 2 if @h > @max_h - 2
|
@@ -94,21 +99,26 @@ module Rcurses
|
|
94
99
|
# Save current cursor position.
|
95
100
|
o_row, o_col = pos
|
96
101
|
|
97
|
-
# Hide cursor
|
98
|
-
# Note: The alternate screen buffer means your program’s output won’t mix with the normal terminal content.
|
99
|
-
STDOUT.print "\e[?25l" # hide cursor
|
100
|
-
# Uncomment the next line to use the alternate screen buffer.
|
101
|
-
#STDOUT.print "\e[?1049h"
|
102
|
+
STDOUT.print "\e[?25l" # Hide cursor
|
102
103
|
|
103
|
-
buf = ""
|
104
|
-
buf << "\e[#{@y};#{@x}H" # Move cursor to start of pane.
|
105
104
|
fmt = [@fg, @bg].compact.join(',')
|
106
105
|
@txt = cont.split("\n")
|
107
106
|
@txt = textformat(cont) if @txt.any? { |line| line.pure.length >= @w }
|
108
107
|
@ix = @txt.length - 1 if @ix > @txt.length - 1
|
109
108
|
@ix = 0 if @ix < 0
|
110
109
|
|
111
|
-
|
110
|
+
# Build the new frame as an array of strings.
|
111
|
+
new_frame = []
|
112
|
+
if @border
|
113
|
+
# Top border spans (@w + 2) characters.
|
114
|
+
top_border = ("┌" + "─" * @w + "┐").c(fmt)
|
115
|
+
new_frame << top_border
|
116
|
+
end
|
117
|
+
|
118
|
+
# Build content lines.
|
119
|
+
content_rows = @h
|
120
|
+
content_rows.times do |i|
|
121
|
+
line_str = ""
|
112
122
|
l = @ix + i
|
113
123
|
if @txt[l].to_s != ""
|
114
124
|
pl = @w - @txt[l].pure.length
|
@@ -116,53 +126,60 @@ module Rcurses
|
|
116
126
|
hl = pl / 2
|
117
127
|
case @align
|
118
128
|
when "l"
|
119
|
-
|
129
|
+
line_str = @txt[l].c(fmt) + " ".c(fmt) * pl
|
120
130
|
when "r"
|
121
|
-
|
131
|
+
line_str = " ".c(fmt) * pl + @txt[l].c(fmt)
|
122
132
|
when "c"
|
123
|
-
|
133
|
+
line_str = " ".c(fmt) * hl + @txt[l].c(fmt) + " ".c(fmt) * (pl - hl)
|
124
134
|
end
|
125
135
|
else
|
126
|
-
|
136
|
+
line_str = " ".c(fmt) * @w
|
127
137
|
end
|
128
|
-
buf << "\e[#{@y + i + 1};#{@x}H" # Next line.
|
129
|
-
end
|
130
138
|
|
131
|
-
|
132
|
-
|
133
|
-
|
134
|
-
|
135
|
-
else
|
136
|
-
@moreup = false
|
137
|
-
end
|
139
|
+
# If border is enabled, add vertical border characters.
|
140
|
+
if @border
|
141
|
+
line_str = "│" + line_str + "│"
|
142
|
+
end
|
138
143
|
|
139
|
-
|
140
|
-
|
141
|
-
|
142
|
-
|
143
|
-
@
|
144
|
+
# Add scroll markers (overwrite the last character) if needed.
|
145
|
+
if i == 0 and @ix > 0 and @scroll
|
146
|
+
line_str[-1] = "∆".c(fmt)
|
147
|
+
@moreup = true
|
148
|
+
elsif i == content_rows - 1 and @txt.length - @ix > @h and @scroll
|
149
|
+
line_str[-1] = "∇".c(fmt)
|
150
|
+
@moredown = true
|
151
|
+
else
|
152
|
+
@moreup = false
|
153
|
+
@moredown = false
|
154
|
+
end
|
155
|
+
new_frame << line_str
|
144
156
|
end
|
145
157
|
|
146
|
-
# Draw border if enabled.
|
147
158
|
if @border
|
148
|
-
|
149
|
-
@
|
150
|
-
|
151
|
-
buf << "\e[#{@y + i};#{@x + @w}H" << "│".c(fmt)
|
152
|
-
end
|
153
|
-
buf << "\e[#{@y + @h};#{@x - 1}H" << ("└" + "─" * @w + "┘").c(fmt)
|
159
|
+
# Bottom border.
|
160
|
+
bottom_border = ("└" + "─" * @w + "┘").c(fmt)
|
161
|
+
new_frame << bottom_border
|
154
162
|
end
|
155
163
|
|
156
|
-
#
|
157
|
-
|
158
|
-
|
159
|
-
|
160
|
-
|
164
|
+
# Diff-based update: update only lines that changed.
|
165
|
+
diff_buf = ""
|
166
|
+
new_frame.each_with_index do |line, i|
|
167
|
+
# Determine row number:
|
168
|
+
row_num = @border ? (@y - 1 + i) : (@y + i)
|
169
|
+
# When border is enabled, all lines (including content) start at column (@x - 1)
|
170
|
+
col_num = @border ? (@x - 1) : @x
|
171
|
+
if @prev_frame.nil? || @prev_frame[i] != line ||
|
172
|
+
(@border && (i == 0 || i == new_frame.size - 1))
|
173
|
+
diff_buf << "\e[#{row_num};#{col_num}H" << line
|
174
|
+
end
|
175
|
+
end
|
161
176
|
|
162
|
-
|
163
|
-
|
177
|
+
diff_buf << "\e[#{o_row};#{o_col}H"
|
178
|
+
print diff_buf
|
179
|
+
#STDOUT.print "\e[?25h" # Show cursor - but use Cursor.show instead if needed
|
164
180
|
|
165
|
-
@
|
181
|
+
@prev_frame = new_frame
|
182
|
+
new_frame.join("\n")
|
166
183
|
end
|
167
184
|
|
168
185
|
def textformat(cont)
|
@@ -439,7 +456,7 @@ module Rcurses
|
|
439
456
|
def calculate_posx
|
440
457
|
total_length = 0
|
441
458
|
(@ix + @line).times do |i|
|
442
|
-
total_length += @txt[i].pure.length + 1 # +1 for
|
459
|
+
total_length += @txt[i].pure.length + 1 # +1 for newline
|
443
460
|
end
|
444
461
|
total_length += @pos
|
445
462
|
total_length
|
data/lib/rcurses.rb
CHANGED
@@ -5,7 +5,7 @@
|
|
5
5
|
# Web_site: http://isene.com/
|
6
6
|
# Github: https://github.com/isene/rcurses
|
7
7
|
# License: Public domain
|
8
|
-
# Version: 3.
|
8
|
+
# Version: 3.1: Flicker reduction by diff rendering
|
9
9
|
|
10
10
|
require 'io/console' # Basic gem for rcurses
|
11
11
|
require 'io/wait' # stdin handling
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: rcurses
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: '3.
|
4
|
+
version: '3.1'
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Geir Isene
|
@@ -29,8 +29,8 @@ description: 'Create curses applications for the terminal easier than ever. Crea
|
|
29
29
|
up text (in panes or anywhere in the terminal) in bold, italic, underline, reverse
|
30
30
|
color, blink and in any 256 terminal colors for foreground and background. Use a
|
31
31
|
simple editor to let users edit text in panes. Left, right or center align text
|
32
|
-
in panes. Cursor movement around the terminal. New in 3.
|
33
|
-
|
32
|
+
in panes. Cursor movement around the terminal. New in 3.1: Flicker reduction by
|
33
|
+
diff rendering.'
|
34
34
|
email: g@isene.com
|
35
35
|
executables: []
|
36
36
|
extensions: []
|