rcurses 2.0 → 2.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/LICENSE +24 -0
- data/{rcurses_example.rb → examples/basic_panes.rb} +1 -1
- data/lib/rcurses/cursor.rb +79 -0
- data/lib/rcurses/input.rb +83 -0
- data/lib/rcurses/pane.rb +494 -0
- data/lib/rcurses.rb +5 -699
- data/lib/string_extensions.rb +34 -0
- metadata +11 -8
- data/extconf.rb +0 -33
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: c193555f436c0c4c0b2b3f41c8ba4045987ac9f35bdbc8258c0018584ef79f8a
|
4
|
+
data.tar.gz: e704f5c7356ebc779a23092de1b50c54b6aea1b50703578b3614fe82dd04e3bc
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 4cb46397b2629300cb28caec54f0fcf2679f51a8e1417f8f4f89be7e7fde4da6245c532af54a8a53d98eb71e4a17ddb9a8cee3727f452e6d94f08997c6d87e3b
|
7
|
+
data.tar.gz: d90157ceb59ddafd9679d5f164339d3fe0a540a2fc3d25f5abfb825aadcfb35b49f704c5589caaf1b8fac07a7fca23521cb495f31f4ac327f663399cb0599e0e
|
data/LICENSE
ADDED
@@ -0,0 +1,24 @@
|
|
1
|
+
This is free and unencumbered software released into the public domain.
|
2
|
+
|
3
|
+
Anyone is free to copy, modify, publish, use, compile, sell, or
|
4
|
+
distribute this software, either in source code form or as a compiled
|
5
|
+
binary, for any purpose, commercial or non-commercial, and by any
|
6
|
+
means.
|
7
|
+
|
8
|
+
In jurisdictions that recognize copyright laws, the author or authors
|
9
|
+
of this software dedicate any and all copyright interest in the
|
10
|
+
software to the public domain. We make this dedication for the benefit
|
11
|
+
of the public at large and to the detriment of our heirs and
|
12
|
+
successors. We intend this dedication to be an overt act of
|
13
|
+
relinquishment in perpetuity of all present and future rights to this
|
14
|
+
software under copyright law.
|
15
|
+
|
16
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
17
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
18
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
|
19
|
+
IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR
|
20
|
+
OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
|
21
|
+
ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
|
22
|
+
OTHER DEALINGS IN THE SOFTWARE.
|
23
|
+
|
24
|
+
For more information, please refer to <https://unlicense.org>
|
@@ -16,7 +16,7 @@ pane_left.border = true # Adding a border to the left pane
|
|
16
16
|
# Add content to the panes
|
17
17
|
pane_top.text = Time.now.to_s[0..15].b + " Welcome to the rcurses example program"
|
18
18
|
pane_left.text = `ls --color`
|
19
|
-
pane_right.text = "Output of
|
19
|
+
pane_right.text = "Output of free:\n\n" + `free`
|
20
20
|
pane_bottom.prompt = "Enter any text and press ENTER: ".b # The prompt text before the user starts writing content
|
21
21
|
|
22
22
|
pane_top.refresh # This is the order of drawing/refreshing the panes
|
@@ -0,0 +1,79 @@
|
|
1
|
+
module Rcurses
|
2
|
+
module Cursor
|
3
|
+
# Terminal cursor movement ANSI codes (inspired by https://github.com/piotrmurach/tty-cursor)
|
4
|
+
module_function
|
5
|
+
ESC = "\e".freeze
|
6
|
+
CSI = "\e[".freeze
|
7
|
+
def save # Save current position
|
8
|
+
print(Gem.win_platform? ? CSI + 's' : ESC + '7')
|
9
|
+
end
|
10
|
+
def restore # Restore cursor position
|
11
|
+
print(Gem.win_platform? ? CSI + 'u' : ESC + '8')
|
12
|
+
end
|
13
|
+
def pos # Query cursor current position
|
14
|
+
res = ''
|
15
|
+
$stdin.raw do |stdin|
|
16
|
+
$stdout << CSI + '6n' # The actual ANSI get-position
|
17
|
+
$stdout.flush
|
18
|
+
while (c = stdin.getc) != 'R'
|
19
|
+
res << c if c
|
20
|
+
end
|
21
|
+
end
|
22
|
+
m = res.match(/(?<row>\d+);(?<col>\d+)/)
|
23
|
+
return m[:row].to_i, m[:col].to_i
|
24
|
+
end
|
25
|
+
def rowget
|
26
|
+
row, _col = pos
|
27
|
+
row
|
28
|
+
end
|
29
|
+
def colget
|
30
|
+
_row, col = pos
|
31
|
+
col
|
32
|
+
end
|
33
|
+
def up(n = 1) # Move cursor up by n
|
34
|
+
print(CSI + "#{(n || 1)}A")
|
35
|
+
end
|
36
|
+
def down(n = 1) # Move the cursor down by n
|
37
|
+
print(CSI + "#{(n || 1)}B")
|
38
|
+
end
|
39
|
+
def left(n = 1) # Move the cursor backward by n
|
40
|
+
print(CSI + "#{n || 1}D")
|
41
|
+
end
|
42
|
+
def right(n = 1) # Move the cursor forward by n
|
43
|
+
print(CSI + "#{n || 1}C")
|
44
|
+
end
|
45
|
+
def col(n = 1) # Cursor moves to nth position horizontally in the current line
|
46
|
+
print(CSI + "#{n || 1}G")
|
47
|
+
end
|
48
|
+
def row(n = 1) # Cursor moves to the nth position vertically in the current column
|
49
|
+
print(CSI + "#{n || 1}d")
|
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
|
78
|
+
end
|
79
|
+
end
|
@@ -0,0 +1,83 @@
|
|
1
|
+
module Rcurses
|
2
|
+
module Input
|
3
|
+
def getchr
|
4
|
+
# Function to process key presses
|
5
|
+
c = $stdin.getch
|
6
|
+
case c
|
7
|
+
when "\e" # ANSI escape sequences
|
8
|
+
return "ESC" if !$stdin.ready?
|
9
|
+
second_char = $stdin.getc
|
10
|
+
case second_char
|
11
|
+
when '[' # CSI
|
12
|
+
third_char = $stdin.getc
|
13
|
+
case third_char
|
14
|
+
when 'A' then chr = "UP"
|
15
|
+
when 'B' then chr = "DOWN"
|
16
|
+
when 'C' then chr = "RIGHT"
|
17
|
+
when 'D' then chr = "LEFT"
|
18
|
+
when 'Z' then chr = "S-TAB"
|
19
|
+
when '2'
|
20
|
+
fourth_char = $stdin.getc
|
21
|
+
chr = fourth_char == '~' ? "INS" : ""
|
22
|
+
when '3'
|
23
|
+
fourth_char = $stdin.getc
|
24
|
+
chr = fourth_char == '~' ? "DEL" : ""
|
25
|
+
when '5'
|
26
|
+
fourth_char = $stdin.getc
|
27
|
+
chr = fourth_char == '~' ? "PgUP" : ""
|
28
|
+
when '6'
|
29
|
+
fourth_char = $stdin.getc
|
30
|
+
chr = fourth_char == '~' ? "PgDOWN" : ""
|
31
|
+
when '1', '7'
|
32
|
+
fourth_char = $stdin.getc
|
33
|
+
chr = fourth_char == '~' ? "HOME" : ""
|
34
|
+
when '4', '8'
|
35
|
+
fourth_char = $stdin.getc
|
36
|
+
chr = fourth_char == '~' ? "END" : ""
|
37
|
+
else chr = ""
|
38
|
+
end
|
39
|
+
when 'O' # Function keys
|
40
|
+
third_char = $stdin.getc
|
41
|
+
case third_char
|
42
|
+
when 'a' then chr = "C-UP"
|
43
|
+
when 'b' then chr = "C-DOWN"
|
44
|
+
when 'c' then chr = "C-RIGHT"
|
45
|
+
when 'd' then chr = "C-LEFT"
|
46
|
+
else chr = ""
|
47
|
+
end
|
48
|
+
else
|
49
|
+
chr = ""
|
50
|
+
end
|
51
|
+
when "\r" then chr = "ENTER"
|
52
|
+
when "\t" then chr = "TAB"
|
53
|
+
when "\u007F", "\b" then chr = "BACK"
|
54
|
+
when "\u0001" then chr = "C-A"
|
55
|
+
when "\u0002" then chr = "C-B"
|
56
|
+
when "\u0003" then chr = "C-C"
|
57
|
+
when "\u0004" then chr = "C-D"
|
58
|
+
when "\u0005" then chr = "C-E"
|
59
|
+
when "\u0006" then chr = "C-F"
|
60
|
+
when "\u0007" then chr = "C-G"
|
61
|
+
when "\u000B" then chr = "C-K"
|
62
|
+
when "\u000C" then chr = "C-L"
|
63
|
+
when "\u000D" then chr = "C-M"
|
64
|
+
when "\u000E" then chr = "C-N"
|
65
|
+
when "\u000F" then chr = "C-O"
|
66
|
+
when "\u0010" then chr = "C-P"
|
67
|
+
when "\u0011" then chr = "C-Q"
|
68
|
+
when "\u0012" then chr = "C-R"
|
69
|
+
when "\u0014" then chr = "C-T"
|
70
|
+
when "\u0015" then chr = "C-U"
|
71
|
+
when "\u0016" then chr = "C-V"
|
72
|
+
when "\u0018" then chr = "C-X"
|
73
|
+
when "\u0019" then chr = "C-Y"
|
74
|
+
when "\u001A" then chr = "C-Z"
|
75
|
+
when "\u0017" then chr = "WBACK"
|
76
|
+
when "\u0013" then chr = "C-S"
|
77
|
+
when /[[:print:]]/ then chr = c
|
78
|
+
else chr = ""
|
79
|
+
end
|
80
|
+
chr
|
81
|
+
end
|
82
|
+
end
|
83
|
+
end
|