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

[1.48] dotbot 1.1 (simple text/file reader)

Started by InputUsername, 03 January 2013 - 03:50 AM
InputUsername #1
Posted 03 January 2013 - 04:50 AM

dotbot 1.1 - © 2013 InputUsername

nevermind the name, it doesn't make sense :)/>


Updated to 1.1! See the changelog and known bugs sections for more information.
Because of some fixes and changes to the installer you'll have to re-download and then run it.


What is dotbot?
dotbot is a simple text/file reading program. You can use it to read any file on regular and advanced computers. Monitor and turtle support will be added in a future version.

How do I use dotbot?
To use dotbot, simply run it. When you don't provide any parameters you'll get more information on how to use the program.

Features:
Spoiler
  • easy to install
  • easy to use
  • nice, simple interface
  • regular and advanced computers supported
  • created by a noob (I don't know if that is a good thing though :P/>)
  • it's not a door lock/"Operating System"! :P/>
NOTE: there is currently NO support for turtles and/or monitors!

Images:
SpoilerMost of these images still apply to version 1.1.
dotbot 1.0 running on a regular computer


dotbot 1.0 running on an advanced computer


Logo for version 1.0

How can I get it?
You simply download the installer from one of the links below and then run it.
The
SpoilerAll versions:
Installer:
Pastebin download
In-game:

pastebin get DKwQejBK dotbot_installer
(Requires the http-API to be enabled*)

Known bugs:
SpoilerWill be fixed in the next version - Will be fixed some day - No solution
Version 1.1
  • When a line of text is wider than the screen width, it is not visible. I already know how to fix this but I felt I should release the program anyway.
  • The indentation in both the installer and the main program is quite screwed up, thanks to Notepad++ :)/> I will probably fix this if anyone wants me to.
Version 1.0
  • When a line of text is wider than the screen width, it is not visible. I already know how to fix this but I felt I should release the program anyway.
  • The indentation in both the installer and the main program is quite screwed up, thanks to Notepad++ :)/> I will probably fix this if anyone wants me to.
  • The installer currently uses shell.run('pastebin get …') fixed in 1.1
  • Sometimes, when trying to remove the main folder ('dotfiles') you will get an 'access denied' error (at least, from my experiences). There is currently nothing I can do about it and sometimes it WILL remove the folder. fixed in 1.1

Changelog:
SpoilerVersion 1.1
  • (*) improved/updated the code slightly
  • (*) does not install the logo on a regular computer anymore
  • (*) removing the main folder 'dotfiles' does not give an error (thanks GravityScore!)
  • (-) shell.run removed from installer (thanks GravityScore!)
The word wrapping functionality is delayed, because it is harder to implement than I thought.

Version 1.0
  • First release

Planned features:
Spoiler
  • Support for turtles and monitors
  • Printing
  • Better GUI
  • Grammar/Spelling fixes
  • Code optimization
  • Ability to open files using the edit program (essentially just a shell.run('edit …') call :P/>)



* How to enable the http-API
Spoiler
  1. Navigate to your .minecraft folder (located in your Application Data folder) and open it
  2. Find the config folder
  3. Open the file ComputerCraft.cfg with a program like Notepad or WordPad
  4. Find the section named general and scroll down to enableAPI_http=false (if it is true, then you already have the API enabled and you can close the config file)
  5. Change the 'false' to 'true' so it looks something like enableAPI_http=true
  6. Save and close the file
  7. You now have the http-API enabled
To disable the API, just follow the steps and change 'true' to 'false'.


Thanks for reading!
Please, if you find any bugs (in either the program or the post) or things you would like to see/change in the program, tell me! Constructive criticism is appreciated, but if you don't like the program, for the love of god, provide a reason.
GravityScore #2
Posted 03 January 2013 - 06:01 AM
Regarding the bugs you have:

1) Here is a simple function you can use to download something from Pastebin without having to use pastebin get …

local function download(code, path)
for i = 1, 3 do
  local response = http.get("http://pastebin.com/raw.php?i=" .. code)
  if response then
   local data = response.readAll()
   response.close()
   local f = io.open(path, "w")
   if f then
    f:write(data)
    f:close()
   else return false end
   return true
  end
