Created
September 11, 2021 11:56
-
-
Save terasakisatoshi/7d03d5274d1fc450d80fb7f6075200e1 to your computer and use it in GitHub Desktop.
TextUserInterfaces.jl
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using InteractiveUtils | |
using TextUserInterfaces | |
function main() | |
init_tui() | |
w, c = create_window_with_container(border=true, title="MyFirstUI") | |
label_1 = @tui_label( | |
parent = c, left = 0, top = 0, | |
text = "This app is created based on TextUserInterfaces.jl" | |
) | |
label_2 = @tui_label( | |
parent = c, anchor_left = (label_1, :left), anchor_top = (label_1, :bottom), | |
text = "Press <Tab> key to select button and press <Enter> key to execute function" | |
) | |
button_container = @tui_container( | |
parent = c, | |
border = true, | |
anchor_top = (label_2, :bottom), | |
anchor_left = (label_1, :left), | |
anchor_right = (:parent, :right), | |
height = 3, | |
) | |
function do_something(w, k) | |
k.ktype != :enter && return nothing | |
msg = sprint(versioninfo) | |
change_text(canvas, msg) | |
end | |
function clear_msg(w, k) | |
k.ktype != :enter && return nothing | |
change_text(canvas, "") | |
end | |
versioninfo_button = @tui_button( | |
parent = button_container, | |
left = 1, top = 1, | |
label = "show versioninfo", | |
signal = (key_pressed, do_something) | |
) | |
clear_button = @tui_button( | |
parent = button_container, | |
anchor_left = (versioninfo_button, :right), | |
anchor_top = (versioninfo_button, :top), | |
label = "Clear", | |
signal = (key_pressed, clear_msg) | |
) | |
canvas = @tui_ansi_label( | |
parent = c, | |
anchor_left = (button_container, :left), | |
anchor_top = (button_container, :bottom), | |
anchor_bottom = (:parent, :bottom), | |
anchor_right = (:parent, :right), | |
text = "Canvas" | |
) | |
app_main_loop() | |
end | |
main() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Usage
$ julia textui.jl
Result