Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/Mcrevs/cc-text-formatter
CC:T A basic text formatting library to help create multi-line and coloured text.
https://github.com/Mcrevs/cc-text-formatter
cc-tweaked computer-craft computercraft computercraft-tweaked text
Last synced: 2 months ago
JSON representation
CC:T A basic text formatting library to help create multi-line and coloured text.
- Host: GitHub
- URL: https://github.com/Mcrevs/cc-text-formatter
- Owner: Mcrevs
- License: mit
- Created: 2024-01-02T13:53:55.000Z (12 months ago)
- Default Branch: main
- Last Pushed: 2024-02-27T21:43:57.000Z (10 months ago)
- Last Synced: 2024-07-29T17:41:33.676Z (5 months ago)
- Topics: cc-tweaked, computer-craft, computercraft, computercraft-tweaked, text
- Language: Lua
- Homepage:
- Size: 61.5 KB
- Stars: 2
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# Text Formatter
Text formatter (tf) is a basic computer craft text formatting system used for creating inline coloured text.
## Examples
```lua
local tf = require("tf")local width, height = term.getSize()
local header = tf.createString("$b7 Current status ")
header = tf.align(header, width, "centre")
tf.write(header)tf.print("$f8Turtle$f_ Mining Turtle $feOffline")
tf.print("$f8Turtle$f_ Farming Turtle $f5Online")
tf.print("$f8Server$f_ Chat Server $f5Online")
```
![Screenshot of the text produced by the above code](Assets/Example1.png)
```lua
local tf = require("tf")tf.print("Lorem ipsum dolor sit amet, consectetur adipiscing elit. Aliquam eu $c74elit eu turpis$c__ porta eleifend vitae a tortor.\nQuisque congue ultricies urna, ac tincidunt urna eleifend a.\nVestibulum $c74posuere ipsum sit$c__ amet sem dapibus egestas. Lorem ipsum dolor sit amet, consectetur adipiscing elit. Nunc luctus $c74facilisis felis$c__ sit amet sagittis.\nPellentesque in laoreet augue, eget egestas eros. Duis tincidunt sodales elit eu feugiat. Aenean ut $c74dictum arcu, eget aliquet$c__ ex.")
```
![Screenshot of the text produced by the above code](Assets/Example2.png)
# How to use
## Formatting
Tags are used to swich or suggest the formatting of the text. Tags always start with a `$` therefore in order to have a `$` as text you need to type `$$`. The current tags are shown in the table below.
| Tag | Purpose |
| :--------- | :------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ |
| `$f{1}` | Switch the colour of the text to be `{1}` where `{1}` is a hexadecimal digit referring to the colour in the current colour palette or a `_` specifying to use the default foreground colour. |
| `$b{1}` | Switch the colour of the background below the current text to be `{1}` where `{1}` is a hexadecimal digit referring to the colour in the current colour palette or a `_` specifying to use the default background colour. |
| `$c{1}{2}` | Switch the foreground and background colour of the text to be `{1}` and `{2}` respectively. Equivelent to `$f{1}$b{2}.` |
| `$$` | Writes a single $ character. |For example, to send a message such as `ERROR Turtle is on fire!` with the word `ERROR` having a red background and the word `fire` in orange, you would use `$beERROR$bf Turtle is on $f1fire$f0!`.
## Quick start guideFor more detailed doccumentaion on every function please see the [wiki](https://github.com/Mcrevs/cc-text-formatter/wiki) page.
### Installing
Type the following command into the terminal to download the required lua file.
```
wget https://raw.githubusercontent.com/Mcrevs/cc-text-formatter/main/tf.lua
```
### Importing
Add this to the start of your program file to include the library.
```lua
local tf = require("tf")
```
### Printing
Print a coloured string accross multiple lines if required.
```lua
tf.print("$feH$f1E$f4L$f5L$fbL$faO$f0 $cfeW$b1O$b4R$b5L$bbD$ba!")
```