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

KaoShell official release [1.2.6]

Started by KaoS, 01 May 2013 - 08:48 AM
KaoS #1
Posted 01 May 2013 - 10:48 AM
Hi all, I have decided to create a thread specifically for KaoShell as it has grown a bit too big to be included in my utils post

KaoShell is not an OS but it is as close as I will ever come to creating one. I prefer command line interfaces so I left the original shell in place, I just overrode the normal shell and re-inserted it with some major updates which are as follows:

Layer modification:
the term API has been largely changed so you can recall any text that is on the screen at any time with the term.getTextAt(x,y,len) function, it also implements a layering system so you can have a separate layers for different programs/functions, you can create a new layer with the term.newLayer([reference,tParams]) command which will then return a layer at y-index: reference (a higer numerical reference means it is rendered on top of lower references), you can term.redirect to layers and restore again and treat them as individual terms. tParams is a table of arguments that will be covered in the upcoming video tutorial (it will also include a lot more details on usage of the layer API and how it changes things)
A scroll bar has been added to the right of the screen showing how far the term layer has been scrolled and you can scroll layers by a negative number to scroll back upwards. A monitoring daemon has also been added for advanced computers so that if you scroll upwards or downwards or click the arrows on the scroll bar the screen scrolls in the appropriate direction, it also moves the cursor up when you scroll down etc so you do not lose your place

Messaging daemon:
Running in parallel with the shell is a coroutine to display messages, it uses the layer modification to display messages on layer 100, call os.queueEvent("message","This is a test message",5) to display "This is a test message" at the top of the screen for 5 seconds, the timout is optional and defaults to 2


Coroutine management:
On KaoShell execution the normal CC shell is re-executed but this time you can add additional coroutines which run in parallel with the top level shell (and the other KaoShell elements), simply call KaoShell.addCo(function,[reference,display]) to add a function that will be run in parallel with the shell, it will be stored in a table of coroutines that are organised by their reference numbers.
The addCo function returns the reference number of your thread once it is created, you can also specify a custom reference as the second argument in the function.
As your coroutines run you will be notified via the messaging daemon if there are any errors or if the coroutine terminates. If the third argument is true then you will not be notified when the coroutine terminates so you can make coroutines designed to run for a short while and then terminate.
Call KaoShell.remCo(reference,display) to instantly terminate a coroutine, if display is true it will show the normal temination message at the top of the screen.
Call KaoShell.getCo(reference) to get a coroutine table back in case you need to edit it
Rather than queuing events that get in the way of all of the other coroutines you can use KaoShell.queueEvent(reference, events) to queue events for a specific routine. I am thinking of adding an event filter where you can manage what kind of events are sent to certain coroutines but am not sure what security issues this would cause

myNet networking daemon:
The myNet addon is a rednet monitor that allows myNet computers to forward messages around, call myNet.send(message,[id]) to send a message to the specified computer ID running myNet or broadcast to all myNet computers in range, they will in turn forward the message on etc. call myNet.receive([timeout]) to receive myNet messages

Peripheral monitoring:
KaoShell computers are always watching for peripheral events, if a peripheral is attached or detached from the machine it displays a message at the top of the screen, notifying you. Any modems attached to the computer are automatically opened

Automated position tracking:
If a modem is attached to the computer when it starts up it will attempt to locate its position and store it in a hidden file where it will be read in future, if it is a turtle it will then try to move back, re-locate and move forward again. It will then use that information to calculate its facing.
You can also use KaoShell.setPos(x,y,z,face) to set it and KaoShell.getPos() to retrieve it.
Once the computer knows its position it acts as a GPS host in addition to its other activities, turtles track their position as they move and act as mobile GPS hosts (compatible with old and new GPS functionality)

Basic GUI API:
KaoShell includes a very basic GUI API that takes advantage of the layer addon and coroutine functions so you can add buttons to your screen with a single command, it is still in development.

FS override:
KaoShell overrides the default fs API to hide its core functions and files so they do not get in your way, you can create files with the same filenames as KaoShell files and it will redirect you to other files, use fs.old.list etc. to access these files if the need arises

Auto Update:
As new versions of KaoShell are released you will be automatically updated if your http API is enabled, if you want to opt out and keep the current version change the version number at the top of the file to 100, set it to 0 to force update. After an update the old KaoShell is backed up in KaoShell.bak in case you need to restore it

Variable Tab Completion:
I have modified the read function to auto-complete global variables when you press tab so
"str"+tab="string"
and
"str.du"+tab="string.dump"
etc. Keep pressing tab to cycle through the possible solutions, it separates these completions with spaces so
"randomstring str"+tab="randomstring string"
and if you press left arrow key to move the cursor back until it is on a different word it will tab complete that word. I also made it so read does not cling to its starting cursorPos, if you term.setCursorPos somewhere else it will move to that position.

