Skip to content

Commit

Permalink
Optimise and update modules
Browse files Browse the repository at this point in the history
  • Loading branch information
bill88t committed Jun 12, 2024
1 parent b6a7a94 commit b53b5fe
Show file tree
Hide file tree
Showing 7 changed files with 41 additions and 74 deletions.
1 change: 1 addition & 0 deletions Boardfiles/m5stack_cardputer/boot.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
00-gpio.py
00-no-dmesg.lja
01-early-connection.py
02-LEDs.py
03-reload-hostname.py
Expand Down
1 change: 1 addition & 0 deletions base/Beryllium/bin/help.lja
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
fpexec /bin/help.py
22 changes: 22 additions & 0 deletions base/Beryllium/bin/help.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
rename_process("help")
term.write(
f"LNL {colors.magenta_t}based{colors.endc}\nThese shell commands are defined internally or are in PATH.\nType 'help' to see this list.\n{colors.green_t}"
)

vr("lt", set(be.based.get_bins() + be.based.get_internal()))
vr("l", [])
vr("lenn", 0)
for pv[get_pid()]["i"] in vr("lt"):
if not vr("i").startswith("_"):
vr("l").append(vr("i"))
if len(vr("i")) > vr("lenn"):
vr("lenn", len(vr("i")))

vrp("lenn", 2)
vr("l").sort()

for pv[get_pid()]["index"], pv[get_pid()]["tool"] in enumerate(vr("l")):
term.write(vr("tool"), end=(" " * vr("lenn")).replace(" ", "", len(vr("tool"))))
if vr("index") % 4 == 3:
term.write()
term.write(colors.endc)
2 changes: 1 addition & 1 deletion packages/nano
Submodule nano updated 2 files
+1 −1 files/Manifest.json
+1 −1 files/main.py
2 changes: 1 addition & 1 deletion packages/neofetch
85 changes: 14 additions & 71 deletions source/be.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
# ------------------------------------- #
# Beryllium OS #
# #
# No security means no backdoors :) #
# ------------------------------------- #
# ------------------------------------ #
# Beryllium OS #
# #
# I'm crying, pls no more optimisation #
# ------------------------------------ #

# Process stuffs
pv = {} # Process variable container storage
Expand Down Expand Up @@ -325,15 +325,6 @@ def dmtex(
# From now on use dmtex
dmtex("Dmesg ready")

use_compiler = False
try:
compile("", "", "exec")

use_compiler = True
dmtex("Kernel compiler enabled")
except NameError:
dmtex("Kernel compiler disabled")

try:
from neopixel_write import neopixel_write
except ImportError:
Expand Down Expand Up @@ -394,11 +385,6 @@ def dmtex(
del optt, optt_dt

del defaultoptions
gc.collect()
gc.collect()

dmtex(f"Board memory: " + str(gc.mem_alloc() + gc.mem_free()) + " bytes")
dmtex(f"Memory free: " + str(gc.mem_free()) + " bytes")


def systemprints(mod: int, tx1: str, tx2: str = None) -> None:
Expand Down Expand Up @@ -538,22 +524,6 @@ def idfu() -> int:
self.key = key
self.id = idfu

def remove_ansi(text: str) -> str:
"""
Remove all ansi from a given string.
"""
result = ""
i = 0
while i < len(text):
if text[i : i + 2] == "\033[": # Skip
while i < len(text) and text[i] != "m":
i += 1
i += 1
else:
result += text[i]
i += 1
return result

def getvar(var: str):
"""
Get a system user variable without mem leaks
Expand Down Expand Up @@ -1071,13 +1041,12 @@ def code_load(filename: str):
else:
prog = be.code_cache[filename]
return prog
if use_compiler:
prog = compile(prog, filename, "exec")
if gc.mem_free() > 200_000:
be.code_cache[filename] = prog
elif len(be.code_cache):
# We should clear the cache.
be.code_cache.clear()
prog = compile(prog, filename, "exec")
if gc.mem_free() > 200_000:
be.code_cache[filename] = prog
elif len(be.code_cache):
# We should clear the cache.
be.code_cache.clear()
return prog

def adv_input(whatever, _type=str):
Expand Down Expand Up @@ -1347,14 +1316,13 @@ def error(wh=3, f=None, prefix=f"{colors.magenta_t}Based{colors.endc}") -> None:
10: "File exists",
11: "Not enough system memory",
12: "Based: Error, variable already used",
13: f"Terminal too small, minimum size: {f}",
14: "Is a file",
15: "Is a directory",
16: "Directory not empty",
17: "Not a directory",
18: "Not a file",
19: "Not a device",
20: f"Unhandled exception:\n",
20: "Unhandled exception:\n",
}
term.write(f"{prefix}: {errs[wh]}")
if wh == 20:
Expand Down Expand Up @@ -1382,9 +1350,7 @@ def process_failure(err) -> None:
for i in erl:
term.write(i)
term.write(
"Please take note of the above information and report it"
+ " to your system administrator for further assistance.\n"
+ "If you plan on opening a Github issue, "
"If you plan on opening a Github issue, "
+ "please provide this information along with the program.\n"
)
if ( # Restore dir
Expand Down Expand Up @@ -1502,28 +1468,6 @@ def exec(inpt: str) -> None:
except OSError:
be.based.error(4, vr("inpt")[0])

def help(inpt: str) -> None:
term.write(
f"LNL {colors.magenta_t}based{colors.endc}\nThese shell commands are defined internally or are in PATH.\nType 'help' to see this list.\n{colors.green_t}"
)

lt = set(be.based.get_bins() + be.based.get_internal())
l = []
lenn = 0
for i in lt:
if not i.startswith("_"):
l.append(i)
if len(i) > lenn:
lenn = len(i)
lenn += 2
l.sort()

for index, tool in enumerate(l):
term.write(tool, end=(" " * lenn).replace(" ", "", len(tool)))
if index % 4 == 3:
term.write()
term.write(colors.endc)

def var(inpt: str): # variables setter / editor
valid = True
inpt = inpt.split(" ")
Expand Down Expand Up @@ -1679,8 +1623,7 @@ def history(inpt): # history frontend

def pexec(inpt): # Python exec
launch_process("pexec")
if use_compiler:
inpt = compile(inpt, "pexec", "exec")
inpt = compile(inpt, "pexec", "exec")
gc.collect()
try:
exec(inpt)
Expand Down
2 changes: 1 addition & 1 deletion source/jcurses
Submodule jcurses updated 1 files
+2 −0 jcurses.py

0 comments on commit b53b5fe

Please sign in to comment.