- Sky
- Blueberry
- Slate
- Blackcurrant
- Watermelon
- Strawberry
- Orange
- Banana
- Apple
- Emerald
- Chocolate
- Charcoal
mpmxyz
-
Content Count
56 -
Joined
-
Last visited
-
Days Won
24
Posts posted by mpmxyz
-
-
I suppose that you want to edit a file via the ingame program 'edit' and it's opening only in 'readonly' mode, right?
(hint: Take your time when writing your question; others - like me - might need to read it twice to find out where your sentences end and what exactly your problem is. ;-) )
Back to the problem:
If your filesystem is readonly it is most likely because you booted from an OpenOS floppy disk.
To be able to modify files you need to install OpenOS on a hard disk drive. (shell command: install)
Then remove the floppy disk and reboot.
Now you can edit all libraries, programs etc. via 'edit'.
-
I had some fun playing around with this.
Here some hints for improvement:
Did you know you could rewrite the following line
{["state"]=3, ["posX"]=2, ["posY"]=2, ["pitch"]=25},
to
{state=3, posX=2, posY=2, pitch=25},
?
It does exactly the same and isn't cluttered with brackets and quotes.
And you should definitely try two for loops to create your buttons:
--iterate through posY = 2,3,4 ... 16 for posY = 2,16 do local row = {} --add table row to the list buttons table.insert(buttons, row) --iterate through posX = 2,5,8 ... 44 (notice how the third parameter = 3 defines how much posX is changing) for posX = 2,44,3 do --create a table for the button and add it to the row table.insert(row, {state=3, posX=posX, posY=posY, pitch=25}) end end
(That saves ~250 lines of code and makes it easier to move the buttons! :-))
If you have a question about this code: Feel free to ask!
-
You mean this one?
https://github.com/OpenPrograms/Magik6k-Programs/blob/master/libdeflate/deflate.lua
That would at least enable extracting tar.gz files. (no compressing though...)
I could add this with an optional dependency.
If it isn't too complex I might even write another program + library to do both compressing and uncompressing.
(The file format doesn't look as complicated as *.tar; I just need to find a good reference for all the algorithms involved.)
In either case I'd let you know. ;-)
PS: If I decide to create such a library I'd also split the *.tar program into a program and a library. To make installation easier I'd have to create an installer program, too. (So much on my TODO list now. xD)
-
Introduction
If you already know 'tar' and tar archives:
Yes, this is a tar implementation for OpenComputers.
It supports viewing, extracting and even creating archives on tape and file.
It supports most of the original tar format and the long name part of the ustar extension.
You can now skip the introduction.
Now for everyone else:
'tar' is a very old archive file format originating from early UNIX days.
It is an uncompressed archive format with the built in ability to store everything from files and directories to symbolic links or even device files together with their file permissions, last modification time/date and owner.
In easier words: You could backup and restore an entire UNIX file system without loosing anything. (not even modification times)
Because of this utility it's still widely used today. (most of the time compressed by another format, e.g. *.tar.gz files)
Why doesn't have OpenComputers have tar?
Well, there already is one program, but that only supports extracting.
I wanted to be able to create tar files, too.
There is a huge advantage in being able to:
You can now exchange whole filesystems with a single pastebin / wget operation.
Updating a bunch of files is also a lot easier: You can't forget a file if you extract an archive.
(compared to deleting and copying files manually)
Man Page
NAME tar - tar archiver for OpenComputers SYNOPSIS tar <function letter> [other options] FILES... DESCRIPTION allows working with tar archives in OpenComputers It supports the standard tar format + ustar extension. (not every feature but enough for most uses) That makes it a nice tool to exchange multiple files and directories between OpenComputers and "real computers". Tar a bunch of files, use pastebin / wget to transmit the archive and extract it at destination. Since this program is also able to create tar archives it is possible in both directions! When you want read from / write to a file you have to use the option -f / --file. It then uses the first file given as the archive. Else it uses the primary Computronics tape drive. (with the archive starting at the current position) A function flag is required to indicate what you want to do with the archive. Further options can be used to modify the behaviour of the program. By default the program does not print anything except errors. Use --verbose to make it 'talk'! By default it overwrites every existing file. Take care or use options like --keep-old-files! FUNCTION LETTERS -c --create create a new tar archive -r --append append to the tar archive (tape only unless io.open is going to support rb+ mode) -t --list list contents of tar archive -x --extract --get extract the archive to the current directory --help show usage information OTHER OPTIONS -f --file tell tar to use the first file parameter as a tar archive (When creating an archive, it will be the output file.) Without this option the primary tape drive is used instead. --address=ADDRESS tell tar to use the tape drive with the given address instead of the primary one -h --dereference follow symlinks (treating them as files / directories) --exclude=FILE1;FILE2 exclude a semicolon separated list of files The archive file is automaticly excluded when writing to an archive. When using the --dereference option it might be necessary to exclude the archive manually. (i.e. when following a symlink directs the program to include the archive itself) The program will throw an error if an input file grew while being copied to the archive. (So it at least terminates when it tries to put the archive into itself.) -v --verbose print out what the program is doing If the library auto_progress is installed it also displays nice progress bars on large files. --keep-old-files throw an error when extracting and an output file already exists --skip-old-files do not overwrite existing files, but continues without errors --keep-newer-files overwrite existing files only if they are older than the one within the archive --dir=DIR change the reference directory i.e. to extract a tar file in a subdirectory (The original tar option is "-C DIR". But shell.parse() does not support an option+parameter combination.) EXAMPLES tar --create --file all.tar / --exclude=/mnt creates an archive 'all.tar' containing the whole file system except "/mnt". tar -xf -v another.tar extracts the contents of 'another.tar' while showing the user what it's doing. tar -t displays the contents of the tape archive. The current position is read as the beginning of the archive.
Depencencies
Software
tar requires only standard libraries from OpenComputers.
It additionally uses but does not require the auto_progress library to display progress bars in verbose mode.
(-v --verbose)
It has been tested with OpenComputers 1.4.1.14.
Hardware
RAM: min. 256 KiB, recommended: 392 KiB
(rare, but possible out of memory errors are possible on minimum)
Did you know: The 'real' tar was originally created as a tape archiver.
Therefore I implemented support for Computronics tape drives.
Usage is quite similar except that you leave out the "-f" option.
Installation
Simply move the file to the 'bin' directory of your choice.
I recommend the directory "/home/bin".
Download (last update: 13.04.17)
github: tar archive for easy installation
Ingame:
wget 'https://raw.githubusercontent.com/mpmxyz/ocprograms/master/home/bin/tar.lua' wget 'https://raw.githubusercontent.com/mpmxyz/ocprograms/master/usr/man/tar.man' wget 'https://raw.githubusercontent.com/mpmxyz/ocprograms/master/tars/tar.tar' OR oppm install mpm.tar
Known Issues
It does not support every version or extension of the tar file format.
Implementing them all would be too much work.
But if there is a feature you would like to see, feel free to tell me.
Another side note: I should write more in detail what is supported and what not.
Appending to tar files on a file system does not work because you would need to use the "rb+" mode to open the file.
That's currently not possible in OpenComputers and workarounds would have to include copying the file instead of simply working in place.
tar currently does not detect link cycles and would therefore follow them when creating an archive.
In that case it will terminate because it filled the whole filesystem. (You have been warned!)
You can only use the primary tape drive. (I simply didn't create an option. Maybe later...)
It currently doesn't check if you have enough storage space available. (Maybe later...)
-
Introduction
We all know the problem:
Users - including me - can be quite impatient.
This is especially true if a busy program does not give a clue if it is actually doing something.
That's where a progress bar is useful.
This library - I named it 'auto_progress' - makes it easy to include a nice progress bar into your program.
Apart from the progress bar itself you also get a numeric indication and a time to finish estimate.
To avoid cluttering the limited screen space it is only activated if your program didn't finish the first 50% within a second.
Redrawing is limited to 4 redraws per second to reduce the slowdown due to drawing operations.
To use it you need a number to describe an amount of 'work'.
This can be a number of bytes, a number of items or any unit you like. (You define it!)
API
FUNCTIONS auto_progress.new(totalWork or table or nil) -> progress_state if the parameter is a table: uses this table as the progress_state, adds methods and default values if it is a number: creates a new progress state with totalWork set to the number if it is nil: creates a new progress state with totalWork=1 progress_state.update(workAdded) adds 'workAdded' to the internal progress counter and updates the progress bar if necessary. (should be called at regular intervals) progress_state.finish() draws the final 100%-progress bar if it has been drawn before. (should be called if the program finished it's operation successfully) progress_state.draw() forces drawing the progress bar. It also cancels the initial drawing delay by setting progress_state.drawing to true. PROPERTIES progress_state.x, progress_state.y uses the given position to draw the progress bar. (recommended if you want to use the progress bar within an UI) Nil values are replaced by the corresponding term.getCursor() ordinates, unless both values are nil and the cursor isn't at the beginning of the line. Then they will be set to the beginning of the next line. progress_state.width sets the width of the progress bar; nil makes the progress bar extend to the end of the line. progress_state.drawing setting this to true cancels the drawing delay. progress_state.disabled true disables automatic drawing; manual drawing is still possible though. progress_state.doneWork the counter which is summing up all workAdded values from progress_state.update() progress_state.totalWork the amount of work that corrensponds to 100% progress_state.creationTime the computer.uptime() when the object was created progress_state.lastUpdate the computer.uptime() from the last progress_state.draw() call
Example
--load library local auto_progress = require 'mpm.auto_progress' --generate a list of actions local todo = {} for i=1, 30 do todo[i] = math.random() * 2 end --create progress bar: initialize it with the amount of work to do local pbar = auto_progress.new(#todo) for _, duration in pairs(todo) do --simulate an action os.sleep(duration) --update progress bar: 1 step done pbar.update(1) end --tell progress bar that the action has been finished pbar.finish()
Example output:
[-----50% ETA: 30s ]
[----------100%----------]
Dependencies
Software
This library only depends on standard OpenComputers libraries.
It was tested with OpenComputers 1.4.1.14.
Hardware
To see a progress bar you obviously need a screen and a gpu.
But the library itself should work fine without them. Anything else is a bug!
Installation
Just download the library and move it to the lib directory of your choice.
I recommend "/home/lib".
Download (last update: 07.05.15)
Ingame:
wget 'https://raw.githubusercontent.com/mpmxyz/ocprograms/master/home/lib/mpm/auto_progress.lua'
Update from 07.05.15: changed library name from "auto_progress" to "mpm.auto_progress" to clean up library directories
Known Issues
The progress bar does not move upward, if you print something on the screen that causes scrolling.
If you have an idea how to fix that or any other suggestion, feel free to leave a comment below.
I also added a lot of features while writing this description.
If something doesn't work as expected: It's a bug in the code or in the documentation.
Lua minifier
in Requests
Posted
I've just written a lua parser in lua for that purpose.
The first part - to cut the code into 'tokens' like numbers, strings etc. - is lightweight enough to be executed from within OpenComputers.
The second part - to generate a tree representing the structure of the code - currently needs > 50 MiB during initialization.
(It should be possible to move the resource intensive parts out of OpenComputers via a file with a precomputed table.)
Obviously this is only reading the code.
But I already have ideas for the next step:
-remove comments and unnecessary whitespace (only needs the first part)
-rename variables (i.e. "thisIsMyLongVariable = thisIsMyLongFunction" -> "a = b0", can be improved by knowing variable visibility)
-replace "local a=1 local b=2" by "local a,b=1,2" (needs a more detailed analysis of the variables referenced behind the '=')
I'm going to publish the program in the forum when it's ready. (It might take some time though.)