Pastebin: http://pastebin.com/Yr3NQqQg

A video tutorial will be made soon with examples on how to use all of the above functions. If you have any functionality requests please ask, I especially need requests for the GUI API
Edited on 24 May 2013 - 06:27 AM
superaxander #2
Posted 03 May 2013 - 12:36 PM
Cool!
KaoS #3
Posted 03 May 2013 - 03:47 PM
Cool!
Thanks :)/> let me know if there are any problems in use
KaoS #4
Posted 11 May 2013 - 03:07 PM
updated to version 1.2, term.clearLine fixed and major speed update for rendering
KaoS #5
Posted 11 May 2013 - 04:55 PM
updated to version 1.2.1 to add variable tab completion
NeptunasLT #6
Posted 12 May 2013 - 05:12 AM
No pic's no Click's ;)/>
Espen #7
Posted 12 May 2013 - 06:38 AM
No pic's no Click's ;)/>
That's ironic, seeing that your very own Kalbex topic doesn't have pictures.
Don't give in to double-standards. Lead by example instead. ;)/>
KaoS #8
Posted 12 May 2013 - 06:41 AM
I'm actually trying to make a video tutorial but my recording program doesn't work when running minecraft for some reason :(/>

does anyone know of a good recording program I could use?
Espen #9
Posted 12 May 2013 - 06:45 AM
The most promiment ones that come to mind would be Dxtory and Fraps.
KaoS #10
Posted 12 May 2013 - 07:12 AM
Thanks Espen. I'll take a look when I get back from work
KaoS #11
Posted 12 May 2013 - 11:47 AM
version 1.2.3 out. 1.2.2 had a minor bugfix and 1.2.3 adds correct scrolling capability to the modified read function
KaoS #12
Posted 18 May 2013 - 03:10 PM
version 1.2.4: minor layer API bugfix with redirecting and restoring from layers (Incorrect cursor blink issue)
kelevra.1337 #13
Posted 22 May 2013 - 05:06 PM
I really like it, currently only using the coroutine management and already feel obligated to thank you for your work :)/>
KaoS #14
Posted 23 May 2013 - 02:25 AM
I really like it, currently only using the coroutine management and already feel obligated to thank you for your work :)/>

It's great to receive encouragement about this, I wasn't sure anyone used it lol :)/> Thanks for trying it out
KaoS #15
Posted 24 May 2013 - 06:13 AM
updated to 1.2.5 for a minor bugfix in the modified read function so it functions correctly when writing out of the current screen area
KaoS #16
Posted 24 May 2013 - 08:27 AM
I apologize for any inconvenience caused. Version 1.2.5 contained a major rendering bug which is now fixed. Version 1.2.6 out now
MCGamer20000 #17
Posted 13 June 2013 - 05:11 PM
There's a bug with the scrolling feature. I downloaded your mini menu program and if I scroll the bar on the right scrolls also and it messes up if I scroll lower then the shell.
Images:
Spoiler
Okay.

Bad
And, it messes up even built-in programs like edit.
Example:
SpoilerOn the shell. I scroll down:

I type: edit os

As you can see, the scroll bar is still down there. But sadly, the edit program uses the scroll bar itself… I scroll up…
So, what it should do is it should disable the scroll bar before executing the command entered in the shell and enable it after the program ends. And, there should be a command to enable/disable the scroll bar so a program can actually use it if they need it. Also, for full support with programs, the shell should scroll to the bottom before a command is executed and scroll back where it was after the program ends. Does this all sound good?
KaoS #18
Posted 15 June 2013 - 08:47 AM
There's a bug with the scrolling feature. I downloaded your mini menu program and if I scroll the bar on the right scrolls also and it messes up if I scroll lower then the shell.
Images:
Spoiler
Okay.

Bad
And, it messes up even built-in programs like edit.
Example:
SpoilerOn the shell. I scroll down:

I type: edit os

As you can see, the scroll bar is still down there. But sadly, the edit program uses the scroll bar itself… I scroll up…
So, what it should do is it should disable the scroll bar before executing the command entered in the shell and enable it after the program ends. And, there should be a command to enable/disable the scroll bar so a program can actually use it if they need it. Also, for full support with programs, the shell should scroll to the bottom before a command is executed and scroll back where it was after the program ends. Does this all sound good?

the menu program was designed on vanilla CraftOS, now multiple coroutines are detecting scrolls at the same time. If you like I can make a KaoShell compatible version

Edit used to have an issue as I had not overridden term.clearLine() correctly but I sorted that out… the scroll issue is on EDIT's side not my code. Normally you just don't notice it constantly scrolling
MCGamer20000 #19
Posted 02 July 2013 - 08:51 PM
Okay. Also, can you make it so it only try to render parts of layers that would be visible? (Using layer.scrolled) I tried to do it myself and failed badly.