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

GUI File Browser

Started by inventor2514, 04 July 2012 - 10:57 PM
inventor2514 #1
Posted 05 July 2012 - 12:57 AM
Description
This generically named file browser offers a convenient pseudo-GUI solution for your file browsing needs. Files and directories are portrayed with ASCII icons and standard functions are available in menus. Scroll up/down, close, and back "buttons" are present on the window-like screen border, but their functions can also be accessed with keys. Suggestions and constructive criticisms are appreciated!

Controls
SpoilerLeft Click = Perform default action
Right Click = Open menu
Middle Click or Backspace = Exit current directory
Mouse Wheel or Page Up/Down = Scroll Up/Down
End = Exit program

Pictures
Spoiler





Changelog
Spoilerv 1.4.1
+ Added some color and config variables
+ Made middle click act like the back button

v 1.4.0
* Replaced cursor controls with mouse controls

v 1.3.3
* Modified some functions to be more flexible

v 1.3.2
+ Added a config variable for starting directory
* Made the current shell directory the default starting directory

v 1.3.1
+ Added a config variable for edit program path
* Fixed another disk-related bug

v 1.3.0
+ Added a special menu for disks
* Fixed several bugs relating to disks

v 1.2
* Fixed custom cursors not getting along with menus

v 1.1
+ Added support for WASD
+ Added support for custom cursors (default is smoother)
+ Added prompts to text boxes
+ Added an overwrite confirmation dialog
* Fixed a nasty bug where new files were not editable

Downloads
Spoilerv 1.4.1 (Mouse)
http://pastebin.com/hGdMREQB
or "pastebin get hGdMREQB guifb"

v 1.3.3 (Keyboard)
http://pastebin.com/9a8ZwG5v
or "pastebin get 9a8ZwG5v guifb"

Newer versions use the mouse, so advanced computers only. If you insist on a regular computer, use the old keyboard version.
rex41043 #2
Posted 05 July 2012 - 03:26 AM
not bad i like it
Mendax #3
Posted 05 July 2012 - 07:08 AM
Wow. This is AMAZING. May I include this in ShadOS? (Slight Modification :P/>/>)
Deathknight0897 #4
Posted 05 July 2012 - 12:58 PM
this is very impressive would you pm me your source please so i may inspect it and take notes
inventor2514 #5
Posted 05 July 2012 - 02:36 PM
Wow. This is AMAZING. May I include this in ShadOS? (Slight Modification :P/>/>)

Feel free to use/modify my code as long as you credit me as the original author. That goes for anyone who is interested.
Mendax #6
Posted 05 July 2012 - 03:25 PM
Ok, thanks! Quick question, how do I change the top bar? I want to add '[SExplorer]' next to the / on the top left…
inventor2514 #7
Posted 05 July 2012 - 03:34 PM
Ok, thanks! Quick question, how do I change the top bar? I want to add '[SExplorer]' next to the / on the top left…

Locate the drawBorder() function and append:

output(2, 1, "[SExplorer]")
Mendax #8
Posted 05 July 2012 - 03:36 PM
Ok, I'll try that. :D/>/> Thanks!
EDIT:
Worked :)/>/>
(Although I moved it a little :P/>/>)

Also, is it possible to change the cursor? I want to change it to a +
inventor2514 #9
Posted 05 July 2012 - 05:22 PM
Changing the cursor is not currently possible as I used the built-in cursor from the term API, but I might add support for custom cursors in a future update.
tfoote #10
Posted 06 July 2012 - 12:49 AM
Nice! I have to create something similar to that so Thanks for the Excellent Example!
inventor2514 #11
Posted 06 July 2012 - 03:58 AM
Just updated to v1.1! I'm surprised that my bug wasn't noticed; I also tweaked a few things.
Mendax #12
Posted 06 July 2012 - 06:55 AM
So how do I change the cursor?
+ Added support for custom cursors (default is smoother)
EDIT: While using custom cursor, it bugs when using a menu.
Deathknight0897 #13
Posted 06 July 2012 - 10:34 AM
insert <derp comment>
inventor2514 #14
Posted 06 July 2012 - 01:52 PM
EDIT: While using custom cursor, it bugs when using a menu.

