# test the vtty widget
# Compiled by:
#
src/lib/x-kit/tut/widget/widgets.libstipulate
include package threadkit; # threadkit is from
src/lib/src/lib/thread-kit/src/core-thread-kit/threadkit.pkg #
package fil = file__premicrothread; # file__premicrothread is from
src/lib/std/src/posix/file--premicrothread.pkg package rx = run_in_x_window_old; # run_in_x_window_old is from
src/lib/x-kit/widget/old/lib/run-in-x-window-old.pkg package top = hostwindow; # hostwindow is from
src/lib/x-kit/widget/old/basic/hostwindow.pkg package wg = widget; # widget is from
src/lib/x-kit/widget/old/basic/widget.pkg package wa = widget_attribute_old; # widget_attribute_old is from
src/lib/x-kit/widget/old/lib/widget-attribute-old.pkg package wy = widget_style_old; # widget_style_old is from
src/lib/x-kit/widget/old/lib/widget-style-old.pkg package vt = virtual_terminal; # virtual_terminal is from
src/lib/x-kit/widget/old/text/virtual-terminal.pkgherein
package test_vtty: api {
do_it': (List(String), String) -> Void;
do_it: Void -> Void;
main: (List(String), X) -> Void;
}
{
resources = [
"*background: forestgreen"
];
fun tester root
=
{ top::start_widgettree_running_in_hostwindow hostwindow;
loop ();
}
where
fun quit ()
=
{ wg::delete_root_window root;
shut_down_thread_scheduler 0;
};
style = wg::style_from_strings (root, resources);
name = wy::make_view
{ name => wy::style_name [],
aliases => [ wy::style_name [] ]
};
view = (name, style);
vtty = vt::make_virtual_terminal root { rows => 24, cols => 80 };
my (ins, outs)
=
vt::open_virtual_terminal vtty;
hostwindow_args
=
[ (wa::title, wa::STRING_VAL "test"),
(wa::icon_name, wa::STRING_VAL "test")
];
hostwindow = top::hostwindow
(root, view, hostwindow_args)
(vt::as_widget vtty);
fun cat_file fname
=
{ inf = fil::open_for_read fname;
#
fun out_f ()
=
case (fil::read_n (inf, 1024))
#
"" => ();
s => { file::write (outs, s);
out_f ();
};
esac;
out_f ();
fil::close_input inf;
}
except
io_exceptions::IO { name, op, ... }
=
file::write (outs, (name + " " + op + "\n"));
fun cat [] => file::write (outs, "cat: missing file name\n");
cat files => apply cat_file files;
end;
fun loop ()
=
for (;;) {
file::write (outs, "> ");
file::flush outs;
line = file::read_line ins;
fun do_cmd ("cat" ! t) => cat t;
do_cmd ("quit" ! _) => quit ();
#
do_cmd ("help" ! _) => file::write (outs, "Commands: cat <files>, quit, help\n");
do_cmd (s ! _) => file::write (outs, "Unknown command: " + s + "\n");
#
do_cmd [] => ();
end;
do_cmd (string::tokens char::is_space (the line));
};
end; # fun tester
fun do_it' (debug_flags, server)
=
{ xlogger::init debug_flags;
#
rx::run_in_x_window_old' tester [ rx::DISPLAY server ];
};
fun do_it ()
=
rx::run_in_x_window_old tester;
fun main (program ! server ! _, _) => do_it' ([], server);
main _ => do_it ();
end;
}; # package test_vtty
end;