Skip to content

Commit 7bff5b6

Browse files
committed
Added winsz() function
1 parent dbc92e0 commit 7bff5b6

File tree

6 files changed

+34
-2
lines changed

6 files changed

+34
-2
lines changed

src/console.jl

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,4 +52,15 @@ function cls()
5252
end
5353
export cls
5454

55+
function winsz()
56+
lines = Cint[0]
57+
columns = Cint[0]
58+
ccall((:winsz, libconsole),
59+
Nothing,
60+
(Ptr{Cint}, Ptr{Cint}),
61+
lines, columns)
62+
return lines[1], columns[1]
63+
end
64+
export winsz
65+
5566
end

src/dialog.jl

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,8 +34,9 @@ function openfiledialog(path)
3434
if length(songs) > 0
3535
settty()
3636
cls()
37+
lines, colums = winsz()
3738
while true
38-
last = first + min(23, length(songs) - 1)
39+
last = first + min(lines-1, length(songs) - 1)
3940
for index in first:last
4041
outtextxy(1, index - scrolled, rpad(songs[index][1], 80))
4142
end

src/lib/libconsole.dll

0 Bytes
Binary file not shown.

src/lib/libconsole.dylib

75 Bytes
Binary file not shown.

src/lib/libconsole.so

-3.72 KB
Binary file not shown.

src/libconsole.c

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
cc -shared -arch arm64 -arch x86_64 -o libconsole.dylib libconsole.c
44
Windows:
55
cl /c libconsole.c
6-
link /out:libconsole.dll libconsole.obj
6+
link /dll /out:libconsole.dll libconsole.obj
77
Linux:
88
cc -shared -fPIC -o libconsole.so libconsole.c
99
*/
@@ -17,6 +17,7 @@
1717
#include <termios.h>
1818
#include <signal.h>
1919
#include <sys/time.h>
20+
#include <sys/ioctl.h>
2021
typedef void (*sighandler_t)(int);
2122
#endif
2223

@@ -238,3 +239,22 @@ void cls(void)
238239
fflush(stdout);
239240
#endif
240241
}
242+
243+
void winsz(int *lines, int *columns)
244+
{
245+
#if defined(_WIN32)
246+
CONSOLE_SCREEN_BUFFER_INFO csbi;
247+
248+
GetConsoleScreenBufferInfo(std_output, &csbi);
249+
250+
*lines = csbi.srWindow.Bottom - csbi.srWindow.Top + 1;
251+
*columns = csbi.srWindow.Right - csbi.srWindow.Left + 1;
252+
#else
253+
struct winsize w;
254+
ioctl(STDOUT_FILENO, TIOCGWINSZ, &w);
255+
256+
*lines = w.ws_row;
257+
*columns = w.ws_col;
258+
#endif
259+
}
260+

0 commit comments

Comments
 (0)