Class: Redwood::ScrollMode
- Inherits:
-
Mode
show all
- Defined in:
- lib/sup/modes/scroll_mode.rb
Instance Attribute Summary collapse
-
#botline ⇒ Object
readonly
we left leftcol and rightcol as the left and right columns of any content in the current view.
-
#leftcol ⇒ Object
readonly
we left leftcol and rightcol as the left and right columns of any content in the current view.
-
#status ⇒ Object
readonly
we left leftcol and rightcol as the left and right columns of any content in the current view.
-
#topline ⇒ Object
readonly
we left leftcol and rightcol as the left and right columns of any content in the current view.
Attributes inherited from Mode
#buffer
Instance Method Summary
collapse
Methods inherited from Mode
#blur, #cleanup, #focus, #handle_input, #help_text, keymap, keymaps, #killable?, load_all_modes, make_name, #name, #pipe_to_process, register_keymap, #resolve_input, #save_to_file, #unsaved?
Constructor Details
#initialize(opts = {}) ⇒ ScrollMode
Returns a new instance of ScrollMode.
31
32
33
34
35
36
37
38
39
40
|
# File 'lib/sup/modes/scroll_mode.rb', line 31
def initialize opts={}
@topline, @botline, @leftcol = 0, 0, 0
@slip_rows = opts[:slip_rows] || 0 @twiddles = opts.member?(:twiddles) ? opts[:twiddles] : true
@search_query = nil
@search_line = nil
@status = ""
super()
end
|
Instance Attribute Details
we left leftcol and rightcol as the left and right columns of any content in the current view. but since we’re operating in a line-centric fashion, rightcol is always leftcol + the buffer width. (whereas botline is topline + at most the buffer height, and can be == to topline in the case that there’s no content.)
13
14
15
|
# File 'lib/sup/modes/scroll_mode.rb', line 13
def botline
@botline
end
|
we left leftcol and rightcol as the left and right columns of any content in the current view. but since we’re operating in a line-centric fashion, rightcol is always leftcol + the buffer width. (whereas botline is topline + at most the buffer height, and can be == to topline in the case that there’s no content.)
13
14
15
|
# File 'lib/sup/modes/scroll_mode.rb', line 13
def leftcol
@leftcol
end
|
we left leftcol and rightcol as the left and right columns of any content in the current view. but since we’re operating in a line-centric fashion, rightcol is always leftcol + the buffer width. (whereas botline is topline + at most the buffer height, and can be == to topline in the case that there’s no content.)
13
14
15
|
# File 'lib/sup/modes/scroll_mode.rb', line 13
def status
@status
end
|
we left leftcol and rightcol as the left and right columns of any content in the current view. but since we’re operating in a line-centric fashion, rightcol is always leftcol + the buffer width. (whereas botline is topline + at most the buffer height, and can be == to topline in the case that there’s no content.)
13
14
15
|
# File 'lib/sup/modes/scroll_mode.rb', line 13
def topline
@topline
end
|
Instance Method Details
#at_bottom? ⇒ Boolean
132
|
# File 'lib/sup/modes/scroll_mode.rb', line 132
def at_bottom?; @botline == lines end
|
#at_top? ⇒ Boolean
131
|
# File 'lib/sup/modes/scroll_mode.rb', line 131
def at_top?; @topline == 0 end
|
#cancel_search! ⇒ Object
58
|
# File 'lib/sup/modes/scroll_mode.rb', line 58
def cancel_search!; @search_line = nil end
|
99
100
101
|
# File 'lib/sup/modes/scroll_mode.rb', line 99
def col_jump
$config[:col_jump] || 2
end
|
103
104
105
106
107
|
# File 'lib/sup/modes/scroll_mode.rb', line 103
def col_left
return unless @leftcol > 0
@leftcol -= col_jump
buffer.mark_dirty
end
|
#col_right ⇒ Object
109
110
111
112
|
# File 'lib/sup/modes/scroll_mode.rb', line 109
def col_right
@leftcol += col_jump
buffer.mark_dirty
end
|
#continue_search_in_buffer ⇒ Object
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
|
# File 'lib/sup/modes/scroll_mode.rb', line 60
def continue_search_in_buffer
unless @search_query
BufferManager.flash "No current search!"
return
end
start = @search_line || search_start_line
line, col = find_text @search_query, start
if line.nil? && (start > 0)
line, col = find_text @search_query, 0
BufferManager.flash "Search wrapped to top!" if line
end
if line
@search_line = line + 1
search_goto_pos line, col, col + @search_query.display_length
buffer.mark_dirty
else
BufferManager.flash "Not found!"
end
end
|
44
45
46
47
48
49
50
51
52
53
54
55
|
# File 'lib/sup/modes/scroll_mode.rb', line 44
def draw
ensure_mode_validity
(@topline ... @botline).each { |ln| draw_line ln, :color => :text_color }
((@botline - @topline) ... buffer.content_height).each do |ln|
if @twiddles
buffer.write ln, 0, "~", :color => :twiddle_color
else
buffer.write ln, 0, "", :color => :text_color
end
end
@status = "lines #{@topline + 1}:#{@botline}/#{lines}"
end
|
#ensure_mode_validity ⇒ Object
143
144
145
146
|
# File 'lib/sup/modes/scroll_mode.rb', line 143
def ensure_mode_validity
@topline = @topline.clamp 0, [lines - 1, 0].max
@botline = [@topline + buffer.content_height, lines].min
end
|
#half_page_down ⇒ Object
138
|
# File 'lib/sup/modes/scroll_mode.rb', line 138
def half_page_down; jump_to_line @topline + buffer.content_height / 2; end
|
#half_page_up ⇒ Object
139
|
# File 'lib/sup/modes/scroll_mode.rb', line 139
def half_page_up; jump_to_line @topline - buffer.content_height / 2; end
|
#in_search? ⇒ Boolean
57
|
# File 'lib/sup/modes/scroll_mode.rb', line 57
def in_search?; @search_line end
|
#jump_to_col(col) ⇒ Object
114
115
116
117
118
|
# File 'lib/sup/modes/scroll_mode.rb', line 114
def jump_to_col col
col = col - (col % col_jump)
buffer.mark_dirty unless @leftcol == col
@leftcol = col
end
|
#jump_to_end ⇒ Object
141
|
# File 'lib/sup/modes/scroll_mode.rb', line 141
def jump_to_end; jump_to_line lines - buffer.content_height; end
|
#jump_to_left ⇒ Object
120
|
# File 'lib/sup/modes/scroll_mode.rb', line 120
def jump_to_left; jump_to_col 0; end
|
#jump_to_line(l) ⇒ Object
123
124
125
126
127
128
129
|
# File 'lib/sup/modes/scroll_mode.rb', line 123
def jump_to_line l
l = l.clamp 0, lines - 1
return if @topline == l
@topline = l
@botline = [l + buffer.content_height, lines].min
buffer.mark_dirty
end
|
#jump_to_start ⇒ Object
140
|
# File 'lib/sup/modes/scroll_mode.rb', line 140
def jump_to_start; jump_to_line 0; end
|
#line_down ⇒ Object
134
|
# File 'lib/sup/modes/scroll_mode.rb', line 134
def line_down; jump_to_line @topline + 1; end
|
135
|
# File 'lib/sup/modes/scroll_mode.rb', line 135
def line_up; jump_to_line @topline - 1; end
|
#page_down ⇒ Object
136
|
# File 'lib/sup/modes/scroll_mode.rb', line 136
def page_down; jump_to_line @topline + buffer.content_height - @slip_rows; end
|
137
|
# File 'lib/sup/modes/scroll_mode.rb', line 137
def page_up; jump_to_line @topline - buffer.content_height + @slip_rows; end
|
#resize(*a) ⇒ Object
148
149
150
151
|
# File 'lib/sup/modes/scroll_mode.rb', line 148
def resize *a
super(*a)
ensure_mode_validity
end
|
42
|
# File 'lib/sup/modes/scroll_mode.rb', line 42
def rightcol; @leftcol + buffer.content_width; end
|
#search_goto_line(line) ⇒ Object
97
|
# File 'lib/sup/modes/scroll_mode.rb', line 97
def search_goto_line line; jump_to_line line end
|
#search_goto_pos(line, leftcol, rightcol) ⇒ Object
subclasses can override these three!
89
90
91
92
93
94
95
|
# File 'lib/sup/modes/scroll_mode.rb', line 89
def search_goto_pos line, leftcol, rightcol
search_goto_line line
if rightcol > self.rightcol jump_to_col [rightcol - buffer.content_width + 1, 0].max end
end
|
#search_in_buffer ⇒ Object
81
82
83
84
85
86
|
# File 'lib/sup/modes/scroll_mode.rb', line 81
def search_in_buffer
query = BufferManager.ask :search, "search in buffer: "
return if query.nil? || query.empty?
@search_query = Regexp.escape query
continue_search_in_buffer
end
|
#search_start_line ⇒ Object
96
|
# File 'lib/sup/modes/scroll_mode.rb', line 96
def search_start_line; @topline end
|