Compare commits

...

3 commits

21 changed files with 1439 additions and 94 deletions

View file

@ -23,6 +23,7 @@ test -f ~/.profile.js && chmod +x ~/.profile.js && ~/.profile.js | grep -v undef
## forward not-found commands to javascript (via jsh)
command_not_found_handle(){
set +e
echo "[!] '$1' not found, did you mean $1(...) (javascript?)"
test -n "$ONBOARDING" && echo "[i] type 'help' for handy commands"
test -n "$ONBOARDING" || help_tips
@ -65,15 +66,21 @@ which screen &> /dev/null && {
test -n "$STY" || {
resize # call twice
resize # otherwise COLUMNS/ROWS is 0
# add URL-hash as extra screen session
test -z "$HASH" || {
grep 'screen -t #' /root/.screenrc || {
echo "screen -t xrsh+URL 3 /bin/sh -c '${HASH}; sh'" | sed "s/'#/'/g" >> /root/.screenrc
}
}
screen -Aa -R -T screen-256color -c /root/.screenrc
# resize # call twice
# resize # otherwise COLUMNS/ROWS is 0
# # add URL-hash as extra screen session
# test -z "$HASH" || {
# grep 'screen -t #' /root/.screenrc || {
# echo "screen -t xrsh+URL 3 /bin/sh -c 'source /etc/profile.sh; ${HASH}; sh'" | sed "s/'#/'/g" >> /root/.screenrc
# }
# }
# execute URL hash or GNU screen
test -n "$HASH" && hook URI/fragment "${HASH:1}"
test -z "$HASH" && screen -Aa -R -T screen-256color -c /root/.screenrc
}
test -n "$STY" && {
resize # call twice
resize # otherwise COLUMNS/ROWS is 0
test -f /root/motd && cat /root/motd || cat /etc/motd;
say "welcome to eex r, shell. For an optimal user experience, connect a Bluetooth keyboard." &
}

View file

@ -8,7 +8,7 @@ hook(){
logger " |+ hook $hook $*"
{ $hook "$@" || true; } | awk '{ gsub(/\/root\/\//,"",$1); $1 = sprintf("%-40s", $1)} 1'
done
} &> ~/hook.d/log.txt
} | tee -a ~/hook.d/log.txt
}
alert(){
@ -46,6 +46,7 @@ console(){
#
# info: adds javascript/css url/script to DOM
require(){
test -n "$1" || { echo "usage: require <url>"; exit 0; }
file=$(basename "$1")
ext="${file/*\./}"

View file

@ -58,7 +58,7 @@ test -d /dev/browser || {
setup_mounts(){
mkdir /mnt/helloworld /mnt/THREE
fusescript /root/fs/helloworld /mnt/helloworld
fusescript /root/fs/THREE.js /mnt/THREE
fusescript /root/fs/THREE /mnt/THREE
}
modprobe fuse # load fuse

View file

@ -9,5 +9,5 @@ exitVR
exitAR
tail -n1 -f /dev/browser/console /var/log/messages
require https://snips.sh/f/VBz-iWm8so?r=1
require https://xrfragment.org/example/assets/index.glb
require https://coderofsalvation.github.io/xrsh-media/assets/background.glb
a-gltf-model https://xrfragment.org/example/assets/index.glb
a-gltf-model https://coderofsalvation.github.io/xrsh-media/assets/background.glb

View file

@ -27,6 +27,9 @@ cd(){
}
}
# get latest xrfragments to support interactive models
require https://xrfragment.org/dist/xrfragment.aframe.js
# start index.js if /dev/browser/js filesize is not great than 0
if [ ! -s /dev/browser/js ]; then
chmod +x /mnt/root/index.js && /mnt/root/index.js | grep -v undefined

View file

@ -1,7 +1,11 @@
#!/bin/sh
test -n "$1" || { echo "usage: a-gltf-model <gltf-file>"; exit; }
file="$(readlink -f "$1")"
file="${file#/}" # strip leading slash if present
file="$1"
echo "$file" | grep -q http || {
file="$(readlink -f "$1")"
file="${file#/}" # strip leading slash if present
file="file://xrsh/$file"
}
echo "<a-gltf-model src='file://xrsh/$file'></a-gltf-model>" >> /root/index.html
echo "<a-gltf-model src='$file'></a-gltf-model>" >> /root/index.html

View file

@ -0,0 +1,4 @@
#!/bin/sh
test -n "$1" || { echo "usage: teleport <http://...foo.glb>"; exit 0; }
echo "" > ~/index.html # empty scene
a-gltf-model $*

View file

@ -8,6 +8,7 @@ logger "$0: extracting $file"
mkdir -p "/root/$dir"
cd "/root/$dir"
unzip "$file"
cd "/root/$dir" # trigger auto-env (.env file)
test -f .env && test "$(cat ~/.config/autoenv/package)" = 1 && {
logger "$0: detected $(pwd)/.env [autoenv]"

View file

@ -0,0 +1,71 @@
#!/bin/sh
# virtual file interface for THREE
STATE=/run/THREE
LOG=~/.fuse.log
update(){
js '
let fuse_dir = () => '16877 2 0 0 4096 8'
let fuse_file = (size) => `33188 1 0 0 ${size||1} 1`
function traverseScene(object, path = '/', result = '') {
const objectName = object.name? object.name : object.id;
result += `${path}${objectName} ${fuse_dir()}\n`;
result += `${path}${objectName}/position ${fuse_dir()}\n`;
result += `${path}${objectName}/position/x ${fuse_file()}\n`;
result += `${path}${objectName}/position/y ${fuse_file()}\n`;
result += `${path}${objectName}/position/z ${fuse_file()}\n`;
result += `${path}${objectName}/rotation ${fuse_dir()}\n`;
result += `${path}${objectName}/rotation/x ${fuse_file()}\n`;
result += `${path}${objectName}/rotation/y ${fuse_file()}\n`;
result += `${path}${objectName}/rotation/z ${fuse_file()}\n`;
if( object.userData ){
result += `${path}${objectName}/userData 1 1 1 1\n`;
for( let k in object.userData )
result += `${path}${objectName}/userData/${k} 1 1 1 1\n`;
}
object.children.forEach(child => {
result = traverseScene(child, `${path}${objectName}/`, result);
});
return result;
}
return traverseScene( document.querySelector('a-scene').object3D );
' > $STATE
}
readdir(){ # print first column [filename] from header
test -f $STATE || update
awk '/^#\'$1'/ {
gsub("^#'$1'[/]?","",$1); # strip dirname
gsub("\\/.*","",$1); # strip subdirs/files
if( $1 ) print $1
}' $STATE | uniq
}
getattr(){ # print column 2 till 7 from header
awk '$1 == "#'$1'" { print $2" "$3" "$4" "$5" "$6" "$7 }' $STATE
grep -qE '#$1' $0 || return 2 # FUSE expects -NOENT if file does not exist
}
read(){ # print everything (data) after 7th column
awk '$1 == "#'$1'" { $1=$2=$3=$4=$5=$6=$7=""; sub(/^ +/, ""); print $0 }' $0
}
getxattr(){ # print xattr value from commentheader
awk '$1 == "#xattr:'$1'" && $2 == "'$2'" { print $3 }' $STATE
}
setxattr(){ # save xattr value from commentheader
file=$1 ; key=$2 ; shift; shift
sed -i "s/^#xattr:\\$key .*/#xattr:\\$key $*" $STATE || echo "#xattr:$file $key $*" >> $0
}
listxattr(){ # list xattr keys
awk '$1 == "#xattr:'$1'" { printf("%s\0",$2) }' $STATE
}
echo "> $0 $*" >> $LOG
"$@" | tee -a $LOG

View file

@ -1,14 +1,13 @@
#!/bin/js
// Function to handle getattr command
function getattr(path,obj) {
function getattr(path,opts){
let size = 1
if (path === '/' || path.match(/\/[0-9]+$/) ) {
return "16877 2 1000 1000 4096 8\n"
if (path === '/' || opts.obj ){
return "16877 2 0 0 4096 8\n"
} else {
return `33188 1 1000 1000 ${size} 1\n`
return `33188 1 0 0 ${size} 1\n`
}
return ''
}
function getPath(str){
@ -18,22 +17,23 @@ function getPath(str){
const parent = path.pop()
let obj = name == ""
? scene
: scene.getObjectById( parseInt(name.substr(1)) )
const propvalue = ""
if( obj && obj[ name ] ) propvalue = obj[name]
return {obj,propname:name,propvalue}
: scene.getObjectByName( name ) ||
scene.getObjectById( parseInt(name.substr(1)) )
console.dir({parent,name,obj})
return {obj,propname:name}
}
// Main function to handle commands
function main(args) {
console.log( 'fs/THREE '+args.join(' ') )
let children = ''
let props = ['name','uuid','position','rotation']
let props = ['uuid','position','rotation']
switch (args[0]) {
case 'readdir':{
const {obj,propvalue,propname} = getPath( args[1] )
const {obj} = getPath( args[1] )
if( obj && obj.children ){
children = obj.children.map( (n) => n.name || n.id )
.join("\n")
@ -43,14 +43,14 @@ function main(args) {
}
case 'getattr':{
const {obj,propvalue,propname} = getPath( args[1] )
return getattr(args[1],{args,obj,propvalue,propname});
const opts = getPath( args[1] )
return getattr(args[1],{...opts, args});
break;
}
case 'read':{
const {propvalue,propname} = getPath( args[1] )
return propvalue;
const {obj,propname} = getPath( args[1] )
return obj[propname];
break;
}
@ -62,3 +62,4 @@ function main(args) {
// Run the main function
return main(args.slice(1));

View file

@ -13,10 +13,10 @@ echo "$0 $*" >> $LOG
# format: mode nlink uid gid size block
case "$2" in
/)
echo "16877 2 1000 1000 4096 8" && exit 0 # dir (mode 0755)
echo "16877 2 0 0 4096 8" && exit 0 # dir (mode 0755)
;;
/file1)
echo "33188 1 1000 1000 ${#file1} 1" && exit 0 # file (mode 0644, size 6)
echo "33188 1 0 0 ${#file1} 1" && exit 0 # file (mode 0644, size 6)
;;
esac
exit 1

View file

@ -20,8 +20,8 @@ function log_command() {
}
function print_getattr(p) {
if (p == "/") print "16877 2 1000 1000 4096 8"
else if (p == "/file1") print "33188 1 1000 1000 " length(file1) " 1"
if (p == "/") print "16877 2 0 0 4096 8"
else if (p == "/file1") print "33188 1 0 0 " length(file1) " 1"
else exit 1
}

View file

@ -6,9 +6,9 @@ const file1 = "hello world";
// Function to handle getattr command
function getattr(path) {
if (path === '/') {
return "16877 2 1000 1000 4096 8"
return "16877 2 0 0 4096 8"
} else if (path === '/file1') {
return `33188 1 1000 1000 ${file1.length} 1`
return `33188 1 0 0 ${file1.length} 1`
} else {
return ''
}

View file

@ -7,8 +7,8 @@ local function log_command(args)
end
local function getattr(path)
if path == "/" then print("16877 2 1000 1000 4096 8")
elseif path == "/file1" then print(string.format("33188 1 1000 1000 %d 1", #file1))
if path == "/" then print("16877 2 0 0 4096 8")
elseif path == "/file1" then print(string.format("33188 1 0 0 %d 1", #file1))
else os.exit(1) end
end

View file

@ -4,7 +4,7 @@ LOG_PATH = os.path.join(os.getenv("HOME", "/tmp"), ".fuse.log")
file1 = "hello world"
def log(msg): open(LOG_PATH, "a").write(msg + "\n")
def getattr(path): return {"16877 2 1000 1000 4096 8" if path == "/" else f"33188 1 1000 1000 {len(file1)} 1"} if path in ["/", "/file1"] else None
def getattr(path): return {"16877 2 0 0 4096 8" if path == "/" else f"33188 1 0 0 {len(file1)} 1"} if path in ["/", "/file1"] else None
def readdir(): print("file1")
def read(path): print(file1) if path == "/file1" else sys.exit(1)

View file

@ -0,0 +1,6 @@
#!/bin/sh
source /etc/profile.sh # expose xrsh cmds like require etc
echo "" # clear line
$* # simply execute
echo "$*" >> /tmp/frag.log

View file

@ -0,0 +1 @@
../../../../bin/ziprun

View file

@ -1,8 +1,17 @@
#!/bin/sh
test -n "$1" || { echo "usage: codemirror <file>"; exit 0; }
test -n "$1" || { echo "usage: codemirror <file> <x> <y> <z>"; exit 0; }
me="$(dirname $(readlink -f $0))"
set -e
me="$(dirname $(readlink -f $0))"
file="$(readlink -f "$1")"
$me/codemirror.js "$file"
if [[ "$1" =~ ^http ]]; then
file="$(basename "$1")"
test -f $file && rm $file # *TODO* ask permission
wget "${1/*:\/\/}"
else
file="$(readlink -f "$1")"
fi
$me/codemirror.js "$file" $2 $3 $4
echo "press ctrl-Q to exit editor"

View file

@ -1,6 +1,6 @@
#!/bin/js
if( args[1] == undefined ) return "usage: codemirror <file>"
let keymap = "default" // "vim"
if( AFRAME.components.codemirror ) delete AFRAME.components.codemirror
AFRAME.registerComponent('codemirror', {
@ -9,6 +9,7 @@ AFRAME.registerComponent('codemirror', {
term: { type:"selector", default: "[isoterminal]" },
width: { type:"number", default:700},
height: { type:"number", default:500},
keymap: { type:"string", default:"default"}
},
init: function () {
@ -40,34 +41,34 @@ AFRAME.registerComponent('codemirror', {
css: (me) => `.CodeMirror{
width: ${me.com.data.width}px !important;
height: ${me.com.data.height-30}px !important;
}
.cm-s-shadowfox .CodeMirror-cursor {
}
.cm-s-shadowfox .CodeMirror-cursor {
border-left: 10px solid #a5f !important;
visibility: visible !important;
}
.codemirror *{
font-size: 14px;
font-family: "Cousine",Liberation Mono,DejaVu Sans Mono,Courier New,monospace;
font-weight:500 !important;
letter-spacing: 0 !important;
text-shadow: 0px 0px 10px #F075;
}
}
.codemirror *{
font-size: 14px;
font-family: "Cousine",Liberation Mono,DejaVu Sans Mono,Courier New,monospace;
font-weight:500 !important;
letter-spacing: 0 !important;
text-shadow: 0px 0px 10px #F075;
}
.wb-body:has(> .codemirror){
overflow:hidden;
}
.wb-body:has(> .codemirror){
overflow:hidden;
}
.CodeMirror {
margin-top:18px;
}
.cm-s-shadowfox.CodeMirror {
background:transparent !important;
}
`
.CodeMirror {
margin-top:18px;
}
.cm-s-shadowfox.CodeMirror {
background:transparent !important;
}
`
},
createEditor: function(value){
this.el.setAttribute("window", `title: codemirror; uid: ${this.el.dom.id}; attach: #overlay; dom: #${this.el.dom.id}; width: ${this.data.width}px; height: ${this.data.height}px; class: no-full, no-resize`)
this.el.setAttribute("window", `title: codemirror; uid: ${this.el.dom.id}; attach: #overlay; dom: #${this.el.dom.id}; width: ${this.data.width}px; height: ${this.data.height}px; class: no-full, no-max, no-resize`)
this.editor = CodeMirror( this.el.dom, {
value,
mode: this.data.file.match(/\.js$/) ? "text/javascript" :
@ -80,6 +81,7 @@ AFRAME.registerComponent('codemirror', {
lineNumbers: true,
styleActiveLine: true,
matchBrackets: true,
keyMap: this.data.keymap,
Tab: "indentMore",
defaultTab: function(cm) {
if (cm.somethingSelected()) cm.indentSelection("add");
@ -92,15 +94,17 @@ AFRAME.registerComponent('codemirror', {
this.el.emit('close',true) // window.js will react accordingly
}
})
this.editor.updateFile = AFRAME.utils.throttle( (file,str) => {
this.updateFile(file,str)
}, 1500)
this.editor.updateFile = (file,str) => {
clearTimeout( this.editor.updateFile.tid)
setTimeout( (file,str) => {
this.updateFile(file,str)
},500, file,str)
}
this.editor.on('change', (instance,changeObj) => {
this.editor.updateFile( this.data.file, instance.getValue() )
})
this
.handleFocus()
this.handleFocus()
setTimeout( () => {
this.el.setAttribute("html-as-texture-in-xr", `domid: #${this.el.dom.id}`) // only show aframe-html in xr
@ -137,15 +141,15 @@ AFRAME.registerComponent('codemirror', {
DOMready: function(e){
this.isoterminal.worker.read_file(this.data.file)
.then( this.isoterminal.convert.Uint8ArrayToString )
.then( (str) => {
console.log("creating editor: "+this.data.file)
this.createEditor( str )
})
.catch( (e) => {
console.log("error opening "+this.data.file+", creating new one")
this.createEditor("")
})
.then( this.isoterminal.convert.Uint8ArrayToString )
.then( (str) => {
console.log("creating editor: "+this.data.file)
this.createEditor( str )
})
.catch( (e) => {
console.log("error opening "+this.data.file+", creating new one")
this.createEditor("")
})
},
},
@ -198,33 +202,39 @@ This is a help file which describes the application.
It will be rendered thru troika text, and will contain
headers based on non-punctualized lines separated by linebreaks,
in above's case "\nHelloworld application\n" will qualify as header.
`
`
}
});
AFRAME.utils.require({
codemirrorjs: "https://cdnjs.cloudflare.com/ajax/libs/codemirror/5.58.1/codemirror.js",
codemirrorcss: "https://cdnjs.cloudflare.com/ajax/libs/codemirror/5.35.0/codemirror.css",
cmtheme: "https://cdnjs.cloudflare.com/ajax/libs/codemirror/5.35.0/theme/shadowfox.css"
codemirrorjs: "https://cdnjs.cloudflare.com/ajax/libs/codemirror/5.58.1/codemirror.js",
codemirrorcss: "https://cdnjs.cloudflare.com/ajax/libs/codemirror/5.35.0/codemirror.css",
cmtheme: "https://cdnjs.cloudflare.com/ajax/libs/codemirror/5.35.0/theme/shadowfox.css"
})
.then( () => AFRAME.utils.require({
.then( () => {
let extras = {
cmxml: "https://cdnjs.cloudflare.com/ajax/libs/codemirror/5.35.0/mode/xml/xml.js",
cmjavascript: "https://cdnjs.cloudflare.com/ajax/libs/codemirror/5.35.0/mode/javascript/javascript.js",
cmcss: "https://cdnjs.cloudflare.com/ajax/libs/codemirror/5.35.0/mode/css/css.js",
cmlua: "https://cdnjs.cloudflare.com/ajax/libs/codemirror/5.35.0/mode/lua/lua.js",
cmpython: "https://cdnjs.cloudflare.com/ajax/libs/codemirror/5.35.0/mode/python/python.js",
cmmarkdown: "https://cdnjs.cloudflare.com/ajax/libs/codemirror/5.35.0/mode/markdown/markdown.js",
highlight: "https://cdnjs.cloudflare.com/ajax/libs/codemirror/5.35.0/mode/htmlmixed/htmlmixed.js",
})
)
.then( () => {
let el = document.createElement("a-entity")
el.setAttribute("codemirror", `file: ${args[1]}`)
document.querySelector("a-scene").appendChild(el)
highlight: "https://cdnjs.cloudflare.com/ajax/libs/codemirror/5.35.0/mode/htmlmixed/htmlmixed.js"
}
if( keymap == "vim" ) extras.cmvim = "https://cdnjs.cloudflare.com/ajax/libs/codemirror/5.35.0/keymap/vim.js";
return AFRAME.utils.require(extras)
})
.then( () => {
let el = document.createElement("a-entity")
el.setAttribute("codemirror", `file: ${args[1]}`)
if( args.length == 5 ){
el.setAttribute("position",`${args[2]} ${args[3]} ${args[4]}`)
}
document.querySelector("a-scene").appendChild(el)
})
return "" // empty stdout(put)
// for shellscript-equivalent see bin/codemirror
return "" // empty stdout(put)

File diff suppressed because it is too large Load diff

BIN
dist/v86-linux.iso vendored

Binary file not shown.