I just updated; this should be fixed now.
inventor2514 #15
Posted 06 July 2012 - 10:06 PM
Updated to v 1.3.0! Aside from fixes to bugs that may arise, this should be the last update for a while.
inventor2514 #16
Posted 14 July 2012 - 02:48 AM
Minor update this time; nothing fancy.
Exerro #17
Posted 14 July 2012 - 10:15 AM
this looks rly good can i use it in my os with only a few gui changes
inventor2514 #18
Posted 14 July 2012 - 01:01 PM
Feel free to use/modify my code as long as you credit me as the original author. That goes for anyone who is interested.
Exerro #19
Posted 15 July 2012 - 11:43 AM
wow thats rly complicated…would u be able to change the gui a bit and send it to me pls?
inventor2514 #20
Posted 15 July 2012 - 01:50 PM
wow thats rly complicated…would u be able to change the gui a bit and send it to me pls?
That depends. What exactly would you want changed?
ETHANATOR360 #21
Posted 16 July 2012 - 12:34 AM
wow im using this in my OS thats amazing,and how lond did the ascii art take?
inventor2514 #22
Posted 16 July 2012 - 01:03 AM
The ASCII art took about five minutes, but the actual coding was fairly time consuming.
ETHANATOR360 #23
Posted 16 July 2012 - 01:48 AM
i cant find where the code is to change what it does when you hit the x in the corner
inventor2514 #24
Posted 16 July 2012 - 02:37 AM
At lines 349-351, it detects that cancel was "clicked" and ends the main program loop. At lines 639-End, it deletes the temporary copy file and clears the screen.
ETHANATOR360 #25
Posted 16 July 2012 - 03:39 PM
thanks, you should take this further in to a full OS it could be like windows in a way :P/>/>
inventor2514 #26
Posted 16 July 2012 - 05:02 PM
I've been thinking about that, but I'm still figuring out co-routines for multitasking.
ETHANATOR360 #27
Posted 16 July 2012 - 07:56 PM
can you modify it so it opens to a differnt directory then the main one?
inventor2514 #28
Posted 16 July 2012 - 11:33 PM
can you modify it so it opens to a differnt directory then the main one?
I just added a configuration variable for that. Also, the current shell directory is the default start directory now.
Exerro #29
Posted 17 July 2012 - 05:45 PM
i have an os so if youre interested it wud be great for you to work with me and my os…but anyway i basically want O's around the edge instead of
+—+
| |
+—+
Darky_Alan #30
Posted 17 July 2012 - 08:41 PM
I'm curious, how come the color of the text in the screen is different, is that a custom addition to the mod, or is there an acctual command I can use for that?
KevinW1998 #31
Posted 17 July 2012 - 09:11 PM
You can change the color in the config but you can't use multiple colors at the same time!
inventor2514 #32
Posted 19 July 2012 - 09:39 PM
Another minor update. This one is for those who are trying to use/modify parts of my code.
makerimages #33
Posted 13 August 2012 - 11:33 AM
how do you display that ascii art gui??
inventor2514 #34
Posted 13 August 2012 - 01:44 PM
I use term.setCursorPos() and term.write() to draw the ASCII art. Take a look at the functions drawIcon() and drawBorder() in my code for more detail.
Laserman34170 #35
Posted 17 August 2012 - 05:38 PM
Where should I edit the code if I want to use mutiple icons?
Cranium #36
Posted 17 August 2012 - 05:44 PM
Wow, this is REALLY nice! I love it!
inventor2514 #37
Posted 17 August 2012 - 06:18 PM
Where should I edit the code if I want to use mutiple icons?
Right now, I can only distinguish between files and directories, so I only have one icon for each. I declare them at lines 23&amp;24. If you wanted to, you could declare your own icons in the same style and use them as arguments for drawIcon(), but you would need a way to recognize different types of files.

