Skip to content

Commit b719fde

Browse files
committed
CC:T term redirections
1 parent ed3f889 commit b719fde

11 files changed

Lines changed: 670 additions & 72 deletions

computercraft/cc_peripherals/_base.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,4 +19,4 @@ def _call(self, method, *args):
1919
return eval_lua(b'G:peripheral:M:call', self._side, method, *args)
2020

2121
def get_expr_code(self):
22-
return b'peripheral.wrap("' + self._side.encode('ascii') + b'")'
22+
return b'return peripheral.wrap("' + self._side.encode('ascii') + b'")'

examples/test_redirect_to_local_monitor.py

Lines changed: 0 additions & 16 deletions
This file was deleted.

examples/test_redirect_to_window.py

Lines changed: 0 additions & 30 deletions
This file was deleted.
Lines changed: 0 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
from computercraft.cc.peripheral import CCMonitor
2-
from computercraft.cc.mixins import TermMixin
31
from cc import import_file, colors, os, peripheral
42

53
_lib = import_file('_lib.py', __file__)
@@ -14,23 +12,6 @@
1412

1513
m = peripheral.wrap(side)
1614
assert m is not None
17-
18-
19-
tbl = _lib.get_object_table(f'peripheral.wrap("{side}")')
20-
21-
# remove British method names to make API lighter
22-
del tbl['function']['getBackgroundColour']
23-
del tbl['function']['getPaletteColour']
24-
del tbl['function']['getTextColour']
25-
del tbl['function']['isColour']
26-
del tbl['function']['setBackgroundColour']
27-
del tbl['function']['setPaletteColour']
28-
del tbl['function']['setTextColour']
29-
# NOTE: peripheral doesn't have nativePaletteColor method
30-
31-
assert _lib.get_multiclass_table(TermMixin, CCMonitor) == tbl
32-
33-
3415
assert m.getSize() == (7, 5)
3516
assert m.isColor() is True
3617
assert m.setTextColor(colors.white) is None
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
from cc import colors, term, peripheral
2+
3+
4+
side = 'left'
5+
input(f'Attach 3x3 color monitor to {side} side of computer [enter]')
6+
7+
with term.redirect(peripheral.wrap(side)):
8+
term.setBackgroundColor(colors.green)
9+
term.setTextColor(colors.white)
10+
term.clear()
11+
term.setCursorPos(1, 1)
12+
print('Redirected to monitor')
13+
14+
print('Test finished successfully')

examples/test_redirect_to_remote_monitor.py renamed to tests/cc_programs/redirect_to_remote_monitor.py

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,20 @@
1-
from cc import import_file, colors, term, peripheral
2-
3-
_lib = import_file('_lib.py', __file__)
1+
from cc import colors, term, peripheral
42

53

64
side = 'back'
7-
_lib.step(f'Attach wired modem to {side} side of computer')
5+
input(f'Attach wired modem to {side} side of computer [enter]')
86

97
mod = peripheral.wrap(side)
108

11-
_lib.step('Connect remote monitor using wires, activate its modem')
9+
input('Connect remote monitor using wires, activate its modem [enter]')
1210

1311
for name in mod.getNamesRemote():
1412
if mod.getTypeRemote(name) == 'monitor':
1513
break
1614
else:
1715
assert False
1816

19-
with term.redirect(peripheral.get_term_target(name)):
17+
with term.redirect(peripheral.wrap(name)):
2018
term.setBackgroundColor(colors.blue)
2119
term.setTextColor(colors.white)
2220
term.clear()
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
from cc import colors, term, window
2+
3+
4+
w, h = term.getSize()
5+
left = window.create(
6+
term.current(),
7+
1, 1, w // 2, h, True)
8+
right = window.create(
9+
term.current(),
10+
w // 2 + 1, 1, w // 2, h, True)
11+
with term.redirect(left):
12+
term.setBackgroundColor(colors.green)
13+
term.setTextColor(colors.white)
14+
term.clear()
15+
term.setCursorPos(1, h // 2)
16+
print('Left part')
17+
with term.redirect(right):
18+
term.setBackgroundColor(colors.red)
19+
term.setTextColor(colors.yellow)
20+
term.clear()
21+
term.setCursorPos(1, h // 2)
22+
print('Right part')
23+
print('Default terminal restored')
24+
25+
print('Test finished successfully')

0 commit comments

Comments
 (0)