Create TerminalUserInterfaces in Julia.
pkg> add TerminalUserInterfaces
See documentation and examples folder for information how to use the package.
Check out my JuliaCon talk where I use this package to make a presentation in the terminal.
Terminal User Interfaces in Julia.
License: MIT License
Create TerminalUserInterfaces in Julia.
pkg> add TerminalUserInterfaces
See documentation and examples folder for information how to use the package.
Check out my JuliaCon talk where I use this package to make a presentation in the terminal.
Hi,
Here's the error that I get, pretty much right out of the gate.
julia> using TerminalUserInterfaces
julia> const TUI = TerminalUserInterfaces
TerminalUserInterfaces
julia> TUI.terminal_size()
ERROR: ioctl failed: Inappropriate ioctl for device
Stacktrace:
[1] ioctl(fd::RawFD, parameter::Int64)
@ TerminalUserInterfaces.IOCTL ~/.julia/packages/TerminalUserInterfaces/ha2Cg/src/ioctl.jl:123
[2] ioctl
@ ~/.julia/packages/TerminalUserInterfaces/ha2Cg/src/ioctl.jl:126 [inlined]
[3] terminal_size(io::Base.TTY)
@ TerminalUserInterfaces ~/.julia/packages/TerminalUserInterfaces/ha2Cg/src/utils.jl:9
[4] terminal_size()
@ TerminalUserInterfaces ~/.julia/packages/TerminalUserInterfaces/ha2Cg/src/utils.jl:13
[5] top-level scope
@ REPL[3]:1
julia> versioninfo()
Julia Version 1.6.1
Commit 6aaedecc44* (2021-04-23 05:59 UTC)
Platform Info:
OS: Linux (x86_64-pc-linux-gnu)
CPU: Intel(R) Core(TM) i7-8550U CPU @ 1.80GHz
WORD_SIZE: 64
LIBM: libopenlibm
LLVM: libLLVM-11.1.0 (ORCJIT, skylake)
(@v1.6) pkg> status TerminalUserInterfaces
Status `~/.julia/environments/v1.6/Project.toml`
[408767e4] TerminalUserInterfaces v0.2.0
I'm on Arch Linux. This happens both in the text console and in a terminal emulator running under X.
I think it would be as simple as just replacing the if-else block and using something like
partials = (
FULL_BLOCK,
LEFT_SEVEN_EIGHTHS_BLOCK,
LEFT_THREE_QUARTERS_BLOCK,
LEFT_HALF_BLOCK,
LEFT_FIVE_EIGHTHS_BLOCK,
LEFT_THREE_EIGHTHS_BLOCK,
LEFT_ONE_QUARTER_BLOCK,
LEFT_ONE_EIGHTH_BLOCK,
' ',
)
...
width = (right(inner_area) - left(inner_area) + 1)
for y in top(inner_area):bottom(inner_area)
for x in left(inner_area):right(inner_area)
symbol = clamp(round(Int, (x - r * width) * 8), 0, 8) + 1
set(buf, x, y, crayon, partials[symbol])
end
end
Would also make the output more copy friendly.
I really enjoyed your juliacon presentation, it looks like this has great potential for creating tools to:
please include a folder with sample code to demonstrate how you made the presentation from juliacon2020.
juliacon 2020: Terminal User Interfaces in Julia
juliacon 2020: Terminal User Interfaces in Julia - YOUTUBE
I use Linux here and I tried to use your library to get the size of my terminal in pixels. Maybe a bit overkill but I don't know a better way yet. When I try to get that size, I get the following error:
julia> TerminalUserInterfaces.terminal_size()
ERROR: ioctl failed: Inappropriate ioctl for device
Stacktrace:
[1] error(::String) at ./error.jl:33
[2] ioctl(::RawFD, ::Int64) at /home/simon/.julia/packages/TerminalUserInterfaces/ha2Cg/src/ioctl.jl:123
[3] ioctl at /home/simon/.julia/packages/TerminalUserInterfaces/ha2Cg/src/ioctl.jl:126 [inlined]
[4] terminal_size(::Base.TTY) at /home/simon/.julia/packages/TerminalUserInterfaces/ha2Cg/src/utils.jl:9
[5] terminal_size() at /home/simon/.julia/packages/TerminalUserInterfaces/ha2Cg/src/utils.jl:13
[6] top-level scope at REPL[71]:1
I then tried out
julia> TerminalUserInterfaces.IOCTL.ioctl(stdout, TerminalUserInterfaces.IOCTL.TIOCGWINSZ)
ERROR: ioctl failed: Inappropriate ioctl for device
Stacktrace:
[1] error(::String) at ./error.jl:33
[2] ioctl(::RawFD, ::Int64) at /home/simon/.julia/packages/TerminalUserInterfaces/ha2Cg/src/ioctl.jl:123
[3] ioctl(::Base.TTY, ::Int64) at /home/simon/.julia/packages/TerminalUserInterfaces/ha2Cg/src/ioctl.jl:126
[4] top-level scope at REPL[73]:1
and got the same error. Finally I looked at the code and saw that TerminalUserInterfaces.IOCTL.TIOCGWINSZ
is set to 25
for linux systems. I looked up ioctl.h
on the internet and saw that there TIOCGWINSZ
is set to 21523
. So I tried that out and it worked:
julia> TerminalUserInterfaces.IOCTL.ioctl(stdout, 21523)
TerminalUserInterfaces.IOCTL.winsize(0xdeb8, 0x1b66, 0x7ffe, 0x0000)
So is it possible that the value for TIOCGWINSZ is incorrectly defined?
This issue is used to trigger TagBot; feel free to unsubscribe.
If you haven't already, you should update your TagBot.yml
to include issue comment triggers.
Please see this post on Discourse for instructions and more details.
If you'd like for me to do this for you, comment TagBot fix
on this issue.
I'll open a PR within a few hours, please be patient!
Hi @kdheepak, I just watched your JuliaCon talk and came here to try things out. However the examples don't seem to work on my Ubuntu 18.04 machine with gnome-terminal, Julia 1.4 and TerminalUserInterfaces 0.2.0:
julia> include("barchart.jl")
[ Info: Precompiling TerminalUserInterfaces [408767e4-586b-40c7-9657-f9758988469a]
ERROR: LoadError: TERMIOSError: tcgetattr failed: Bad file descriptor
Stacktrace:
[1] tcgetattr(::RawFD, ::TERMIOS.termios) at /home/chris/.julia/packages/TERMIOS/Kvyl9/src/TERMIOS.jl:610
[2] tcgetattr(::Base.TTY, ::TERMIOS.termios) at /home/chris/.julia/packages/TERMIOS/Kvyl9/src/TERMIOS.jl:612
[3] backup_termios() at /home/chris/.julia/packages/TerminalUserInterfaces/ha2Cg/src/utils.jl:194
[4] initialize() at /home/chris/.julia/packages/TerminalUserInterfaces/ha2Cg/src/utils.jl:199
[5] main() at /home/chris/.julia/packages/TerminalUserInterfaces/ha2Cg/examples/barchart.jl:6
[6] top-level scope at /home/chris/.julia/packages/TerminalUserInterfaces/ha2Cg/examples/barchart.jl:62
[7] include(::String) at ./client.jl:439
[8] top-level scope at REPL[1]:1
in expression starting at /home/chris/.julia/packages/TerminalUserInterfaces/ha2Cg/examples/barchart.jl:62
Any thoughts on what could be causing this?
Very cool package, but in terms of convenience I feel there are a few layers missing. It would be better if users could simply call selectablelist(options)
and have what is now in list.jl in the examples folder. I don't mean that that layer of convenience should be here, or even written by you, I only mean that it's probably a major barrier preventing many users from using this fantastic package.
I am using the master branch of TUI, on Arch Linux, Julia 1.6.1.
Only the percentage is visible, which I don't believe was intended.
Recording here.
Any time a break a loop (and I don't mean through an error, just normally), the terminal "goes dead" meaning that it no longer appears to accept any user input. I figured this was coming from somewhere in TUI.cleanup()
(since the programs themselves seemed to work normally) but this seems to happen even if TUI.cleanup()
is not called, so something seems to be going wrong before this.
This is happening on alacritty. I happened to have gnome-terminal
on this machine so I checked that, and I get the same behavior, so it probably isn't terminal specific.
julia> using TerminalUserInterfaces
ERROR: InitError: MethodError: no method matching tcgetattr(::Base.Libc.WindowsRawSocket, ::TERMIOS.termios)
Closest candidates are:
tcgetattr(::Base.LibuvStream, ::Any) at C:\Users\Maste\.julia\dev\TERMIOS\src\TERMIOS.jl:612
tcgetattr(::Int64, ::Any) at C:\Users\Maste\.julia\dev\TERMIOS\src\TERMIOS.jl:613
tcgetattr(::RawFD, ::TERMIOS.termios) at C:\Users\Maste\.julia\dev\TERMIOS\src\TERMIOS.jl:608
Stacktrace:
[1] tcgetattr(s::Base.TTY, term::TERMIOS.termios)
@ TERMIOS C:\Users\Maste\.julia\dev\TERMIOS\src\TERMIOS.jl:612
[2] backup_termios()
@ TerminalUserInterfaces C:\Users\Maste\.julia\dev\TerminalUserInterfaces\src\utils.jl:198
......
TerminalUserInterfaces.jl/src/utils.jl
Line 198 in 6061a01
both stdin
and stdout
were not IO type.
julia> stdin
Base.TTY(Base.Libc.WindowsRawSocket(0x0000000000000254) open, 0 bytes waiting)
julia> stdout
Base.TTY(Base.Libc.WindowsRawSocket(0x0000000000000228) open, 0 bytes waiting)
I'm on Julia 1.7.1 and here is my full versioninfo()
Julia Version 1.7.1
Commit ac5cc99908 (2021-12-22 19:35 UTC)
Platform Info:
OS: Windows (x86_64-w64-mingw32)
CPU: AMD Ryzen 7 5800X 8-Core Processor
WORD_SIZE: 64
LIBM: libopenlibm
LLVM: libLLVM-12.0.1 (ORCJIT, znver3)
TerminalUserInterfaces v0.8.0
Julia Version 1.10.2 REPL
Windows-Terminal Version: 1.19.10573.0
Windows 11
Just Copy&Paste of example code
https://github.com/kdheepak/TerminalUserInterfaces.jl/blob/main/examples/list.jl
into REPL opens up the list menu fine.
Now changing the window focus to some other window, the TUI menu crashes with:
julia> main()
ERROR: ArgumentError: invalid JSON at byte position 1 while parsing type JSON3.Object: ExpectedOpeningObjectChar
"FocusLost"
Stacktrace:
[1] invalid(error::JSON3.Error, buf::Base.CodeUnits{UInt8, String}, pos::Int64, T::Type)
@ JSON3 C:\Users\oheil\.julia\packages\JSON3\jSAdy\src\JSON3.jl:30
[2] #read#43
@ C:\Users\oheil\.julia\packages\JSON3\jSAdy\src\structs.jl:429 [inlined]
[3] read
@ C:\Users\oheil\.julia\packages\JSON3\jSAdy\src\structs.jl:353 [inlined]
[4] read
@ C:\Users\oheil\.julia\packages\JSON3\jSAdy\src\structs.jl:350 [inlined]
[5] read(str::String, ::Type{Dict}; jsonlines::Bool, kw::@Kwargs{})
@ JSON3 C:\Users\oheil\.julia\packages\JSON3\jSAdy\src\structs.jl:41
[6] read
@ C:\Users\oheil\.julia\packages\JSON3\jSAdy\src\structs.jl:33 [inlined]
[7] read()
@ Crossterm C:\Users\oheil\.julia\packages\Crossterm\IcBlh\src\Crossterm.jl:384
[8] #try_get_event#19
@ C:\Users\oheil\.julia\packages\TerminalUserInterfaces\eHCFe\src\terminal.jl:48 [inlined]
[9] try_get_event
@ C:\Users\oheil\.julia\packages\TerminalUserInterfaces\eHCFe\src\terminal.jl:46 [inlined]
[10] (::TerminalUserInterfaces.var"#54#55"{Float64, Model})()
@ TerminalUserInterfaces C:\Users\oheil\.julia\packages\TerminalUserInterfaces\eHCFe\src\app.jl:37
[11] tui(f::TerminalUserInterfaces.var"#54#55"{Float64, Model}; flags::@Kwargs{})
@ TerminalUserInterfaces C:\Users\oheil\.julia\packages\TerminalUserInterfaces\eHCFe\src\terminal.jl:262
[12] tui
@ C:\Users\oheil\.julia\packages\TerminalUserInterfaces\eHCFe\src\terminal.jl:258 [inlined]
[13] #app#53
@ C:\Users\oheil\.julia\packages\TerminalUserInterfaces\eHCFe\src\app.jl:31 [inlined]
[14] app
@ C:\Users\oheil\.julia\packages\TerminalUserInterfaces\eHCFe\src\app.jl:30 [inlined]
[15] main()
@ Main .\REPL[9]:3
[16] top-level scope
@ REPL[10]:1
julia>
I'd like to read the arrow keys, but it seems that they come in as a strange combination of 3 bytes, meaning I have to call take!(t.stdin_channel)
3 times and put the values together. What kind of data can I generally expect to come out of stdin in "raw mode"?
Version 0.8.0 does not precompile with version 1.8 as it requires @kwdef, but this is not exported until Julia 1.9. Version 0.3.0 compiles, but the documentation for this version does not appear in the documentation page, only for 0.2.0 and 0.8.0.
This could be a case of me misusing the library, but enable_raw_mode() works just fine and lets me get the work done. It does not seem like I can disable it, however.
julia> TerminalUserInterfaces.disable_raw_mode()
ERROR: UndefRefError: access to undefined reference
Stacktrace:
[1] getproperty
@ ./Base.jl:33 [inlined]
[2] getindex
@ ./refvalue.jl:56 [inlined]
[3] disable_raw_mode()
@ TerminalUserInterfaces ~/.julia/packages/TerminalUserInterfaces/Mhqzn/src/utils.jl:191
[4] top-level scope
@ REPL[2]:1
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.