mirror of
https://github.com/Open-Argon/argon-v3.git
synced 2025-12-06 00:46:07 +00:00
add platform object
This commit is contained in:
7
go.mod
7
go.mod
@@ -9,7 +9,12 @@ require (
|
||||
|
||||
require (
|
||||
github.com/chzyer/readline v1.5.1 // indirect
|
||||
github.com/go-ole/go-ole v1.2.6 // indirect
|
||||
github.com/joho/godotenv v1.5.1 // indirect
|
||||
github.com/shirou/gopsutil v2.21.11+incompatible // indirect
|
||||
github.com/tklauser/go-sysconf v0.3.14 // indirect
|
||||
github.com/tklauser/numcpus v0.8.0 // indirect
|
||||
github.com/yusufpapurcu/wmi v1.2.4 // indirect
|
||||
)
|
||||
|
||||
require (
|
||||
@@ -21,7 +26,7 @@ require (
|
||||
github.com/jwalton/go-supportscolor v1.1.0
|
||||
github.com/mattn/go-colorable v0.1.13 // indirect
|
||||
github.com/mattn/go-isatty v0.0.17 // indirect
|
||||
golang.org/x/sys v0.6.0 // indirect
|
||||
golang.org/x/sys v0.19.0 // indirect
|
||||
golang.org/x/term v0.6.0
|
||||
golang.org/x/text v0.8.0
|
||||
)
|
||||
|
||||
13
go.sum
13
go.sum
@@ -6,6 +6,8 @@ github.com/fatih/color v1.14.1 h1:qfhVLaG5s+nCROl1zJsZRxFeYrHLqWroPOQ8BWiNb4w=
|
||||
github.com/fatih/color v1.14.1/go.mod h1:2oHN61fhTpgcxD3TSWCgKDiH1+x4OiDVVGH8WlgGZGg=
|
||||
github.com/gabriel-vasile/mimetype v1.4.2 h1:w5qFW6JKBz9Y393Y4q372O9A7cUSequkh1Q7OhCmWKU=
|
||||
github.com/gabriel-vasile/mimetype v1.4.2/go.mod h1:zApsH/mKG4w07erKIaJPFiX0Tsq9BFQgN3qGY5GnNgA=
|
||||
github.com/go-ole/go-ole v1.2.6 h1:/Fpf6oFPoeFik9ty7siob0G6Ke8QvQEuVcuChpwXzpY=
|
||||
github.com/go-ole/go-ole v1.2.6/go.mod h1:pprOEPIfldk/42T2oK7lQ4v4JSDwmV0As9GaiUsvbm0=
|
||||
github.com/joho/godotenv v1.5.1 h1:7eLL/+HRGLY0ldzfGMeQkb7vMd0as4CfYvUVzLqw0N0=
|
||||
github.com/joho/godotenv v1.5.1/go.mod h1:f4LDr5Voq0i2e/R5DDNOoa2zzDfwtkZa6DnEwAbqwq4=
|
||||
github.com/jwalton/go-supportscolor v1.1.0 h1:HsXFJdMPjRUAx8cIW6g30hVSFYaxh9yRQwEWgkAR7lQ=
|
||||
@@ -15,12 +17,21 @@ github.com/mattn/go-colorable v0.1.13/go.mod h1:7S9/ev0klgBDR4GtXTXX8a3vIGJpMovk
|
||||
github.com/mattn/go-isatty v0.0.16/go.mod h1:kYGgaQfpe5nmfYZH+SKPsOc2e4SrIfOl2e/yFXSvRLM=
|
||||
github.com/mattn/go-isatty v0.0.17 h1:BTarxUcIeDqL27Mc+vyvdWYSL28zpIhv3RoTdsLMPng=
|
||||
github.com/mattn/go-isatty v0.0.17/go.mod h1:kYGgaQfpe5nmfYZH+SKPsOc2e4SrIfOl2e/yFXSvRLM=
|
||||
github.com/shirou/gopsutil v2.21.11+incompatible h1:lOGOyCG67a5dv2hq5Z1BLDUqqKp3HkbjPcz5j6XMS0U=
|
||||
github.com/shirou/gopsutil v2.21.11+incompatible/go.mod h1:5b4v6he4MtMOwMlS0TUMTu2PcXUg8+E1lC7eC3UO/RA=
|
||||
github.com/tklauser/go-sysconf v0.3.14 h1:g5vzr9iPFFz24v2KZXs/pvpvh8/V9Fw6vQK5ZZb78yU=
|
||||
github.com/tklauser/go-sysconf v0.3.14/go.mod h1:1ym4lWMLUOhuBOPGtRcJm7tEGX4SCYNEEEtghGG/8uY=
|
||||
github.com/tklauser/numcpus v0.8.0 h1:Mx4Wwe/FjZLeQsK/6kt2EOepwwSl7SmJrK5bV/dXYgY=
|
||||
github.com/tklauser/numcpus v0.8.0/go.mod h1:ZJZlAY+dmR4eut8epnzf0u/VwodKmryxR8txiloSqBE=
|
||||
github.com/wadey/go-rounding v1.1.0 h1:RAs9dMkB/uUHFv9ljlbRFC8/kBrQ5jhwt1GQq+2cciY=
|
||||
github.com/wadey/go-rounding v1.1.0/go.mod h1:/uD953tCL6Fea2Yp+LZBBp8d60QSObkMJxY6SPOJ5QE=
|
||||
github.com/yusufpapurcu/wmi v1.2.4 h1:zFUKzehAFReQwLys1b/iSMl+JQGSCSjtVqQn9bBrPo0=
|
||||
github.com/yusufpapurcu/wmi v1.2.4/go.mod h1:SBZ9tNy3G9/m5Oi98Zks0QjeHVDvuK0qfxQmPyzfmi0=
|
||||
golang.org/x/crypto v0.7.0 h1:AvwMYaRytfdeVt3u6mLaxYtErKYjxA2OXjJ1HHq6t3A=
|
||||
golang.org/x/crypto v0.7.0/go.mod h1:pYwdfH91IfpZVANVyUOhSIPZaFoJGxTFbZhFTx+dXZU=
|
||||
golang.org/x/net v0.8.0 h1:Zrh2ngAOFYneWTAIAPethzeaQLuHwhuBkuV6ZiRnUaQ=
|
||||
golang.org/x/net v0.8.0/go.mod h1:QVkue5JL9kW//ek3r6jTKnTFis1tRmNAW2P1shuFdJc=
|
||||
golang.org/x/sys v0.0.0-20190916202348-b4ddaad3f8a3/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
|
||||
golang.org/x/sys v0.0.0-20201119102817-f84b799fce68/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
|
||||
golang.org/x/sys v0.0.0-20210220050731-9a76102bfb43/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
|
||||
golang.org/x/sys v0.0.0-20220310020820-b874c991c1a5/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
|
||||
@@ -29,6 +40,8 @@ golang.org/x/sys v0.3.0 h1:w8ZOecv6NaNa/zC8944JTU3vz4u6Lagfk4RPQxv92NQ=
|
||||
golang.org/x/sys v0.3.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
|
||||
golang.org/x/sys v0.6.0 h1:MVltZSvRTcU2ljQOhs94SXPftV6DCNnZViHeQps87pQ=
|
||||
golang.org/x/sys v0.6.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
|
||||
golang.org/x/sys v0.19.0 h1:q5f1RH2jigJ1MoAWp2KTp3gm5zAGFUTarQZ5U386+4o=
|
||||
golang.org/x/sys v0.19.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA=
|
||||
golang.org/x/term v0.0.0-20210220032956-6a3ed077a48d h1:SZxvLBoTP5yHO3Frd4z4vrF+DBX9vMVanchswa69toE=
|
||||
golang.org/x/term v0.0.0-20210220032956-6a3ed077a48d/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo=
|
||||
golang.org/x/term v0.6.0 h1:clScbb1cHjoCkyRbWwBEUZ5H/tIFu5TAXIqaZD0Gcjw=
|
||||
|
||||
@@ -9,6 +9,7 @@ func makeGlobal() ArObject {
|
||||
var vars = anymap{}
|
||||
vars["global"] = vars
|
||||
vars["env"] = env
|
||||
vars["platform"] = platform
|
||||
vars["term"] = ArTerm
|
||||
vars["ArgonVersion"] = ArString(VERSION)
|
||||
vars["ArgonVersionNumber"] = newNumber().SetInt64(VERSION_NUM)
|
||||
|
||||
@@ -10,8 +10,8 @@ var Args = os.Args[1:]
|
||||
|
||||
type stack = []ArObject
|
||||
|
||||
const VERSION = "3.0.9"
|
||||
const VERSION_NUM = 7
|
||||
const VERSION = "3.0.10"
|
||||
const VERSION_NUM = 8
|
||||
|
||||
func newscope() ArObject {
|
||||
return Map(anymap{})
|
||||
|
||||
49
src/platform.go
Normal file
49
src/platform.go
Normal file
@@ -0,0 +1,49 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"runtime"
|
||||
"time"
|
||||
|
||||
"github.com/shirou/gopsutil/cpu"
|
||||
)
|
||||
|
||||
var platform = Map(
|
||||
anymap{
|
||||
"os": ArString(runtime.GOOS),
|
||||
|
||||
"cpu": Map(anymap{
|
||||
"count": newNumber().SetInt64((int64)(runtime.NumCPU())),
|
||||
"usage": builtinFunc{"usage", func(args ...any) (any, ArErr) {
|
||||
if len(args) != 2 {
|
||||
return nil, ArErr{
|
||||
TYPE: "Runtime Error",
|
||||
message: "usage takes 2 arguments, got " + fmt.Sprint(len(args)),
|
||||
EXISTS: true,
|
||||
}
|
||||
}
|
||||
if !isAnyNumber(args[0]) {
|
||||
return nil, ArErr{
|
||||
TYPE: "Runtime Error",
|
||||
message: "first argument is meant to be a number, got " + fmt.Sprint(typeof(args[0])),
|
||||
EXISTS: true,
|
||||
}
|
||||
}
|
||||
var Number = newNumber().Mul(args[0].(number), newNumber().SetInt64(1000)).Num().Int64()
|
||||
avgPercent, err := cpu.Percent(time.Duration(Number)*time.Millisecond, anyToBool(args[1]))
|
||||
if err != nil {
|
||||
return nil, ArErr{
|
||||
TYPE: "Runtime Error",
|
||||
message: err.Error(),
|
||||
EXISTS: true,
|
||||
}
|
||||
}
|
||||
var ArAvgPercent = []any{}
|
||||
for i := 0; i < len(avgPercent); i++ {
|
||||
ArAvgPercent = append(ArAvgPercent, newNumber().SetFloat64(avgPercent[i]))
|
||||
}
|
||||
return ArArray(ArAvgPercent), ArErr{}
|
||||
}},
|
||||
}),
|
||||
},
|
||||
)
|
||||
@@ -14,7 +14,7 @@ func shell(global ArObject) {
|
||||
go func() {
|
||||
for sig := range c {
|
||||
if sig == os.Interrupt {
|
||||
fmt.Println("\x1b[0m\n\x1b[32;5;240mBye :)\x1b[0m")
|
||||
fmt.Println("\x1b[0m\n\x1b[32;240mBye :)\x1b[0m")
|
||||
os.Exit(0)
|
||||
}
|
||||
}
|
||||
@@ -27,7 +27,7 @@ func shell(global ArObject) {
|
||||
textBefore := ">>>"
|
||||
for i := 1; indent > 0 || (previous != indent && indent >= 0) || i == 1; i++ {
|
||||
indentStr := strings.Repeat(" ", indent)
|
||||
inp, err := input("\x1b[38;240m" + textBefore + indentStr + " \x1b[0m\x1b[1;240m")
|
||||
inp, err := input("\x1b[38;240m" + textBefore + indentStr + " \x1b[0m")
|
||||
if err != nil {
|
||||
fmt.Println("\x1b[0m\n\x1b[32;240mBye :)\x1b[0m")
|
||||
os.Exit(0)
|
||||
|
||||
Reference in New Issue
Block a user