This is a read-only snapshot of the ComputerCraft forums, taken in April 2020.
SquidDev's profile picture

Mildly Better Shell - various extensions to the default shell

Started by SquidDev, 28 December 2017 - 06:07 PM
SquidDev #1
Posted 28 December 2017 - 07:07 PM
Mildly Better Shell (or mbs for short) is a series of extensions to the default shell which make it, well, mildly better. Heavily inspired by ClamShell, it aims to augment the existing environment without becoming a full operating system.

Features
Whilst there is a full list of features on the repository, here's a couple of exciting highlights:
  • History for Lua REPL and shell is preserved across restarts.
  • readline-esque keybindings to the read function, allowing easier editing of text.
  • Improved behaviour of full screen programs
  • The shell provides a scrollback, allowing you to see data which has disappeared off the screen.


Install
One should run the following commands in the shell:

wget https://raw.githubusercontent.com/SquidDev-CC/mbs/master/mbs.lua mbs
mbs install
reboot
This will generate the a startup file which loads the various extensions and runs the modified shell.

I recommend running this under a recent version of ComputerCraft (1.80pr1). MBS does technically support 1.79, but it's not my primary development version so I can't promise anything - sorry.

Configuring
mbs is relatively modular, using the settings API to configure given features. mbs is split into separate modules, each of which can be configured separately. Run mbs modules to see the various modules and mbs module [name] to see the various options. These can then be changed through ComputerCraft's builtin set command.

Found a bug?
I'm not surprised. I've done a reasonable amount of testing, but I'm sure there's some funky code which breaks everything. If you do find a bug, or just have some changes you'd like to see, do post an issue on the GItHub repository.
Edited on 29 December 2017 - 01:03 PM
Sewbacca #2
Posted 28 December 2017 - 11:00 PM
Just now I have modified the normal shell for scrolling. I wanted to post it here and then I saw that: "Mildly Better Shell - various extensions to the default shell" :D/>
Well, I will try it out your shell.

Edit:
So here is my lovely shell (stable on CC 1.7 probably till 1.79).

