various unix utilities to interface with browser
/ test (push) Successful in 4s
Details
/ test (push) Successful in 4s
Details
This commit is contained in:
parent
3c8d84c46d
commit
7bfa591536
|
@ -82,7 +82,30 @@ AFRAME.registerComponent('isoterminal', {
|
||||||
//var term = new Terminal()
|
//var term = new Terminal()
|
||||||
//term.open(dom)
|
//term.open(dom)
|
||||||
//term.write('Hello from \x1B[1;3;31mxterm.js\x1B[0m $ ')``
|
//term.write('Hello from \x1B[1;3;31mxterm.js\x1B[0m $ ')``
|
||||||
|
if( typeof Terminal == undefined ) throw 'xterm terminal not loaded'
|
||||||
|
// monkeypatch Xterm (which V86 initializes) so we can add our own constructor args
|
||||||
|
window._Terminal = window.Terminal
|
||||||
|
window.Terminal = function(opts){
|
||||||
|
const term = new window._Terminal({ ...opts,
|
||||||
|
cursorBlink:true,
|
||||||
|
onSelectionChange: function(e){
|
||||||
|
debugger
|
||||||
|
}
|
||||||
|
})
|
||||||
|
|
||||||
|
term.onSelectionChange( () => {
|
||||||
|
document.execCommand('copy')
|
||||||
|
term.select(0, 0, 0)
|
||||||
|
instance.setStatus('copied to clipboard')
|
||||||
|
})
|
||||||
|
return term
|
||||||
|
}
|
||||||
|
|
||||||
|
instance.setStatus = (msg) => {
|
||||||
|
const w = instance.winbox
|
||||||
|
w.titleBak = w.titleBak || w.title
|
||||||
|
instance.winbox.setTitle( `${w.titleBak} [${msg}]` )
|
||||||
|
}
|
||||||
|
|
||||||
var emulator = window.emulator = dom.emulator = new V86({
|
var emulator = window.emulator = dom.emulator = new V86({
|
||||||
wasm_path: "com/isoterminal/v86.wasm",
|
wasm_path: "com/isoterminal/v86.wasm",
|
||||||
|
@ -157,7 +180,9 @@ AFRAME.registerComponent('isoterminal', {
|
||||||
"com/isoterminal/mnt/confirm",
|
"com/isoterminal/mnt/confirm",
|
||||||
"com/isoterminal/mnt/prompt",
|
"com/isoterminal/mnt/prompt",
|
||||||
"com/isoterminal/mnt/alert",
|
"com/isoterminal/mnt/alert",
|
||||||
|
"com/isoterminal/mnt/hook",
|
||||||
"com/isoterminal/mnt/profile",
|
"com/isoterminal/mnt/profile",
|
||||||
|
"com/isoterminal/mnt/profile.js",
|
||||||
"com/isoterminal/mnt/motd",
|
"com/isoterminal/mnt/motd",
|
||||||
]
|
]
|
||||||
|
|
||||||
|
|
|
@ -1,2 +1,2 @@
|
||||||
#!/bin/sh
|
#!/bin/sh
|
||||||
jsh alert "$1"
|
echo "$(printf "\033[0m")[i] [38;5;165m$1 $(printf "\033[0m")"
|
||||||
|
|
|
@ -1,10 +1,4 @@
|
||||||
#!/bin/sh
|
#!/bin/sh
|
||||||
test -f /mnt/V86 && {
|
|
||||||
jsh confirm $1 $2
|
|
||||||
}
|
|
||||||
|
|
||||||
test -f /mnt/V86 || {
|
|
||||||
read -p "$(printf "\033[0m")[?] [38;5;165m$1 [y/n] $(printf "\033[0m")" y
|
read -p "$(printf "\033[0m")[?] [38;5;165m$1 [y/n] $(printf "\033[0m")" y
|
||||||
test $y = y && echo true && exit
|
test $y = y && echo true && exit
|
||||||
echo false
|
echo false
|
||||||
}
|
|
||||||
|
|
|
@ -1,7 +0,0 @@
|
||||||
PS3="Enter a number: "
|
|
||||||
|
|
||||||
select character in Sheldon Leonard Penny Howard Raj
|
|
||||||
do
|
|
||||||
echo "Selected character: $character"
|
|
||||||
echo "Selected number: $REPLY"
|
|
||||||
done
|
|
|
@ -0,0 +1,15 @@
|
||||||
|
#!/bin/sh
|
||||||
|
|
||||||
|
test -z $1 && { echo "usage: hook <cmd_or_jsfunction> [args]"; exit 0; }
|
||||||
|
|
||||||
|
cmd=$1
|
||||||
|
shift
|
||||||
|
|
||||||
|
test -d ~/hook.d/$cmd && {
|
||||||
|
chmod +x ~/hook.d/$cmd/*
|
||||||
|
find ~/hook.d/$cmd/ -type f -executable | while read hook; do
|
||||||
|
$hook "$@" || true
|
||||||
|
done
|
||||||
|
}
|
||||||
|
|
||||||
|
#test $BROWSER = 1 && {
|
|
@ -1,5 +1,16 @@
|
||||||
#!/bin/sh
|
#!/bin/sh
|
||||||
flock /dev/browser/js -c "echo '$*' > /dev/browser/js; cat /dev/browser/js"
|
test -z $1 && { echo "Usage: js 'somefunction(1)'"; exit 0; }
|
||||||
|
|
||||||
|
javascript="$*"
|
||||||
|
|
||||||
|
# if we are run as shebang, use the file as input
|
||||||
|
case "$1" in
|
||||||
|
*/*) javascript="$(cat $1 | tail +2)"
|
||||||
|
;;
|
||||||
|
esac
|
||||||
|
|
||||||
|
|
||||||
|
flock /dev/browser/js -c "echo '$javascript' > /dev/browser/js; sleep 0.5; cat /dev/browser/js"
|
||||||
|
|
||||||
# we use flock, an awesome way to make processes read/write the same file
|
# we use flock, an awesome way to make processes read/write the same file
|
||||||
# whilr preventing 1001 concurrency issues
|
# while preventing 1001 concurrency issues
|
||||||
|
|
|
@ -7,11 +7,31 @@ to_js(){
|
||||||
printf "%s(" "$1"
|
printf "%s(" "$1"
|
||||||
shift
|
shift
|
||||||
for arg in "$@"; do
|
for arg in "$@"; do
|
||||||
|
case "$arg" in
|
||||||
|
(*[\.0-9]*)
|
||||||
|
printf '%s,' "$arg"
|
||||||
|
;;
|
||||||
|
(*)
|
||||||
printf '"%s",' "$arg"
|
printf '"%s",' "$arg"
|
||||||
|
;;
|
||||||
|
esac
|
||||||
done
|
done
|
||||||
printf ")\n"
|
printf ")\n"
|
||||||
}
|
}
|
||||||
|
|
||||||
|
# run argument as js
|
||||||
|
test -z $1 || {
|
||||||
func=$(to_js "$@")
|
func=$(to_js "$@")
|
||||||
func=${func/,)/)}
|
func=${func/,)/)}
|
||||||
/mnt/js "$func"
|
js "$func"
|
||||||
|
}
|
||||||
|
|
||||||
|
# otherwise start repl
|
||||||
|
while true; do
|
||||||
|
echo -n "$(printf "\033[0m")jsh> $(printf "\033[0m")"
|
||||||
|
read input
|
||||||
|
test $input = exit && exit
|
||||||
|
js "$input"
|
||||||
|
done
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -1,16 +1,34 @@
|
||||||
install_xrsh(){
|
install_xrsh(){
|
||||||
chmod +x /mnt/confirm /mnt/prompt /mnt/alert /mnt/js*
|
|
||||||
|
setup_binaries(){
|
||||||
|
for bin in /mnt/prompt /mnt/alert /mnt/confirm /mnt/hook /mnt/js*; do
|
||||||
|
chmod +x $bin
|
||||||
|
ln -s $bin /bin/.
|
||||||
|
done
|
||||||
|
}
|
||||||
|
|
||||||
setup_browser_dev(){
|
setup_browser_dev(){
|
||||||
mkdir -p /mnt/dev/browser
|
mkdir -p /mnt/dev/browser
|
||||||
touch /mnt/dev/browser/js
|
touch /mnt/dev/browser/js
|
||||||
touch /mnt/dev/browser/html
|
touch /mnt/dev/browser/html
|
||||||
|
touch /mnt/dev/browser/console
|
||||||
ln -s /mnt/dev/browser /dev/browser
|
ln -s /mnt/dev/browser /dev/browser
|
||||||
test -f /etc/profile && rm /etc/profile
|
test -f /etc/profile && rm /etc/profile
|
||||||
ln -s /mnt/profile /etc/profile
|
ln -s /mnt/profile /etc/profile
|
||||||
}
|
}
|
||||||
|
|
||||||
|
setup_hook_dirs(){ # see /mnt/hook for usage
|
||||||
|
mkdir -p ~/hook.d/alert
|
||||||
|
mkdir -p ~/hook.d/confirm
|
||||||
|
mkdir -p ~/hook.d/prompt
|
||||||
|
echo -e "#!/bin/sh\necho yo" > ~/hook.d/alert/yo
|
||||||
|
echo -e "#!/bin/js\nalert('yo')" > ~/hook.d/alert/yo.js
|
||||||
|
echo -e "#!/usr/bin/lua\nalert('yo')" > ~/hook.d/alert/yo.lua
|
||||||
|
}
|
||||||
|
|
||||||
|
setup_binaries
|
||||||
setup_browser_dev
|
setup_browser_dev
|
||||||
|
setup_hook_dirs
|
||||||
}
|
}
|
||||||
|
|
||||||
test -d /dev/browser || install_xrsh
|
test -d /dev/browser || install_xrsh
|
||||||
|
@ -21,9 +39,20 @@ test -f /mnt/V86 && {
|
||||||
echo 0 > /proc/sys/kernel/printk
|
echo 0 > /proc/sys/kernel/printk
|
||||||
}
|
}
|
||||||
|
|
||||||
|
## forward not-found commands to javascript (via jsh)
|
||||||
|
command_not_found_handle(){
|
||||||
|
echo "$1 not found"
|
||||||
|
alert "did you mean $1(...) (javascript?)"
|
||||||
|
alert "TIP: run 'jsh $1 hello' to run $1('hello')"
|
||||||
|
alert " or simply 'jsh' for a js console"
|
||||||
|
}
|
||||||
|
|
||||||
|
# source javascript functions
|
||||||
|
#js "$(cat /mnt/profile.js)"
|
||||||
|
|
||||||
resize
|
resize
|
||||||
#clear
|
#clear
|
||||||
cat /mnt/motd
|
cat /mnt/motd
|
||||||
export PATH=$PATH:/mnt
|
export PATH=$PATH:/mnt
|
||||||
export PS1="\n[38;5;57mx[38;5;93mr[38;5;129ms[38;5;165mh [38;5;201m# \033[0m"
|
export PS1="\n[38;5;57mx[38;5;93mr[38;5;129ms[38;5;165mh [38;5;201m# \033[0m"
|
||||||
|
export BROWSER=0 # running inside v86 (wasm) will set this to 1
|
||||||
|
|
|
@ -0,0 +1,3 @@
|
||||||
|
window.helloworld = function(){
|
||||||
|
alert("hello world")
|
||||||
|
}
|
|
@ -1,9 +1,3 @@
|
||||||
#!/bin/sh
|
#!/bin/sh
|
||||||
test -f /mnt/V86 && {
|
|
||||||
jsh prompt "$1" "$2"
|
|
||||||
}
|
|
||||||
|
|
||||||
test -f /mnt/V86 || {
|
|
||||||
read -p "$(printf "\033[0m")[?] [38;5;165m$1: $(printf "\033[0m")" answer
|
read -p "$(printf "\033[0m")[?] [38;5;165m$1: $(printf "\033[0m")" answer
|
||||||
echo "$answer"
|
echo "$answer"
|
||||||
}
|
|
||||||
|
|
Loading…
Reference in New Issue