Skip to content

Commit 7885c83

Browse files
committed
Add docstrings
1 parent 650cde5 commit 7885c83

File tree

1 file changed

+105
-0
lines changed

1 file changed

+105
-0
lines changed

src/terminal.jl

Lines changed: 105 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
11
import Base.print
22

3+
"""
4+
Terminal
5+
"""
36
struct Terminal
47
buffers::Vector{Buffer}
58
current::Ref{UInt8}
@@ -41,6 +44,9 @@ struct Terminal
4144
end
4245
end
4346

47+
"""
48+
Get key press
49+
"""
4450
function get_event(t)
4551
return if isready(t.stdin_channel)
4652
take!(t.stdin_channel)
@@ -59,6 +65,9 @@ update_channel(t, arg::String) = put!(t.stdout_channel, arg)
5965

6066
const TERMINAL = Ref{Terminal}()
6167

68+
"""
69+
Flush terminal contents
70+
"""
6271
function flush(t::Terminal, diff = true)
6372
previous_buffer = t.buffers[END - t.current[]]
6473
current_buffer = t.buffers[t.current[]]
@@ -73,44 +82,128 @@ function flush(t::Terminal, diff = true)
7382
update(t)
7483
end
7584

85+
"""
86+
Move cursor
87+
"""
7688
move_cursor(t::Terminal, row, col) = update_channel(t, Terminals.CSI, INDICES[row], ';', INDICES[col], 'H')
89+
"""
90+
Move cursor up
91+
"""
7792
move_cursor_up(t::Terminal, row = 1) = update_channel(t, Terminals.CSI, INDICES[row], 'A')
93+
"""
94+
Move cursor down
95+
"""
7896
move_cursor_down(t::Terminal, row = 1) = update_channel(t, Terminals.CSI, INDICES[row], 'B')
97+
"""
98+
Move cursor right
99+
"""
79100
move_cursor_right(t::Terminal, col = 1) = update_channel(t, Terminals.CSI, INDICES[col], 'C')
101+
"""
102+
Move cursor left
103+
"""
80104
move_cursor_left(t::Terminal, col = 1) = update_channel(t, Terminals.CSI, INDICES[col], 'D')
105+
"""
106+
Move cursor home
107+
"""
81108
move_cursor_home(t::Terminal) = update_channel(t, HOMEPOSITION)
82109

110+
"""
111+
Clear screen
112+
"""
83113
clear_screen(t::Terminal) = update_channel(t, CLEARSCREEN)
114+
"""
115+
Clear screen from cursor up onwards
116+
"""
84117
clear_screen_from_cursor_up(t::Terminal) = update_channel(t, CLEARBELOWCURSOR)
118+
"""
119+
Clear screen from cursor down onwards
120+
"""
85121
clear_screen_from_cursor_down(t::Terminal) = update_channel(t, CLEARABOVECURSOR)
86122

123+
"""
124+
Clear line
125+
"""
87126
clear_line(t::Terminal) = update_channel(t, CLEARLINE)
127+
"""
128+
Clear line from cursor right onwards
129+
"""
88130
clear_line_from_cursor_right(t::Terminal) = update_channel(t, CLEARAFTERCURSOR)
131+
"""
132+
Clear line from cursor left onwards
133+
"""
89134
clear_line_from_cursor_left(t::Terminal) = update_channel(t, CLEARBEFORECURSOR)
90135

136+
"""
137+
Hide cursor
138+
"""
91139
hide_cursor(t::Terminal) = update_channel(t, HIDECURSOR)
140+
"""
141+
Show cursor
142+
"""
92143
show_cursor(t::Terminal) = update_channel(t, SHOWCURSOR)
93144

145+
"""
146+
Save cursor
147+
"""
94148
save_cursor(t::Terminal) = update_channel(t, SAVECURSOR)
149+
"""
150+
Restore cursor
151+
"""
95152
restore_cursor(t::Terminal) = update_channel(t, RESTORECURSOR)
96153

154+
"""
155+
Change cursor to blinking block
156+
"""
97157
change_cursor_to_blinking_block(t::Terminal) = update_channel(t, CURSORBLINKINGBLOCK)
158+
"""
159+
Change cursor to steady block
160+
"""
98161
change_cursor_to_steady_block(t::Terminal) = update_channel(t, CURSORSTEADYBLOCK)
162+
"""
163+
Change cursor to blinking underline
164+
"""
99165
change_cursor_to_blinking_underline(t::Terminal) = update_channel(t, CURSORBLINKINGUNDERLINE)
166+
"""
167+
Change cursor to steady underline
168+
"""
100169
change_cursor_to_steady_underline(t::Terminal) = update_channel(t, CURSORSTEADYUNDERLINE)
170+
"""
171+
Change cursor to blinking ibeam
172+
"""
101173
change_cursor_to_blinking_ibeam(t::Terminal) = update_channel(t, CURSORBLINKINGIBEAM)
174+
"""
175+
Change cursor to steady ibeam
176+
"""
102177
change_cursor_to_steady_ibeam(t::Terminal) = update_channel(t, CURSORSTEADYIBEAM)
103178

179+
"""
180+
Reset terminal settings
181+
"""
104182
reset(t::Terminal) = update_channel(t, RESET)
105183

184+
"""
185+
Alternate screen TUI mode
186+
"""
106187
tui_mode(t::Terminal) = update_channel(t, TUIMODE)
188+
"""
189+
Default mode
190+
"""
107191
default_mode(t::Terminal) = update_channel(t, DEFAULTMODE)
108192

193+
"""
194+
Get current buffer
195+
"""
109196
current_buffer(t::Terminal)::Buffer = t.buffers[t.current[]]
110197
current_buffer()::Buffer = current_buffer(TERMINAL[])
111198

199+
"""
200+
Reset terminal
201+
"""
112202
reset(t::Terminal, buffer::Int) = reset(t.buffers[buffer])
113203

204+
"""
205+
Update terminal
206+
"""
114207
function update(t::Terminal)
115208
reset(t.buffers[END - t.current[]])
116209
t.current[] = END - t.current[]
@@ -123,6 +216,9 @@ function update(t::Terminal)
123216
end
124217
end
125218

219+
"""
220+
Draw terminal
221+
"""
126222
function draw(t::Terminal, buffer::Buffer)
127223
save_cursor(t)
128224
move_cursor_home(t)
@@ -138,6 +234,9 @@ function draw(t::Terminal, buffer::Buffer)
138234
update(t)
139235
end
140236

237+
"""
238+
Draw terminal
239+
"""
141240
function draw(t::Terminal, buffer1::Buffer, buffer2::Buffer)
142241
save_cursor(t)
143242
b1 = buffer1.content[:]
@@ -154,13 +253,19 @@ function draw(t::Terminal, buffer1::Buffer, buffer2::Buffer)
154253
restore_cursor(t)
155254
end
156255

256+
"""
257+
Resize terminal
258+
"""
157259
function resize(t::Terminal, w::Int, h::Int)
158260
rect = Rect(1, 1, w, h)
159261
t.terminal_size[] = rect
160262
t.buffers[1] = Buffer(rect)
161263
t.buffers[2] = Buffer(rect)
162264
end
163265

266+
"""
267+
Locate cursor
268+
"""
164269
function locate_cursor(t::Terminal)
165270
ucs = Char[]
166271
while length(t.keyboard_buffer) > 0

0 commit comments

Comments
 (0)