Skip to content

Commit dcfcc3a

Browse files
Merge pull request #10 from abcdvvvv/main
Solving screen flickering problems with Term: Consoles
2 parents 47787c8 + 46172db commit dcfcc3a

File tree

1 file changed

+12
-9
lines changed

1 file changed

+12
-9
lines changed

src/TerminalSystemMonitor.jl

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ module TerminalSystemMonitor
33
using Dates: Dates, Day, DateTime, Second
44
using UnicodePlots
55
import Term # this is required by UnicodePlots.panel
6+
using Term: Consoles
67
using MLDataDevices: MLDataDevices, CUDADevice, CPUDevice, MetalDevice
78

89
export monitor # entrypoint from REPL
@@ -129,15 +130,11 @@ function plot_cpu_memory_utilization(::Type{CPUDevice})
129130
width = 30,
130131
),
131132
)
132-
133-
end
134-
135-
function monitor(args...)
136-
main(args...)
137133
end
138134

139135
function main(dummyargs...)
140-
hidecursor()
136+
# Control cursor hiding and showing with Term.Consoles
137+
Consoles.hide_cursor()
141138

142139
while true
143140
try
@@ -226,15 +223,21 @@ function main(dummyargs...)
226223
break
227224
end
228225
end
229-
clearlinesall()
226+
227+
Consoles.move_to_line(stdout, 1)
228+
Consoles.cleartoend(stdout)
230229
display(f)
231230
catch e
232-
unhidecursor() # unhide cursor
231+
Consoles.show_cursor()
233232
@warn "Got Exception"
234233
rethrow(e) # so we don't swallow true exceptions
235234
end
236235
end
237-
unhidecursor() # unhide cursor
236+
Consoles.show_cursor()
237+
end
238+
239+
function monitor(args...)
240+
main(args...)
238241
end
239242

240243
end # module TerminalSystemMonitor

0 commit comments

Comments
 (0)