Skip to content

Commit

Permalink
webconsole improvements
Browse files Browse the repository at this point in the history
  • Loading branch information
refaktor committed Apr 21, 2024
2 parents 2b4c3c1 + 5236b5f commit d6b447d
Show file tree
Hide file tree
Showing 8 changed files with 126 additions and 22 deletions.
6 changes: 5 additions & 1 deletion evaldo/builtins.go
Original file line number Diff line number Diff line change
Expand Up @@ -7399,7 +7399,11 @@ var builtins = map[string]*env.Builtin{
Argsn: 1,
Doc: "",
Fn: func(ps *env.ProgramState, arg0 env.Object, arg1 env.Object, arg2 env.Object, arg3 env.Object, arg4 env.Object) env.Object {
return *env.NewString(strings.Join(os.Args[2:], " "))
if len(os.Args) > 1 {
return *env.NewString(strings.Join(os.Args[2:], " "))
} else {
return *env.NewString("")
}
// block, _ := loader.LoadString(os.Args[0], false)
// return block
},
Expand Down
42 changes: 42 additions & 0 deletions evaldo/builtins_math.go
Original file line number Diff line number Diff line change
Expand Up @@ -271,6 +271,48 @@ var Builtins_math = map[string]*env.Builtin{
}
},
},
"atan2": {
Argsn: 2,
Doc: "Returns the arc tangent of y/x, using the signs of the two to determine the quadrant of the return value.",
Fn: func(ps *env.ProgramState, arg0 env.Object, arg1 env.Object, arg2 env.Object, arg3 env.Object, arg4 env.Object) env.Object {
switch val := arg0.(type) {
case env.Integer:
switch val2 := arg1.(type) {
case env.Integer:
return *env.NewDecimal(math.Atan2(float64(val.Value), float64(val2.Value)))
case env.Decimal:
return *env.NewDecimal(math.Atan2(float64(val.Value), val2.Value))
default:
return MakeArgError(ps, 2, []env.Type{env.IntegerType, env.DecimalType}, "atan2")
}
case env.Decimal:
switch val2 := arg1.(type) {
case env.Integer:
return *env.NewDecimal(math.Atan2(val.Value, float64(val2.Value)))
case env.Decimal:
return *env.NewDecimal(math.Atan2(val.Value, val2.Value))
default:
return MakeArgError(ps, 2, []env.Type{env.IntegerType, env.DecimalType}, "atan2")
}
default:
return MakeArgError(ps, 1, []env.Type{env.IntegerType, env.DecimalType}, "atan2")
}
},
},
"atanh": {
Argsn: 1,
Doc: "Returns the inverse hyperbolic tangent.",
Fn: func(ps *env.ProgramState, arg0 env.Object, arg1 env.Object, arg2 env.Object, arg3 env.Object, arg4 env.Object) env.Object {
switch val := arg0.(type) {
case env.Integer:
return *env.NewDecimal(math.Atanh(float64(val.Value)))
case env.Decimal:
return *env.NewDecimal(math.Atanh(val.Value))
default:
return MakeArgError(ps, 1, []env.Type{env.IntegerType, env.DecimalType}, "atanh")
}
},
},
"pi": {
Argsn: 0,
Doc: "Return Pi constant.",
Expand Down
17 changes: 11 additions & 6 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -98,21 +98,26 @@ func main() {

evaldo.ShowResults = !*silent

var code string
if *do != "" {
code = *do
}

// Check for --help flag
if flag.NFlag() == 0 && flag.NArg() == 0 {
main_rye_repl(os.Stdin, os.Stdout, true, false)
if Option_Do_Main {
ryeFile := dotsToMainRye(".")
main_rye_file(ryeFile, false, true, *console, code)
} else {
main_rye_repl(os.Stdin, os.Stdout, true, false)
}
} else {
// Check for --help flag
if *help {
flag.Usage()
os.Exit(0)
}

var code string
if *do != "" {
code = *do
}

args := flag.Args()
// Check for subcommands (cont) and handle them
if len(args) > 0 {
Expand Down
44 changes: 32 additions & 12 deletions planing.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# Planning

---
## For 0.0.16 [+]

### Subc flag default [++]
Expand Down Expand Up @@ -39,6 +39,8 @@ is approachable than shell, which is contrary to what I thought.
We shell needs to support multiline, for some examples in docs to work. It can work the same as Regular shell, where if the last character is space it goes into multiline mode. In this case the space character should be made visible, via
something like middot or a newline like character. Or / and it could look for open parenthesis and go into multiple lines until it's closed.

---

## For 0.0.17 [+]

### Command line arguments improvement [++]
Expand Down Expand Up @@ -76,6 +78,8 @@ users .left-join groups 'group_id 'id
* function arguments are defines inside parenthesis, like math syntax usually is
* added math subcontext that includes typical math functions and math dialect, added first few

---

## For 0.0.18

### Rye force console, silent, do, help, dot behaviour [++]
Expand All @@ -93,19 +97,23 @@ Let state saves be encrypted with password and console_.....rye.enc ask for same
+ walk - useful for dialects, recursive algos, ...
+ xword, exword improvements, xword accepts args, equality - matching still works

### Import function , current path / script [--]
### Import function , current path / script [++]

Import function like "do load %file" but only looks for files local to the main script file or current script file basically.
Try to make import always relative to current script, so interpreter should have a concept of "current script" at loplevel. Maybe a specific "do" variant that is invoked in improt and is script location aware.

This would also be needed for loader errors in case of multiple files, so you know what file the loader failed.

### Improve errors with current path / script [--]
---

## For 0.0.19

### Improve errors with current path / script [+-]

At least loader errors should be able to display filename next to location. Toplevel code at least should also be aware of script filename, or should we look in direction of a stacktrace. Would we need to manually manage the stack of callees'
maybe only in debug flag since it would impact performance. Maybe functionname => number of calls so recursion doesn't push out the stack info.

### Liner with standard ansi colors, some improvements [--]
### Liner with standard ansi colors, some improvements [+-]

Test using standard colors, we will see if they work in Emacs ansi-term then, we will see if maybe general terminal theming works on them, also xterm.js probably has theming, test it, make build flag if possible, update refaktor/liner for it.

Expand All @@ -117,22 +125,32 @@ We could also try to add some low hanging fruit improvements of syntax highlighe
- More key combinations (ctrl-d, ...)
- Sole keys (pageup, pagedown)

## LATER

### Math dialect fwd

Let math dialect call rye functions also, not just builtins. It would be good if we could just use function "math" ... not context math and in it function math or math/do ... but still preserve the usable context too. Hmmmm ....
Let math dialect call rye functions also, not just builtins. It would be good if we could just use function "math" ... not context math and in it function math or math/do ... but still preserve the usable context too.

Pratik is adding standard math functions from https://pkg.go.dev/math to the context.

### Devops context fwd [+-]

- Integrate relevant function from https://github.com/shirou/gopsutil [++]
- Create standard commands / utils like cd / ls / mkdir / cp / mv [+-]
- Integrate awesome script library for many standard piping commands https://github.com/bitfield/script [--]

### do_main build flag and Android test [+-]

if build flag do_main is used make the dot behaviour work even without the dot. Usefull for distributing binary and main.rye , also to test to produce a mobil APK with Fyne.

---

## LATER

### Mod-words - experiment

`word:: ::word` would be mod-words and would allow changing existing values to words. So set-words would only create and fail if word already is set in current context. Mod-words would only change and fail if word
is not yet defined. We rarely modify at all ... to much modifying is a smell that code could be written better. word:: visually is not horrible, or that noticable, but jsut noticable enough I think. So let's do this and
we will see what practice shows. For starters just add it to loader but it could behave the same as set-word so we woule volontarily use it and see hot it looks and feels at all. If it seems ok, we change the interpreter.

### do_main build flag and Android test

if build flag do_main is used make the dot behaviour work even without the dot. Usefull for distributing binary and main.rye , also to test to produce a mobil APK with Fyne.

### MakeArgError improve output

We could try to display more information at MakeArgError. We know what type the value was. We don't but if we knew the names of arguments it would be even better. But builtins in Rye currently don't have named
Expand All @@ -158,7 +176,9 @@ rye . --do 'init' # TODO runs main.rye and function init
rye --do 'print 123 + 123' --quit # TODO
```

## Random ideas
---

## RANDOM

### ~~Smart history v01 (just ideas)~~

Expand Down
2 changes: 1 addition & 1 deletion serve_wasm.rye
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

rye .needs { http }

new-server ":8085"
http-server ":8085"
|handle "/" new-static-handler %wasm
|serve

22 changes: 22 additions & 0 deletions tests/misc.rye
Original file line number Diff line number Diff line change
Expand Up @@ -382,10 +382,32 @@ section "Math functions"
equal { do\in math { atan 1 } } 0.7853981633974483
}

<<<<<<< HEAD

=======
group "atan2"
mold\nowrap ""
{ { string } }
{
equal { do\in math { atan2 3 4 } } 0.6435011087932844
}

group "atanh"
mold\nowrap ""
{ { string } }
{
equal { do\in math { atanh 0.5 } } 0.5493061443340548
}


>>>>>>> 5236b5f75f0221676742cd7157b7d35167348d33
; TODO add sin and cos ... need PI constant

}

<<<<<<< HEAD

end
=======
end
>>>>>>> 5236b5f75f0221676742cd7157b7d35167348d33
3 changes: 3 additions & 0 deletions util/microliner.go
Original file line number Diff line number Diff line change
Expand Up @@ -464,6 +464,9 @@ startOfHere:
line = line[:pos]
s.needRefresh = true
}
case "l":
s.eraseScreen()
s.needRefresh = true
}
} else if next.Alt {
switch strings.ToLower(next.Key) {
Expand Down
12 changes: 10 additions & 2 deletions wasm/ryeshell/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -261,15 +261,23 @@ <h3 style="font-family: mono; font-weight: normal; font-size: 14px; color: #999;
convertEol: true,
rows: 30,
})

// term.setOption('theme', theme)
term.options.theme = theme;
// term.setOption('theme', theme)
term.options.cursorBlink = true;
// term.loadAddon(fitAddon)
// fitAddon.fit()


term.attachCustomKeyEventHandler((arg) => {
if (arg.ctrlKey && arg.code === "KeyV" && arg.type === "keydown") {
navigator.clipboard.readText()
.then(text => {
term.write(text);
})
};
return true;
});
// term.open(document.getElementById('terminal-container'))

// var term = new Terminal();
Expand Down

0 comments on commit d6b447d

Please sign in to comment.