8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
|
# File 'lib/sergeant/modals/help.rb', line 8
def show_help_modal
max_y = lines
max_x = cols
modal_height = [28, max_y - 4].min modal_width = [70, max_x - 4].min modal_y = (max_y - modal_height) / 2
modal_x = (max_x - modal_width) / 2
(modal_y..(modal_y + modal_height)).each do |y|
setpos(y, modal_x)
attron(color_pair(3)) do
addstr(' ' * modal_width)
end
end
setpos(modal_y, modal_x)
attron(color_pair(4) | Curses::A_BOLD) do
addstr("\u250C#{'─' * (modal_width - 2)}\u2510")
end
setpos(modal_y + 1, modal_x)
attron(color_pair(4) | Curses::A_BOLD) do
addstr('│')
end
attron(color_pair(5) | Curses::A_BOLD) do
addstr(' Key Mappings '.center(modal_width - 2))
end
attron(color_pair(4) | Curses::A_BOLD) do
addstr('│')
end
setpos(modal_y + 2, modal_x)
attron(color_pair(4)) do
addstr("\u251C#{'─' * (modal_width - 2)}\u2524")
end
help_lines = [
'Navigation:',
' ↑/k - Move up',
' ↓/j - Move down',
' Enter / →/l - Open directory or preview file',
' ←/h - Go back to parent directory',
'',
'File Operations:',
' Space - Mark/unmark item',
' c - Copy marked items',
' x - Cut marked items',
' p - Paste copied/cut items',
' d - Delete marked items',
' r - Rename current item',
' u - Unmark all items',
' n - Create new file or directory',
'',
'View & Search:',
' e - Edit file ($EDITOR, nano, nvim, vim)',
' v - Preview file or archive contents',
' f - Filter current directory view',
' / - Search files (with fzf if available)',
'',
'Other:',
' : - Execute terminal command',
' o - Toggle ownership display',
' P - Toggle side preview panel',
' b - Go to bookmark',
' H - Show recent directories history',
' R - Force refresh and clear cache',
' q / ESC - Quit and cd to current directory'
]
help_lines.each_with_index do |line, idx|
break if idx >= modal_height - 4
setpos(modal_y + 3 + idx, modal_x)
attron(color_pair(4)) do
addstr('│ ')
end
display_line = if line.length > modal_width - 4
"#{line[0...(modal_width - 7)]}..."
else
line.ljust(modal_width - 4)
end
if line.start_with?('Navigation:', 'File Operations:', 'Other:')
attron(color_pair(1) | Curses::A_BOLD) do
addstr(display_line)
end
else
addstr(display_line)
end
attron(color_pair(4)) do
addstr(' │')
end
end
setpos(modal_y + modal_height - 1, modal_x)
attron(color_pair(4) | Curses::A_BOLD) do
addstr("\u2514#{'─' * (modal_width - 2)}\u2518")
end
refresh
getch
end
|