end
return false
end

2) The access denied error when deleting the dotfiles folder is usually because a file in it has been opened in read-only mode (the "r" mode in fs/io.open), and has not been closed - leaving it to be only readable. Look through your code and make sure that you close any files that you open. After looking at your code, I noticed that you haven't closed the mainFile variable. Once you've finished editing it, make sure you call mainFile.close().

You probably can't delete the dotfiles folder because you were testing the feature where if you input no arguments, it opens the help file in the dotfiles folder. Then, you exit the application and try and delete the dotfiles folder - but you can't because the help file is in read-only mode because you haven't closed the mainFile variable (which was the help file in the dotfiles folder).

You can read more about opening/closing files here.

Hope this can help :D/>
InputUsername #3
Posted 03 January 2013 - 06:07 AM
Thanks! I'll fix the bugs tomorrow! I do feel kind of stupid about the second one. Anyway thanks for the help!
Sammich Lord #4
Posted 03 January 2013 - 06:29 AM
What makes me want to use this script instead of the default "edit" script? I see no advantages over it.
InputUsername #5
Posted 03 January 2013 - 09:23 AM
What makes me want to use this script instead of the default "edit" script? I see no advantages over it.

Readability? Edit is good for programs but not really for regular text files.
Ease of use?
Some other things I can't come up with right now?

And at least be glad I made this instead of a door lock or an 'OS' :)/>
Left4Cake #6
Posted 03 January 2013 - 10:10 AM
What makes me want to use this script instead of the default "edit" script? I see no advantages over it.

two words,

Word Wrap.
InputUsername #7
Posted 04 January 2013 - 04:52 AM
What makes me want to use this script instead of the default "edit" script? I see no advantages over it.

two words,

Word Wrap.

Exactly! Word wrapping will be added soon.

By the way, sorry for bumping but the program has been updated to 1.1. There were some changes to the installer, therefore you'll have to re-dowload it.
GravityScore #8
Posted 04 January 2013 - 05:12 AM
Regarding the word wraping:

In the bios.lua of CC, the write function is defined, with word wrapping. It can help you in making yours. Here is a commented version, sort of explaining it. Note that copy and pasting this should work pretty well (just adapt the variables to meet your needs).
Spoiler

function write(text)
-- Get the terminal size and the cursor position
local w, h = term.getSize()
local x, y = term.getCursorPos()

-- Define the new line function
-- It creates a new line (moves the cursor to the next line, and scrolls the terminal)
local function newLine()
  -- If the next line the cursor will be on is less than the height of the terminal
  if y + 1 <= h then
   term.setCursorPos(1, y + 1)
  else
   -- Scroll the terminal screen
   term.setCursorPos(1, h)
   term.scroll(1)
  end
  x, y = term.getCursorPos()
end

-- Print the line with word wrapping
while string.len(text) > 0 do
  -- Get the amount of whitespace (spaces) are at the current position in the text
  local whitespace = string.match(text, "^[ \t]+")
  if whitespace then
   -- Print whitespace
   term.write(whitespace)
   x, y = term.getCursorPos()
   text = string.sub(text, string.len(whitespace) + 1)
  end

  -- Print any newlines that are needed
  local newline = string.match(text, "^\n")
  if newline then
   newLine()
   text = string.sub(text, 2)
  end
  local text = string.match(text, "^[^ \t\n]+")
  if text then
   text = string.sub(text, string.len(text) + 1)
   if string.len(text) > w then
	-- Print a multiline word (a word that has more letters than the size of the screen)  
	while string.len(text) > 0 do
	 if x > w then
	  newLine()
	 end
	 term.write(text)
	 text = string.sub(text, (w-x) + 2)
	 x, y = term.getCursorPos()
	end
   else
	-- Print a word normally (one that can fit onto the screen)
	if x + string.len(text) - 1 > w then
	 newLine()
	end
	term.write(text)
	x, y = term.getCursorPos()
   end
  end
end
end

Also, suggestion - can you add the ability to scroll through the program using the up and down arrow keys (in an advanced terminal)?