Feedback:
Well, it is pretty nice. How did you track fullscreen programs (I didn't looked at the code right now)? Edit: Okay, so term.clear() triggers fullscreen. MBS is awesome, but there is one thing I don't understand: Why are my inputs in Lua counted?

Edit: I think, I found an issue: https://github.com/SquidDev-CC/mbs/issues/1
Edited on 29 December 2017 - 12:37 AM
SquidDev #3
Posted 29 December 2017 - 11:40 AM
Just now I have modified the normal shell for scrolling.
Sorry! On the bright side, it's always good to have a little competition.

How did you track fullscreen programs (I didn't looked at the code right now)? Edit: Okay, so term.clear() triggers fullscreen.
As you say, term.clear() triggers the full screen mode. If the cursor moves above the shell prompt then said mode is also triggered: this catches cases where term.setCursorPos(1, 1) is used first.

Why are my inputs in Lua counted?
This is inspired by various mathematical tools such as Mathematica or Maxima (as well as IPython's REPL). One can reference the nth input with the _n variable (or out[n]). See this image for an example. This means you can just use the results of expressions without bothering about temporary variables.
SquidDev #4
Posted 29 December 2017 - 01:57 PM
Edit: I think, I found an issue: https://github.com/S...CC/mbs/issues/1
Thanks for the report! For whatever reason, I was reading a setting with a different name. I've fixed that, along with a couple of other issues. Rerunning mbs install should update to the latest version.
Lyqyd #5
Posted 29 December 2017 - 07:36 PM
This looks great!

If you're interested in adding piping/io redirection down the line, you might take a peek at how lsh does so. As far as I can tell, using the io library the way lsh does is both within the intended purpose of the library and the spirit of ComputerCraft, so it's one of the cleaner solutions to the problem.
SquidDev #6
Posted 29 December 2017 - 08:32 PM
If you're interested in adding piping/io redirection down the line, you might take a peek at how lsh does so.
Thanks!

Redirection/piping is something I'm rather on the fence about. On one hand, it's an insanely useful feature if you can get it to work. However, when I implemented something similar for ClamShell, it ended up being a lot code for a feature I didn't use very often.

It's been really interesting prodding through OpenOS's code (sorry) and seeing how they've designed their piping system. As it's baked into the operating system, it means everything plays nice together, but does lead to some rather weird implementations of standard utilities.
SquidDev #7
Posted 19 January 2018 - 11:56 AM
I've just made a couple of minor improvements to various parts of MBS. Aside from a few bug fixes, there's some new features too:
  • The readline module now allows you to use the mouse inside read. Cursor movement on long inputs is also different compared with CraftOS: the cursor can move freely and no longer hugs the right hand side.
  • Full screen programs which error will be drawn to the main terminal. Whilst this can have some strange effects, it's better than discarding the error message. I'm hoping to make some improvements in the future, but it's an acceptable stop-gap for now. That being said, I'd recommend disabling the shell module whilst working on GUIs, as I can't guarantee behaviour is the same as stock CraftOS.
Edited on 19 January 2018 - 10:57 AM
Wilma456 #8
Posted 19 January 2018 - 01:08 PM
Can you please make a PR that add some like scrolling in the shell to vanilla CC?
SquidDev #9
Posted 19 January 2018 - 01:33 PM
Can you please make a PR that add some like scrolling in the shell to vanilla CC?
Maybe in the future, but it's currently a long way from stable. It works for most things, but there are still some cases where a full-screen app won't do what you want it to do. Existing CC programs really aren't designed for this sort of thing, so anything we end up doing is a little hacky. We could have had the read changes built-in, but alas.
SquidDev #10
Posted 04 February 2018 - 02:47 PM
I've just pushed a new update with something I really should have had from the get go:



If your code throws an error, we'll try to display the stack trace so you can figure out the problem more easily. If the stack trace is really long, like in the picture, we'll truncate it so you're not scrolling for 200 lines. We also attempt to do some detection of when people intentionally error, such as when a program's arguments are invalid - in this case we won't display the stack trace.

Note there are some times when the traceback fails spectacularly, namely in the event of a stack overflow. In this case, I recommend turning the feature off by setting mbs.shell.traceback to false.

Also be warned that the trace may not always be as comprehensive as the one above - this was taken using Cobalt with the debug API enabled. If you're on a standard CC installation the trace will be still printed, but also be less informative.
Lupus590 #11
Posted 14 March 2018 - 12:15 AM
I wanted this on all of my computers so I created a script in my resource pack which deploys /.mbs/ to the computer from rom (to save on HTTP requests) and I thought I may as well share.


if not fs.exists("/.mbs") then --# we assume that this is a new computer if the folder is not pressent, additionally we can reinstall by deleting this folder.
    shell.run("copy /rom/.mbs /.mbs")

    --# add on the end of the startup file a command to start mbs
    local f = fs.open("/startup", "a")
    f.writeLine("\nshell.run(\"rom/programs/mbs.lua startup\")")
    f.close()
end
SquidDev #12
Posted 19 May 2018 - 05:24 PM
I've just added a couple of nifty features to the Lua shell, as well as a couple of other bugs.

Firstly, I've added stack tracebacks to the Lua REPL. This means it's much easier to see where an error occurred when experimenting with new code:


I've also rewritten the pretty printer that the Lua REPL uses. The biggest improvement is that the "layout" system has got an entire rewrite. It now tries to ensure the output fits on the screen, meaning it's much easier to get an overview of deeply nested tables. I've also added some basic colouring which helps various outputs stand out.



If you've got Lua's debug API enabled (using CC:T or CCTweaks), then it'll also show where functions are defined, instead of the random hash of numbers.

Feedback is welcome on all of this, especially on the pretty printer. I've tried to fix my biggest problems with the previous one, but do realise it may not suit everyone.
SquidDev #13
Posted 08 August 2018 - 09:15 PM
I thought I'd do another little status update, as it's been a while. There's been no "big major feature", but there are a couple of new nifty changes.

Firstly, pretty printing has been improved a little more. If possible, we'll display a functions arguments as well as its source location. This is insanely useful for getting an overview of an API:



This depends on some 5.2 changes to Lua's debug API, which I've backported to Cobalt. Thus this depends on the next version of CC:T, though hopefully we'll see it in normal CC one day!

I've also added a new module ("pager"), which allows changing how CC's textutils.paged* functions behave. We currently stick with the default behaviour, though you can set the mbs.pager.mode option to none to disable it entirely - which is rather useful when you have scrollback in the shell instead. I'm hoping to add an "actual" pager in the future, though it'll require a fair bit of work, so no promises there!

Lastly, I've fleshed out the readline module a little more, in order to even better replicate its namesake. We've now got all those useful commands you didn't even know existed like C-t (transpose characters), M-u (upcase word) and C-y (paste last deleted string). OK, the last one is useful a couple of times. You can see these in action here:

Edited on 08 August 2018 - 07:16 PM
SquidDev #14
Posted 23 February 2019 - 11:09 AM
There's been a couple of recent changes to mbs, which you may be interested in checking out:

Firstly, the Lua REPL now has some basic syntax highlighting:

The colours are mostly consistent with the pretty printer, hence them being a little different to what you'd see in edit. You can also set mbs.lua.highlight to false to disable this behaviour.

The mbs installer will now install itself as the first startup file, rather than the last one - this means any other startup files will be run within the mbs shell instead, rather than the CraftOS one. Note, you'll need to update your installer first, and then install mbs again - we should automatically transition any existing workspace.
CreeperGoBoom #15
Posted 17 December 2019 - 08:39 AM
How do I install this?


Install
One should run the following commands in the shell:

wget https://raw.githubusercontent.com/SquidDev-CC/mbs/master/mbs.lua mbs
mbs install
reboot



If i run said commands from shell i get bios[14]:1:"="expected
Lupus590 #16
Posted 17 December 2019 - 09:16 AM
Are you running latest computercraft for your MC version?
CreeperGoBoom #17
Posted 17 December 2019 - 09:23 AM
yes and prob sounds ancient at this point in time but thats the modpack. latest for 1.7.10
Lupus590 #18
Posted 17 December 2019 - 09:31 AM
Try manually downloading the sources from GitHub https://github.com/SquidDev-CC/mbs

I also have a resource pack which will install it for you https://github.com/lupus590/CC-My-Code-Pack

SquidDev would tell you to "let 1.7.10 go" https://camo.githubusercontent.com/25d412be7f079119e52b92fd0079a479f40b36ad/68747470733a2f2f73717569646465762e63632f722f6c65742d69742d312e372e31302e706e67
CreeperGoBoom #19
Posted 17 December 2019 - 09:59 AM
Haha :D/>

Never seen the movie but i fully get the reference.

Turns out Win7 is another one of those "Let it go" things XD.

Time to look for better modpacks.

Hmm…Or do I just make my own ^_^/>
Edited on 17 December 2019 - 09:00 AM