Wow, this is REALLY nice! I love it!
Thank you; I appreciate the appreciation.
Laserman34170 #38
Posted 20 August 2012 - 02:53 PM
Where should I edit the code if I want to use mutiple icons?
Right now, I can only distinguish between files and directories, so I only have one icon for each. I declare them at lines 23&amp;24. If you wanted to, you could declare your own icons in the same style and use them as arguments for drawIcon(), but you would need a way to recognize different types of files.
Yes, actually I'm thinking on finding a string inside the filename for an extension.
inventor2514 #39
Posted 20 August 2012 - 05:24 PM
Yes, actually I'm thinking on finding a string inside the filename for an extension.
In that case, make the following changes to my functions; they should be around line 104. You should be able to check for file extensions and draw your custom icons.

-- Draws an icon at the specified position
local function drawIcon(x, y, tIcon, sName)
local tIcon = tIcon
for i, s in ipairs(tIcon) do
  output(x, y+i-1, s)
end
if sName then output(x, y+#tIcon, string.sub(sName, 1, 8)) end
end
-- Draws icons to represent file data
local function drawIcons()
local pos = 1 + maxCol*(row-1)
local limit = pos-1+maxCol*maxRow
if #tData < limit then limit = #tData end
local icon = 1
for i = pos, limit do
  local x, y, sName = tOrigins[icon][1], tOrigins[icon][2], tData[i][1]
  if tData[i][2] then
   drawIcon(x, y, tDirIcon, sName)
  else
   drawIcon(x, y, tFileIcon, sName) -- replace this with your code
  end
  icon = icon + 1
end
end
makerimages #40
Posted 26 September 2012 - 01:12 PM
how do you distinguish between files and directorys?
inventor2514 #41
Posted 30 September 2012 - 03:50 PM
how do you distinguish between files and directorys?

I use fs.isDir() and store the results in a table for later reference.
makerimages #42
Posted 01 October 2012 - 12:39 PM
ok
inventor2514 #43
Posted 13 October 2012 - 03:29 AM
v 1.4.0 PR1 is available with mouse support. If you don't have an advanced computer, just keep using v 1.3.3.
inventor2514 #44
Posted 17 October 2012 - 12:08 AM
v 1.4.0 PR2 for CC 1.45 PR3 is now available.
inventor2514 #45
Posted 28 October 2012 - 04:17 PM
v 1.4.0 is out and has been tested with CC 1.46, though it should also work with 1.45.
In addition, I think the next update will be a rewrite because the interface just doesn't feel as intuitive as I would like with the mouse and I want to make use of color.
BigSHinyToys #46
Posted 28 October 2012 - 05:08 PM
Might be a good idea to add in big print somewhere in the OP that this is has mouse support.

It works quite well and with the icons looks good to.
One idea hit me while using this custom icons.
Leo Verto #47
Posted 29 October 2012 - 06:39 PM
NukeOS is going to use a modified version of this, prepare yourselves.

In case someone reads this: Have fun with secret beta testing of NukeShell, which depends on this program!
Edited on 22 November 2012 - 10:31 AM
inventor2514 #48
Posted 30 December 2012 - 04:29 AM
So, is anyone still using this? If so, are there any improvements you would like to see?
NDFJay #49
Posted 30 December 2012 - 03:15 PM
So, is anyone still using this? If so, are there any improvements you would like to see?

Any chance of making it less text based and more graphical?
inventor2514 #50
Posted 30 December 2012 - 04:03 PM
Any chance of making it less text based and more graphical?

I'm working on that right now. Did you have anything specific in mind?
NDFJay #51
Posted 30 December 2012 - 04:27 PM
Any chance of making it less text based and more graphical?

I'm working on that right now. Did you have anything specific in mind?

Not really, just less Text based more GUI based, colorfull, maybe custom colors, custom Icons, stuff like that, let the users customize it to suite their color scheme with ease
Leo Verto #52
Posted 31 December 2012 - 02:04 AM
Any chance of making it less text based and more graphical?
I'm working on that right now. Did you have anything specific in mind?
Not really, just less Text based more GUI based, colorfull, maybe custom colors, custom Icons, stuff like that, let the users customize it to suite their color scheme with ease
NukeShell, my modified version includes more colors which should not be that hard to be modified, I also edited the icon system and moved useful functions to an API.
My last work was adding a startup that actually does something and a registry for global values.
https://github.com/LeoVerto/NukeShell