Made text.wrap not wrap at a couple more chars.

Added text.wrappedLines to get an iterator over wrapped text.
Made OpenOS show a small info text after booting up.
This commit is contained in:
Florian Nücke 2014-06-26 14:21:39 +02:00
parent c96174d168
commit 45a9728b6d
4 changed files with 71 additions and 3 deletions

View File

@ -50,7 +50,7 @@ dependencies {
```
Adjust the version number accordingly to the version you'd like to build against.
To run the mod in your development environment, download the [`deobf` JAR from the build server][deobf-jar] and drop it into your dev env's `eclipse/mods` folder.
To run the mod in your development environment, download the [`deobf` JAR from the build server][deobf-jar] and drop it into your dev env's `eclipse/mods` folder. **Important**: mark the `api/java/codechicken/lib/vec` folder as *excluded* in your IDE, to avoid issues when running/building the project in it.
Alternatively, leave out the `api` classifier and you can build against the deobf JAR directly. This way you don't have to add it to your mods folder, but you will have to add `-Dfml.coreMods.load=li.cil.oc.common.launch.TransformerLoader` to the VM options in your run configuration.

View File

@ -138,12 +138,47 @@ do
status("Starting shell...")
end
local component = require("component")
local computer = require("computer")
local event = require("event")
local function greet()
if not component.isAvailable("gpu") then
return
end
local f = io.open("/usr/misc/greetings.txt")
if f then
local greetings = {}
pcall(function()
for line in f:lines() do table.insert(greetings, line) end
end)
f:close()
local greeting = greetings[math.random(1, #greetings)]
if greeting then
local text = require("text")
local unicode = require("unicode")
local width = math.max(10, component.gpu.getResolution())
local lines = {_OSVERSION .. " (" .. math.floor(computer.totalMemory() / 1024) .. "k RAM)"}
local maxWidth = 0
for line in text.wrappedLines(greeting, width - 4, width - 4) do
table.insert(lines, line)
maxWidth = math.max(maxWidth, unicode.len(line))
end
local borders = {{unicode.char(0x2552), unicode.char(0x2550), unicode.char(0x2555)},
{unicode.char(0x2502), nil, unicode.char(0x2502)},
{unicode.char(0x2514), unicode.char(0x2500), unicode.char(0x2518)}}
io.write(borders[1][1] .. string.rep(borders[1][2], maxWidth + 2) .. borders[1][3] .. "\n")
for _, line in ipairs(lines) do
io.write(borders[2][1] .. " " .. text.padRight(line, maxWidth) .. " " .. borders[2][3] .. "\n")
end
io.write(borders[3][1] .. string.rep(borders[3][2], maxWidth + 2) .. borders[3][3] .. "\n")
end
end
end
while true do
require("term").clear()
io.write(_OSVERSION .. " (" .. math.floor(computer.totalMemory() / 1024) .. "k RAM)\n")
greet()
local result, reason = os.execute(os.getenv("SHELL"))
if not result then
io.stderr:write((tostring(reason) or "unknown error") .. "\n")

View File

@ -46,7 +46,7 @@ function text.wrap(value, width, maxWidth)
local line, nl = value:match("([^\r\n]*)(\r?\n?)") -- read until newline
if unicode.len(line) > width then -- do we even need to wrap?
local partial = unicode.sub(line, 1, width)
local wrapped = partial:match("(.*[^a-zA-Z0-9._])")
local wrapped = partial:match("(.*[^a-zA-Z0-9._()'`=])")
if wrapped or unicode.len(line) > maxWidth then
partial = wrapped or partial
return partial, unicode.sub(value, unicode.len(partial) + 1), true
@ -58,6 +58,16 @@ function text.wrap(value, width, maxWidth)
return line, start <= unicode.len(value) and unicode.sub(value, start) or nil, unicode.len(nl) > 0
end
function text.wrappedLines(value, width, maxWidth)
local line, nl
return function()
if value then
line, value, nl = text.wrap(value, width, maxWidth)
return line
end
end
end
-------------------------------------------------------------------------------
function text.tokenize(value)

View File

@ -0,0 +1,23 @@
Tier 2 and 3 screens can act as touch screens - don't attach a keyboard or sneak-activate them.
You can change the text size on screens by changing their resolution - run `resolution 40 16` in the shell.
Firing arrows on touch capable screens can trigger touch events.
Item colors indicate their tier - white is tier one, yellow is tier two and cyan is tier three.
Use an Analyzer to get more information on blocks - for example, to find out why a computer crashed.
Keyboards have to be attached to or placed next to a screen to work.
You can install OpenOS on a writable medium by running the `install` program.
Internet Cards can be used to make HTTP requests and open raw TCP connections.
If you crafted something by mistake or don't need it any longer, throw it into a disassembler.
Have a look at the code of the built-in programs for examples on how to use the APIs.
Most programs can be interrupted by pressing Ctrl+Alt+C.
Paste the contents of the clipboard using the middle mouse button or a configurable key (default: insert).
Computers will consume less power while idling - i.e. when os.sleep(n > 0.05) is called.
Screens will consume more power the more lit characters they display.
Most blocks act as 'cables' - use switches and power distributes to create separate networks.
Welcome to the dark side - here, have some cookies.
Screens can display all of Codepage 437 - paste the special chars or use unicode.char.
Run `help` or `man programname` for ingame help on programs shipped with OpenOS - start with `man man`.
For more help, there's a wiki on Github - or find the IRC loot disk and join #oc.
Computers have a very basic, built-in speaker - control it using computer.beep().
Many component methods have a short documentation - use `=component.componentName.methodName` in the Lua interpreter to see it.
You can get a list of all attached components using the `components` program.
If you encounter out of memory errors, throw more RAM at your computer.