Skip to content

Commit

Permalink
Rework console connection management, now exit (/ Ctrl+D) always clos…
Browse files Browse the repository at this point in the history
…es serial.

To quit, use "quit".
  • Loading branch information
bill88t committed Feb 6, 2024
1 parent 5d58c9c commit e0aca40
Show file tree
Hide file tree
Showing 7 changed files with 34 additions and 48 deletions.
1 change: 1 addition & 0 deletions LjinuxRoot/bin/_waitforconnection.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,3 +10,4 @@
ljinux.io.ledset(4)
time.sleep(0.2)
time.sleep(0.2) # Delay for the terminal to get used to it.
term.clear_line()
1 change: 0 additions & 1 deletion LjinuxRoot/bin/disconnect.lja

This file was deleted.

9 changes: 0 additions & 9 deletions LjinuxRoot/bin/disconnect.py

This file was deleted.

27 changes: 20 additions & 7 deletions LjinuxRoot/bin/exit.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,24 @@
rename_process("exit")
term.write("Bye")
if hasattr(term.console, "disconnect"):
# We are running on a remote shell
# Console can kick
term.write("Bye")
term.console.disconnect()
ljinux.based.run("runparts /etc/hooks/disconnect.d/")
else:
vr("Exit", True, pid=0)
try:
vr("Exit_code", int(ljinux.based.user_vars["argj"].split()[1]), pid=0)
except IndexError:
pass
# Console can't kick

if hasattr(term.console, "connected"):
if term.console.connected:
term.write("You can safely disconnect from the console.")
while term.console.connected:
time.sleep(0.1)
ljinux.based.run("runparts /etc/hooks/disconnect.d/")
else:
term.write("You can safely disconnect from the console.")
while term.detect_size() != False:
try:
time.sleep(2)
except KeyboardInterrupt:
pass
ljinux.based.run("runparts /etc/hooks/disconnect.d/")
ljinux.based.command.exec("/LjinuxRoot/bin/_waitforconnection.lja")
1 change: 1 addition & 0 deletions LjinuxRoot/bin/quit.lja
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
fpexec /bin/quit.py
6 changes: 6 additions & 0 deletions LjinuxRoot/bin/quit.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
rename_process("quit")
vr("Exit", True, pid=0)
try:
vr("Exit_code", int(ljinux.based.user_vars["argj"].split()[1]), pid=0)
except IndexError:
pass
37 changes: 6 additions & 31 deletions source/ljinux.py
Original file line number Diff line number Diff line change
Expand Up @@ -1805,35 +1805,11 @@ def shell(led: bool = True, nalias: bool = False) -> int:
ljinux.io.ledset(1) # idle
elif term.buf[0] is 2:
ljinux.io.ledset(2) # keyact
term.write("^D")
if hasattr(term.console, "disconnect"):
# We are running on a remote shell
term.write("Bye")
term.console.disconnect()
ljinux.based.run("runparts /etc/hooks/disconnect.d/")
elif term._active == False: # Can be None
# We want to disconnect from a passive console.
term.write(
"You can safely disconnect from the console."
)
while term.detect_size() != False:
try:
time.sleep(0.1)
except KeyboardInterrupt:
pass
time.sleep(0.5)
if not ljinux.api.console_connected():
ljinux.based.run(
"runparts /etc/hooks/disconnect.d/"
)
ljinux.based.command.exec(
"/LjinuxRoot/bin/_waitforconnection.lja"
)
term.clear_line()
else:
pv[0]["Exit"] = True
pv[0]["Exit_code"] = 0
ljinux.io.ledset(1) # idle
try:
term.write("^D")
except:
pass
ljinux.based.command.fpexec("/LjinuxRoot/bin/exit.py")
break
elif term.buf[0] is 3: # tab key
if len(term.buf[1]):
Expand Down Expand Up @@ -1936,13 +1912,12 @@ def shell(led: bool = True, nalias: bool = False) -> int:
term.focus = 0
ljinux.history.nav[0] = 0
elif term.buf[0] is 20: # console disconnected
time.sleep(0.5)
if not ljinux.api.console_connected():
ljinux.based.run("runparts /etc/hooks/disconnect.d/")
ljinux.based.command.exec(
"/LjinuxRoot/bin/_waitforconnection.lja"
)
term.clear_line()

if not pv[0]["Exit"]:
res = ""
if led:
Expand Down

0 comments on commit e0aca40

Please sign in to comment.