Skip to content

Commit d87794a

Browse files
Implement clearlinesall
1 parent 31c3195 commit d87794a

File tree

1 file changed

+11
-3
lines changed

1 file changed

+11
-3
lines changed

src/TerminalSystemMonitor.jl

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,11 @@ function clearlines(H::Integer)
4545
end
4646
end
4747

48+
function clearlinesall()
49+
CSI = "\x1b["
50+
print("$(CSI)H$(CSI)2J")
51+
end
52+
4853
function hidecursor()
4954
print("\x1b[?25l") # hidecursor
5055
end
@@ -86,19 +91,22 @@ function layout(x, y)
8691
return foldl(/, map(c -> prod(UnicodePlots.panel.(c)), chunks))
8792
end
8893

89-
9094
function main()
9195
hidecursor()
96+
9297
while true
9398
try
9499
y = cpu_percent()
95100
x = ["id: $(i-1)" for (i, _) in enumerate(y)]
96-
(_, cols) = displaysize(stdout)
101+
(newrows, newcols) = displaysize(stdout)
97102

98103
# f = barplot(x, y, title="CPU Usage", maximum=100, width=max(10, cols - 15), height=length(y))
99104
f = layout(x, y)
100105
str = string(f)
101-
clearlines(2 + length(collect(eachmatch(r"\n", str))))
106+
newheight = 2 + length(collect(eachmatch(r"\n", str)))
107+
108+
clearlinesall()
109+
102110
display(f)
103111
catch e
104112
unhidecursor() # unhide cursor

0 commit comments

Comments
 (0)