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

[1.21] Computerpark Api 1.0.1 & Vi Text Editor 1.0

Started by Parker, 12 February 2012 - 08:32 AM
Parker #1
Posted 12 February 2012 - 09:32 AM
Here is simple API for helping handling events and also lightweight implementation of vi editor.

Download: https://github.com/p...zipball/release
Github: https://github.com/p...pi/tree/release

vi editor

Simple and lightweight implementation. Made by pro coder for pro coders. ^_^/>/>

Ctrl emulates esc-key.

Spoiler
left,right,up,down : move cursor
h,j,k,l : move cursor

/search : search string
n	   : search same string again

?search : reverse search string
N	   : reverse search same string again

i	   : insert
I	   : insert at start of line

a	   : append
A	   : append at end of line

o	   : insert line bellow cursor
O	   : insert line above cursor

u	   : undo

yy, Y   : copy line to buffer
p, P	: past line from buffer

^, 0	: ho yo begin of line
$	   : go to end of line

G	   : go to last line
1G	  : go to first line
<n>G	: go to nth line

dd	  : delete line

:w	  : write file
:q	  : quit
:wq	 : write file and quit
:x	  : write file and quit
:wr	 : write file and run it

:sh	 : start shell

ComputerPark API

Simple library which includes helpers for event handling, remote logging, helper for redstone signals and optimized bitwise library which is 10x faster than default one.

SpoilerApplication API

computerpark.callLater(timeout, function)

Calls function later.

timeout: Timeout of seconds
func: function to be called

> function foo() print('bar') end
> computerpark.callLater(5, foo)
> computerpark.callLater(1, function() rs.setOutput('back', false) end)
---
computerpark.handleTimer(timer)

Default handled for timer events. Required for callLater function.

timer: timer events parameter.

> evt, arg = os.pullEvent()
> if evt == 'timer' then handleTimer(arg) end
---
computerpark.main(listener)

Simple main loop with listener suport.

listener: Table of event listeners

> computerpark.main({
>	key = function(code)
>		print('key:', key)
>	end;
>
>   default = function(a,b,c,d)
>		print('default:', a,b,c,d)
>   end
>})
Port helper API

port = computerpark.openPort()

Opens port

> local port = computerpark.openPort('back')
---
port:set()

Set signal enabled.

Redstone:
> port:set()

Bundled:
> port:set(colors.white, colors.red)
---
port:clear()

Clears signal.

Redstone:
> port:clear()

Bundled:
> port:clear(colors.green, colors.blue)
---
port:test()

Test input signal.

Redstone:
> port:test()

Bundled:
> port:test(colors.yellow)
---
port:testOut()
Test output signal.

Bundled:
> port:testOut(colors.gray)
Remote logger
Needs to have second computer connected with bundle cable.

cp.initLog(side, targetID)
Initializes remote logger.

> computerpark.initLog('back')
or
> computerpark.initLog('back', remoteComputerID)
---
cp.log(message)
Sends log message to remote computer.

> computerpark.log('foobar')
And in the other computer run:

logger
Bitwise API

computerpark.bnot(n)
computerpark.band(a,:P/>/>
computerpark.bor(a,B)/>/>
computerpark.bxor(a,B)/>/>
computerpark.blshift(a,bits)
computerpark.brshift(a,bits)
FuzzyPurp #2
Posted 12 February 2012 - 09:35 AM
Nice work man!
Parker #3
Posted 13 February 2012 - 05:40 PM
Added simple cat and grep programs.
Advert #4
Posted 13 February 2012 - 06:11 PM
Awesome! This'll be very useful for people playing on a server who can't upload files.
Parker #5
Posted 14 February 2012 - 01:19 AM
Now vi has most of the basic commands (including undo, search, copy and paste) and it is ready to use :(/>/>

I know there is bugs so if you find them please give me bug report including steps how to reproduce the bug.
FuzzyPurp #6
Posted 14 February 2012 - 02:14 AM
bro this stuff is good.