diff --git a/src/main/java/li/cil/oc/api/component/TextBuffer.java b/src/main/java/li/cil/oc/api/component/TextBuffer.java index 1709e7504..c7297c631 100644 --- a/src/main/java/li/cil/oc/api/component/TextBuffer.java +++ b/src/main/java/li/cil/oc/api/component/TextBuffer.java @@ -300,11 +300,13 @@ public interface TextBuffer extends ManagedEnvironment, Persistable { char get(int column, int row); /** - * Get the character in the text buffer at the specified location. + * Get the foreground color of the text buffer at the specified location. + *
+ * Important: this may be a palette index. * * @param column the horizontal index. * @param row the vertical index. - * @return the foregound color at that index. + * @return the foreground color at that index. */ int getForegroundColor(int column, int row); @@ -320,6 +322,8 @@ public interface TextBuffer extends ManagedEnvironment, Persistable { /** * Get the background color of the text buffer at the specified location. + * + * Important: this may be a palette index. * * @param column the horizontal index. * @param row the vertical index. diff --git a/src/main/resources/assets/opencomputers/loot/OpenOS/bin/lua.lua b/src/main/resources/assets/opencomputers/loot/OpenOS/bin/lua.lua index 0d59503c0..bf84eb772 100644 --- a/src/main/resources/assets/opencomputers/loot/OpenOS/bin/lua.lua +++ b/src/main/resources/assets/opencomputers/loot/OpenOS/bin/lua.lua @@ -24,9 +24,9 @@ term.write("Press Ctrl+C to exit the interpreter.\n") component.gpu.setForeground(0xFFFFFF) while term.isAvailable() do - local foreground, palette = component.gpu.setForeground(0x00FF00) + local foreground = component.gpu.setForeground(0x00FF00) term.write(tostring(env._PROMPT or "lua> ")) - component.gpu.setForeground(foreground, palette) + component.gpu.setForeground(foreground) local command = term.read(history) if command == nil then -- eof return diff --git a/src/main/resources/assets/opencomputers/loot/OpenOS/bin/sh.lua b/src/main/resources/assets/opencomputers/loot/OpenOS/bin/sh.lua index a870ed380..47ec37ce5 100644 --- a/src/main/resources/assets/opencomputers/loot/OpenOS/bin/sh.lua +++ b/src/main/resources/assets/opencomputers/loot/OpenOS/bin/sh.lua @@ -104,9 +104,9 @@ if #args == 0 and (io.input() == io.stdin or options.i) and not options.c then term.clear() end while term.isAvailable() do - local foreground, palette = component.gpu.setForeground(0xFF0000) + local foreground = component.gpu.setForeground(0xFF0000) term.write(expand(os.getenv("PS1") or "$ ")) - component.gpu.setForeground(foreground, palette) + component.gpu.setForeground(foreground) local command = term.read(history) if not command then term.write("exit\n") diff --git a/src/main/resources/assets/opencomputers/loot/OpenOS/boot/02_io.lua b/src/main/resources/assets/opencomputers/loot/OpenOS/boot/02_io.lua index a7889dfdd..f9215f6cf 100644 --- a/src/main/resources/assets/opencomputers/loot/OpenOS/boot/02_io.lua +++ b/src/main/resources/assets/opencomputers/loot/OpenOS/boot/02_io.lua @@ -32,10 +32,9 @@ end function stderrStream:write(str) local component = require("component") if component.isAvailable("gpu") and component.gpu.getDepth() > 1 then - local foreground, palette = component.gpu.getForeground() - component.gpu.setForeground(0xFF0000) + local foreground = component.gpu.setForeground(0xFF0000) term.write(str, true) - component.gpu.setForeground(foreground, palette) + component.gpu.setForeground(foreground) else term.write(str, true) end diff --git a/src/main/scala/li/cil/oc/common/component/TextBuffer.scala b/src/main/scala/li/cil/oc/common/component/TextBuffer.scala index c46b369b9..83a333de3 100644 --- a/src/main/scala/li/cil/oc/common/component/TextBuffer.scala +++ b/src/main/scala/li/cil/oc/common/component/TextBuffer.scala @@ -264,20 +264,26 @@ class TextBuffer(val owner: Container) extends ManagedComponent with api.compone def get(col: Int, row: Int) = data.get(col, row) override def getForegroundColor(column: Int, row: Int) = - PackedColor.unpackForeground(data.color(row)(column), data.format) + if (isForegroundFromPalette(column, row)) { + PackedColor.extractForeground(data.color(row)(column)) + } + else { + PackedColor.unpackForeground(data.color(row)(column), data.format) + } - override def isForegroundFromPalette(column: Int, row: Int) = data.format match { - case palette: PackedColor.PaletteFormat => palette.isFromPalette(PackedColor.extractForeground(data.color(row)(column))) - case _ => false - } + override def isForegroundFromPalette(column: Int, row: Int) = + data.format.isFromPalette(PackedColor.extractForeground(data.color(row)(column))) override def getBackgroundColor(column: Int, row: Int) = - PackedColor.unpackBackground(data.color(row)(column), data.format) + if (isBackgroundFromPalette(column, row)) { + PackedColor.extractBackground(data.color(row)(column)) + } + else { + PackedColor.unpackBackground(data.color(row)(column), data.format) + } - override def isBackgroundFromPalette(column: Int, row: Int) = data.format match { - case palette: PackedColor.PaletteFormat => palette.isFromPalette(PackedColor.extractBackground(data.color(row)(column))) - case _ => false - } + override def isBackgroundFromPalette(column: Int, row: Int) = + data.format.isFromPalette(PackedColor.extractBackground(data.color(row)(column))) @SideOnly(Side.CLIENT) override def renderText() = relativeLitArea != 0 && proxy.render() diff --git a/src/main/scala/li/cil/oc/server/component/GraphicsCard.scala b/src/main/scala/li/cil/oc/server/component/GraphicsCard.scala index cee2c7dba..0dce1274f 100644 --- a/src/main/scala/li/cil/oc/server/component/GraphicsCard.scala +++ b/src/main/scala/li/cil/oc/server/component/GraphicsCard.scala @@ -79,10 +79,16 @@ abstract class GraphicsCard extends component.ManagedComponent { def setBackground(context: Context, args: Arguments): Array[AnyRef] = { val color = args.checkInteger(0) screen(s => { - val oldColor = s.getBackgroundColor - val oldIsPalette = s.isBackgroundFromPalette + val oldValue = s.getBackgroundColor + val (oldColor, oldIndex) = + if (s.isBackroundFromPalette) { + (s.getPaletteColor(oldValue), oldValue) + } + else { + (oldValue, Unit) + } s.setBackgroundColor(color, args.count > 1 && args.checkBoolean(1)) - result(oldColor, oldIsPalette) + result(oldColor, oldIndex) }) } @@ -93,10 +99,16 @@ abstract class GraphicsCard extends component.ManagedComponent { def setForeground(context: Context, args: Arguments): Array[AnyRef] = { val color = args.checkInteger(0) screen(s => { - val oldColor = s.getForegroundColor - val oldIsPalette = s.isForegroundFromPalette + val oldValue = s.getForegroundColor + val (oldColor, oldIndex) = + if (s.isForegroundFromPalette) { + (s.getPaletteColor(oldValue), oldValue) + } + else { + (oldValue, Unit) + } s.setForegroundColor(color, args.count > 1 && args.checkBoolean(1)) - result(oldColor, oldIsPalette) + result(oldColor, oldIndex) }) } @@ -176,7 +188,25 @@ abstract class GraphicsCard extends component.ManagedComponent { val x = args.checkInteger(0) - 1 val y = args.checkInteger(1) - 1 screen(s => { - result(s.get(x, y), s.getForegroundColor(x, y), s.getBackgroundColor(x, y), s.isForegroundFromPalette(x, y), s.isBackgroundFromPalette(x, y)) + val fgValue = s.getForegroundColor(x, y) + val (fgColor, fgIndex) = + if (s.isForegroundFromPalette(x, y)) { + (s.getPaletteColor(fgValue), fgValue) + } + else { + (fgValue, Unit) + } + + val bgValue = s.getBackgroundColor(x, y) + val (bgColor, bgIndex) = + if (s.isBackgroundFromPalette(x, y)) { + (s.getPaletteColor(bgValue), bgValue) + } + else { + (bgValue, Unit) + } + + result(s.get(x, y), fgColor, bgColor, fgIndex, bgIndex) }) }