rcurses 2.1 → 2.2
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/examples/focus_panes.rb +39 -0
- data/lib/rcurses/cursor.rb +19 -51
- data/lib/rcurses.rb +1 -1
- metadata +4 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: df1c1a4900f937e9e6b6b8ff3ca39d830d548c2e5a2627d57cdc058939b9aa02
|
4
|
+
data.tar.gz: 8098dc2b5bb4dca9a33a33d17dc6b91ecf496da7a18f6766990abcf036b6d7ff
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 9f6edc61f223b29c81c268f0141c75d0a7ea6b1a176da81dbd2fe8efadf3c9ddda6d0be90d69b170771a56b2e947c5422d720d676e6697ffc909f988e9de2123
|
7
|
+
data.tar.gz: a3dd0151452e7f910d2a1e2d9032a1b98c99df77d91bf7e3e9d3024391755d759625064d1d11404496f69b73d1bf08681a4286b82b058538cf45d32d80eeba44
|
@@ -0,0 +1,39 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require 'rcurses'
|
4
|
+
include Rcurses::Input
|
5
|
+
include Rcurses::Cursor
|
6
|
+
|
7
|
+
@max_h, @max_w = IO.console.winsize
|
8
|
+
@pane = []
|
9
|
+
@focused = 3 # Start with pane 3 so that the first keypress focuses back to Pane 0
|
10
|
+
hide_cursor
|
11
|
+
|
12
|
+
# Start by creating the panes; Format:
|
13
|
+
# pane = Rcurses::Pane.new( startx, starty, width, height, fg, bg)
|
14
|
+
pane_back = Rcurses::Pane.new( 1, 1, @max_w, @max_h, 255, 236)
|
15
|
+
@pane[0] = Rcurses::Pane.new( 4, 4, 20, 10, 236, 254)
|
16
|
+
@pane[1] = Rcurses::Pane.new( 30, 10, 16, 12, 232, 132)
|
17
|
+
@pane[2] = Rcurses::Pane.new( 8, 20, 30, 20, 136, 54)
|
18
|
+
@pane[3] = Rcurses::Pane.new( 50, 30, 24, 10, 206, 24)
|
19
|
+
|
20
|
+
pane_back.text = "PRESS ANY KEY TO SHIFT FOCUS. PRESS 'ESC' TO QUIT."
|
21
|
+
@pane.each_index { |i| @pane[i].text = "This is pane " + i.to_s }
|
22
|
+
pane_back.refresh
|
23
|
+
@pane.each_index { |i| @pane[i].refresh }
|
24
|
+
|
25
|
+
input = ''
|
26
|
+
while input != 'ESC'
|
27
|
+
input = getchr
|
28
|
+
@pane[@focused].border = false
|
29
|
+
@focused += 1
|
30
|
+
@focused = 0 if @focused == @pane.size
|
31
|
+
@pane[@focused].border = true
|
32
|
+
pane_back.refresh
|
33
|
+
@pane.each_index { |i| @pane[i].refresh }
|
34
|
+
@pane[@focused].refresh
|
35
|
+
end
|
36
|
+
col(1)
|
37
|
+
row(1)
|
38
|
+
clear_screen_down
|
39
|
+
show_cursor
|
data/lib/rcurses/cursor.rb
CHANGED
@@ -4,12 +4,8 @@ module Rcurses
|
|
4
4
|
module_function
|
5
5
|
ESC = "\e".freeze
|
6
6
|
CSI = "\e[".freeze
|
7
|
-
def save # Save current position
|
8
|
-
|
9
|
-
end
|
10
|
-
def restore # Restore cursor position
|
11
|
-
print(Gem.win_platform? ? CSI + 'u' : ESC + '8')
|
12
|
-
end
|
7
|
+
def save; print(Gem.win_platform? ? CSI + 's' : ESC + '7'); end # Save current position
|
8
|
+
def restore; print(Gem.win_platform? ? CSI + 'u' : ESC + '8'); end # Restore cursor position
|
13
9
|
def pos # Query cursor current position
|
14
10
|
res = ''
|
15
11
|
$stdin.raw do |stdin|
|
@@ -30,50 +26,22 @@ module Rcurses
|
|
30
26
|
_row, col = pos
|
31
27
|
col
|
32
28
|
end
|
33
|
-
def up(n = 1) # Move cursor up by n
|
34
|
-
|
35
|
-
end
|
36
|
-
def
|
37
|
-
|
38
|
-
end
|
39
|
-
def
|
40
|
-
|
41
|
-
end
|
42
|
-
def
|
43
|
-
|
44
|
-
end
|
45
|
-
def
|
46
|
-
|
47
|
-
end
|
48
|
-
def
|
49
|
-
|
50
|
-
end
|
51
|
-
def next_line # Move cursor down to beginning of next line
|
52
|
-
print(CSI + 'E' + CSI + "1G")
|
53
|
-
end
|
54
|
-
def prev_line # Move cursor up to beginning of previous line
|
55
|
-
print(CSI + 'A' + CSI + "1G")
|
56
|
-
end
|
57
|
-
def clear_char(n = 1) # Erase n characters from the current cursor position
|
58
|
-
print(CSI + "#{n}X")
|
59
|
-
end
|
60
|
-
def clear_line # Erase the entire current line and return to beginning of the line
|
61
|
-
print(CSI + '2K' + CSI + "1G")
|
62
|
-
end
|
63
|
-
def clear_line_before # Erase from the beginning of the line up to and including the current cursor position.
|
64
|
-
print(CSI + '1K')
|
65
|
-
end
|
66
|
-
def clear_line_after # Erase from the current position (inclusive) to the end of the line
|
67
|
-
print(CSI + '0K')
|
68
|
-
end
|
69
|
-
def clear_screen_down # Clear screen down from current row
|
70
|
-
print(CSI + 'J')
|
71
|
-
end
|
72
|
-
def scroll_up # Scroll display up one line
|
73
|
-
print(ESC + 'M')
|
74
|
-
end
|
75
|
-
def scroll_down # Scroll display down one line
|
76
|
-
print(ESC + 'D')
|
77
|
-
end
|
29
|
+
def up(n = 1); print(CSI + "#{(n)}A"); end # Move cursor up by n
|
30
|
+
def down(n = 1); print(CSI + "#{(n)}B"); end # Move the cursor down by n
|
31
|
+
def left(n = 1); print(CSI + "#{n}D"); end # Move the cursor backward by n
|
32
|
+
def right(n = 1); print(CSI + "#{n}C"); end # Move the cursor forward by n
|
33
|
+
def col(n = 1); print(CSI + "#{n}G"); end # Cursor moves to nth position horizontally in the current line
|
34
|
+
def row(n = 1); print(CSI + "#{n}d"); end # Cursor moves to the nth position vertically in the current column
|
35
|
+
def next_line; print(CSI + 'E' + CSI + "1G"); end # Move cursor down to beginning of next line
|
36
|
+
def prev_line; print(CSI + 'A' + CSI + "1G"); end # Move cursor up to beginning of previous line
|
37
|
+
def clear_char(n = 1); print(CSI + "#{n}X"); end # Erase n characters from the current cursor position
|
38
|
+
def clear_line; print(CSI + '2K' + CSI + "1G"); end # Erase the entire current line and return to beginning of the line
|
39
|
+
def clear_line_before; print(CSI + '1K'); end # Erase from the beginning of the line up to and including the current cursor position.
|
40
|
+
def clear_line_after; print(CSI + '0K'); end # Erase from the current position (inclusive) to the end of the line
|
41
|
+
def clear_screen_down; print(CSI + 'J'); end # Clear screen down from current row
|
42
|
+
def scroll_up; print(ESC + 'M'); end # Scroll display up one line
|
43
|
+
def scroll_down; print(ESC + 'D'); end # Scroll display down one line
|
44
|
+
def hide_cursor; print(CSI + '?25l'); end # Scroll display down one line
|
45
|
+
def show_cursor; print(CSI + '?25h'); end # Scroll display down one line
|
78
46
|
end
|
79
47
|
end
|
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: 2.
|
8
|
+
# Version: 2.2: Added example focus_panes.rb and hide_cursor/show_cursor as Cursor functions
|
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: '2.
|
4
|
+
version: '2.2'
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Geir Isene
|
@@ -28,8 +28,8 @@ description: 'Create panes (with the colors and(or border), manipulate the panes
|
|
28
28
|
add content. Dress up text (in panes or anywhere in the terminal) in bold, italic,
|
29
29
|
underline, reverse color, blink and in any 256 terminal colors for foreground and
|
30
30
|
background. Use a simple editor to let users edit text in panes. Left, right or
|
31
|
-
center align text in panes. Cursor movement around the terminal. New in 2.
|
32
|
-
|
31
|
+
center align text in panes. Cursor movement around the terminal. New in 2.2: Added
|
32
|
+
example focus_panes.rb and hide_cursor/show_cursor as Cursor functions.'
|
33
33
|
email: g@isene.com
|
34
34
|
executables: []
|
35
35
|
extensions: []
|
@@ -38,6 +38,7 @@ files:
|
|
38
38
|
- LICENSE
|
39
39
|
- README.md
|
40
40
|
- examples/basic_panes.rb
|
41
|
+
- examples/focus_panes.rb
|
41
42
|
- lib/rcurses.rb
|
42
43
|
- lib/rcurses/cursor.rb
|
43
44
|
- lib/rcurses/input.rb
|