←  Programs

ComputerCraft | Programmable Computers for Minecraft

»

less - Like the Unix command!

LDDestroier's Photo LDDestroier 07 Jan 2016

I saw a lot of people who made a program to replicate the function of 'cat', but all of them just print the contents of the file and don't allow scrolling.
But then SquidDev told me that's what cat is supposed to do, and now I feel dumb.

See the program for syntax.

Allows for the downloading of files as well. Because that's useful...

pastebin get en8GA73P less
std pb en8GA73P less
std ld less less

It uses arrow keys to scroll left/right and up/down, as well as the mouse scroll. Hold CTRL to mouse-scroll left and right.
When making files, it checks if the path is read-only, and checks if there is enough space.

Also, to exit, press 'X', and to go to a specific line, press 'L'.
To go to bottom of the screen, press 'END' or 'SHIFT+G'. To go to the top, press 'HOME' or 'G'.
Edited by LDDestroier, 08 January 2016 - 05:51 PM.
Quote

SquidDev's Photo SquidDev 07 Jan 2016

If you've got scrolling, it is closer to less than cat :P

In all seriousness, it might be useful to have some functionality from less: being able to do a forwards and backwards search using Lua patterns, page up/down support, as well as several less shortcuts: G,g,q, etc...

Also, the keys table holds the key codes for each key, so you don't need to use constants, but keys.up instead.
Quote

LDDestroier's Photo LDDestroier 07 Jan 2016

 SquidDev, on 07 January 2016 - 07:24 PM, said:

If you've got scrolling, it is closer to less than cat :P

In all seriousness, it might be useful to have some functionality from less: being able to do a forwards and backwards search using Lua patterns, page up/down support, as well as several less shortcuts: G,g,q, etc...

Also, the keys table holds the key codes for each key, so you don't need to use constants, but keys.up instead.
Oh yeah...I mixed the two commands up in my head. Time to rename it...
Quote

LDDestroier's Photo LDDestroier 08 Jan 2016

 SquidDev, on 07 January 2016 - 07:24 PM, said:

In all seriousness, it might be useful to have some functionality from less: being able to do a forwards and backwards search using Lua patterns, page up/down support, as well as several less shortcuts: G,g,q, etc...

While having it search through a document and find the next match of a certain word is hard, I added a goto line function, as well as the 'g', 'q', and 'G' keybinds.
Quote

FUNCTION MAN!'s Photo FUNCTION MAN! 09 Jan 2016

e, y, f, b (and ^E, ^Y, ^F & ^B move forward a line, backwards a line, forwards a window, and backwards a window, respectively. (^LETTER is Ctrl+LETTER)
n repeats the previous search (i.e., find next), and N is find next backwards.
j and k go up and down (I'd prefer it to be k/l myself, maybe make key bindings configurable?)
&<pattern> will hide all lines that don't match <pattern>.
Edited by FUNCTION MAN!, 09 January 2016 - 08:19 PM.
Quote

LDDestroier's Photo LDDestroier 11 Jan 2016

I added some extra buttons based on the less help menu. Boy are there a lot! I didn't add them all, though.
Quote