PSALM - demo.fish
Not logged in
#!/usr/bin/env fish
#
# Demonstration on how to create a GTK GUI using Psalm with FISH Shell 3.3.1.
#
# Run as follows (sockets):
#   socat EXEC:./psalm EXEC:./demo.fish
# 
# Or using socat with pipes:
#   socat EXEC:./psalm,pipes EXEC:./demo.fish,pipes
#
# Or using dpipe from VDE2:
#   dpipe ./psalm = ./demo.fish
#
# Or using pipexec:
#   pipexec [ A ./psalm ] [ B ./demo.fish ] "{A:1>B:0}" "{B:1>A:0}"
#
# Or native Linux:
#   : | { ./psalm | ./demo.fish; } > /dev/fd/0
#
# November 30, 2022 by Peter van Eerten.
#------------------------------------------------------

# Communicate with Psalm
function comm

    echo $argv
    read answer
end

# Declare global variable to store results from Psalm
set answer 0

# Send definitions first
comm "DEF libgtk-3.so.0 void gtk_init int int"
comm "DEF libgtk-3.so.0 long gtk_window_new int"
comm "DEF libgtk-3.so.0 void gtk_window_set_title int char*"
comm "DEF libgtk-3.so.0 void gtk_window_set_position long int"
comm "DEF libgtk-3.so.0 long gtk_button_new_with_label char*"
comm "DEF libgtk-3.so.0 long gtk_table_new int int int"
comm "DEF libgtk-3.so.0 void gtk_table_attach_defaults long long int int int int"
comm "DEF libgtk-3.so.0 void gtk_main_iteration void"
comm "DEF libgtk-3.so.0 void gtk_widget_show_all int"
comm "DEF libgtk-3.so.0 void gtk_widget_set_size_request long int int"
comm "DEF libgtk-3.so.0 void gtk_container_add long long"
comm "DEF libgobject-2.0.so.0 long g_signal_connect_data int char* address void* void* int"

# Setup GUI
comm "EXE gtk_init NULL NULL"
comm "EXE gtk_window_new 0"
set window $answer
comm "EXE gtk_window_set_title" $window "\"FishSHELL and Psalm demo\""
comm "EXE gtk_widget_set_size_request" $window 400 200
comm "EXE gtk_window_set_position" $window 1
comm "EXE gtk_table_new" 10 10 1
set table $answer
comm "EXE gtk_container_add" $window $table
comm "EXE gtk_button_new_with_label \"Click to Quit\""
set button $answer
comm "EXE gtk_table_attach_defaults" $table $button 5 9 5 9
comm "EXE gtk_widget_show_all" $window

# Connect signals
comm "EXE g_signal_connect_data " $window " delete-event callback NULL NULL 0"
comm "EXE g_signal_connect_data " $button " clicked callback NULL NULL 0"

# Initialize first
set event 0

# Mainloop
while test $event != $button -a $event != $window
    comm "EXE gtk_main_iteration"
    comm "CALLBACK 1"; set event $answer
end

# Exit Psalm
comm "EXIT"

Return to PSALM