Skip to content

Commit

Permalink
imp - Interactive editors support transparency
Browse files Browse the repository at this point in the history
---

The interactive editors now support transparency. This is required to port it to Terminaux as soon as 0.1.1 gets released.

-- Backport required --

---

Type: imp
Breaking: False
Doc Required: False
Part: 1/1
  • Loading branch information
AptiviCEO committed Jun 11, 2024
1 parent dca4edb commit fd29961
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 38 deletions.
9 changes: 5 additions & 4 deletions public/Nitrocid/Drivers/Filesystem/BaseFilesystemDriver.cs
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@
using Terminaux.Base;
using Nitrocid.Misc.Progress;
using System.Runtime.Serialization;
using Terminaux.Colors;

namespace Nitrocid.Drivers.Filesystem
{
Expand Down Expand Up @@ -627,7 +628,7 @@ public virtual string RenderContentsInHex(long ByteHighlight, long StartByte, lo
var builder = new StringBuilder();
for (long CurrentByteNumber = StartByte; CurrentByteNumber <= EndByte; CurrentByteNumber += 16)
{
builder.Append($"{unhighlightedColorBackground.VTSequenceBackground}{entryColor.VTSequenceForeground}0x{CurrentByteNumber - 1L:X8} ");
builder.Append($"{ColorTools.RenderSetConsoleColor(unhighlightedColorBackground, true)}{entryColor.VTSequenceForeground}0x{CurrentByteNumber - 1L:X8} ");

// Iterate these number of bytes for the ASCII codes
long byteNum;
Expand All @@ -637,10 +638,10 @@ public virtual string RenderContentsInHex(long ByteHighlight, long StartByte, lo
DebugWriter.WriteDebug(DebugLevel.I, "Byte: {0}", CurrentByte);
builder.Append(
$"{(CurrentByteNumber + byteNum == ByteHighlight ? unhighlightedColorBackground : highlightedColorBackground).VTSequenceForeground}" +
$"{(CurrentByteNumber + byteNum == ByteHighlight ? highlightedColorBackground : unhighlightedColorBackground).VTSequenceBackground}" +
$"{ColorTools.RenderSetConsoleColor((CurrentByteNumber + byteNum == ByteHighlight ? highlightedColorBackground : unhighlightedColorBackground), true)}" +
$"{CurrentByte:X2}" +
$"{highlightedColorBackground.VTSequenceForeground}" +
$"{unhighlightedColorBackground.VTSequenceBackground}" +
$"{ColorTools.RenderSetConsoleColor(unhighlightedColorBackground, true)}" +
$" "
);
}
Expand Down Expand Up @@ -668,7 +669,7 @@ public virtual string RenderContentsInHex(long ByteHighlight, long StartByte, lo
DebugWriter.WriteDebug(DebugLevel.I, "Rendered byte char: {0}", ProjectedByteChar);
builder.Append(
$"{(CurrentByteNumber + byteNum == ByteHighlight ? unhighlightedColorBackground : highlightedColorBackground).VTSequenceForeground}" +
$"{(CurrentByteNumber + byteNum == ByteHighlight ? highlightedColorBackground : unhighlightedColorBackground).VTSequenceBackground}" +
$"{ColorTools.RenderSetConsoleColor((CurrentByteNumber + byteNum == ByteHighlight ? highlightedColorBackground : unhighlightedColorBackground), true)}" +
$"{RenderedByteChar}"
);
}
Expand Down
25 changes: 12 additions & 13 deletions public/Nitrocid/Files/Editors/HexEdit/HexEditInteractive.cs
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,6 @@ internal static void OpenInteractive(string file, ref byte[] bytes)
var screen = new Screen();
ScreenTools.SetCurrent(screen);
ConsoleWrapper.CursorVisible = false;
ColorTools.LoadBackDry(InteractiveTuiStatus.OptionBackgroundColor);
try
{
while (!bail)
Expand Down Expand Up @@ -150,11 +149,11 @@ private static void RenderKeybindings(ref Screen screen)
{
DebugWriter.WriteDebug(DebugLevel.I, "Drawing binding {0} with description {1}...", GetBindingKeyShortcut(binding, false), binding.Name);
bindingsBuilder.Append(
$"{InteractiveTuiStatus.KeyBindingOptionColor.VTSequenceForeground}" +
$"{InteractiveTuiStatus.OptionBackgroundColor.VTSequenceBackground}" +
$"{ColorTools.RenderSetConsoleColor(InteractiveTuiStatus.KeyBindingOptionColor)}" +
$"{ColorTools.RenderSetConsoleColor(InteractiveTuiStatus.OptionBackgroundColor, true)}" +
GetBindingKeyShortcut(binding, false) +
$"{InteractiveTuiStatus.OptionForegroundColor.VTSequenceForeground}" +
$"{InteractiveTuiStatus.BackgroundColor.VTSequenceBackground}" +
$"{ColorTools.RenderSetConsoleColor(InteractiveTuiStatus.OptionForegroundColor)}" +
$"{ColorTools.RenderSetConsoleColor(InteractiveTuiStatus.BackgroundColor, true)}" +
$" {(binding._localizable ? Translate.DoTranslation(binding.Name) : binding.Name)} " +
ConsoleClearing.GetClearLineToRightSequence()
);
Expand All @@ -165,8 +164,8 @@ private static void RenderKeybindings(ref Screen screen)
DebugWriter.WriteDebug(DebugLevel.I, "Bailing because of no space...");
bindingsBuilder.Append(
$"{CsiSequences.GenerateCsiCursorPosition(ConsoleWrapper.WindowWidth - 2, ConsoleWrapper.WindowHeight)}" +
$"{InteractiveTuiStatus.KeyBindingOptionColor.VTSequenceForeground}" +
$"{InteractiveTuiStatus.OptionBackgroundColor.VTSequenceBackground}" +
$"{ColorTools.RenderSetConsoleColor(InteractiveTuiStatus.KeyBindingOptionColor)}" +
$"{ColorTools.RenderSetConsoleColor(InteractiveTuiStatus.OptionBackgroundColor, true)}" +
" K " +
ConsoleClearing.GetClearLineToRightSequence()
);
Expand All @@ -186,8 +185,8 @@ private static void RenderStatus(ref Screen screen)
{
var builder = new StringBuilder();
builder.Append(
$"{InteractiveTuiStatus.ForegroundColor.VTSequenceForeground}" +
$"{InteractiveTuiStatus.BackgroundColor.VTSequenceBackground}" +
$"{ColorTools.RenderSetConsoleColor(InteractiveTuiStatus.ForegroundColor)}" +
$"{ColorTools.RenderSetConsoleColor(InteractiveTuiStatus.BackgroundColor, true)}" +
$"{TextWriterWhereColor.RenderWhere(status + ConsoleClearing.GetClearLineToRightSequence(), 0, 0)}"
);
return builder.ToString();
Expand All @@ -210,8 +209,8 @@ private static void RenderHexViewBox(ref Screen screen)
// Render the box
builder.Append(
$"{InteractiveTuiStatus.PaneSeparatorColor.VTSequenceForeground}" +
$"{InteractiveTuiStatus.BackgroundColor.VTSequenceBackground}" +
$"{ColorTools.RenderSetConsoleColor(InteractiveTuiStatus.PaneSeparatorColor)}" +
$"{ColorTools.RenderSetConsoleColor(InteractiveTuiStatus.BackgroundColor, true)}" +
$"{BorderColor.RenderBorderPlain(0, SeparatorMinimumHeight, SeparatorConsoleWidthInterior, SeparatorMaximumHeightInterior)}"
);
return builder.ToString();
Expand Down Expand Up @@ -244,8 +243,8 @@ private static void RenderContentsInHexWithSelection(int byteIdx, ref Screen scr
// Render the box
builder.Append(
$"{InteractiveTuiStatus.ForegroundColor.VTSequenceForeground}" +
$"{InteractiveTuiStatus.BackgroundColor.VTSequenceBackground}" +
$"{ColorTools.RenderSetConsoleColor(InteractiveTuiStatus.ForegroundColor)}" +
$"{ColorTools.RenderSetConsoleColor(InteractiveTuiStatus.BackgroundColor, true)}" +
$"{TextWriterWhereColor.RenderWhere(rendered, 1, 2)}"
);
return builder.ToString();
Expand Down
41 changes: 20 additions & 21 deletions public/Nitrocid/Files/Editors/TextEdit/TextEditInteractive.cs
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,6 @@ internal static void OpenInteractive(ref List<string> lines)
var screen = new Screen();
ScreenTools.SetCurrent(screen);
ConsoleWrapper.CursorVisible = false;
ColorTools.LoadBackDry(InteractiveTuiStatus.OptionBackgroundColor);
try
{
while (!bail)
Expand Down Expand Up @@ -168,11 +167,11 @@ private static void RenderKeybindings(ref Screen screen)
{
DebugWriter.WriteDebug(DebugLevel.I, "Drawing binding {0} with description {1}...", GetBindingKeyShortcut(binding, false), binding.Name);
bindingsBuilder.Append(
$"{InteractiveTuiStatus.KeyBindingOptionColor.VTSequenceForeground}" +
$"{InteractiveTuiStatus.OptionBackgroundColor.VTSequenceBackground}" +
$"{ColorTools.RenderSetConsoleColor(InteractiveTuiStatus.KeyBindingOptionColor)}" +
$"{ColorTools.RenderSetConsoleColor(InteractiveTuiStatus.OptionBackgroundColor, true)}" +
GetBindingKeyShortcut(binding, false) +
$"{InteractiveTuiStatus.OptionForegroundColor.VTSequenceForeground}" +
$"{InteractiveTuiStatus.BackgroundColor.VTSequenceBackground}" +
$"{ColorTools.RenderSetConsoleColor(InteractiveTuiStatus.OptionForegroundColor)}" +
$"{ColorTools.RenderSetConsoleColor(InteractiveTuiStatus.BackgroundColor, true)}" +
$" {(binding._localizable ? Translate.DoTranslation(binding.Name) : binding.Name)} " +
ConsoleClearing.GetClearLineToRightSequence()
);
Expand All @@ -183,8 +182,8 @@ private static void RenderKeybindings(ref Screen screen)
DebugWriter.WriteDebug(DebugLevel.I, "Bailing because of no space...");
bindingsBuilder.Append(
$"{CsiSequences.GenerateCsiCursorPosition(ConsoleWrapper.WindowWidth - 2, ConsoleWrapper.WindowHeight)}" +
$"{InteractiveTuiStatus.KeyBindingOptionColor.VTSequenceForeground}" +
$"{InteractiveTuiStatus.OptionBackgroundColor.VTSequenceBackground}" +
$"{ColorTools.RenderSetConsoleColor(InteractiveTuiStatus.KeyBindingOptionColor)}" +
$"{ColorTools.RenderSetConsoleColor(InteractiveTuiStatus.OptionBackgroundColor, true)}" +
" K " +
ConsoleClearing.GetClearLineToRightSequence()
);
Expand All @@ -204,8 +203,8 @@ private static void RenderStatus(ref Screen screen)
{
var builder = new StringBuilder();
builder.Append(
$"{InteractiveTuiStatus.ForegroundColor.VTSequenceForeground}" +
$"{InteractiveTuiStatus.BackgroundColor.VTSequenceBackground}" +
$"{ColorTools.RenderSetConsoleColor(InteractiveTuiStatus.ForegroundColor)}" +
$"{ColorTools.RenderSetConsoleColor(InteractiveTuiStatus.BackgroundColor, true)}" +
$"{TextWriterWhereColor.RenderWhere(status + ConsoleClearing.GetClearLineToRightSequence(), 0, 0)}"
);
return builder.ToString();
Expand All @@ -228,8 +227,8 @@ private static void RenderTextViewBox(ref Screen screen)
// Render the box
builder.Append(
$"{InteractiveTuiStatus.PaneSeparatorColor.VTSequenceForeground}" +
$"{InteractiveTuiStatus.BackgroundColor.VTSequenceBackground}" +
$"{ColorTools.RenderSetConsoleColor(InteractiveTuiStatus.PaneSeparatorColor)}" +
$"{ColorTools.RenderSetConsoleColor(InteractiveTuiStatus.BackgroundColor, true)}" +
$"{BorderColor.RenderBorderPlain(0, SeparatorMinimumHeight, SeparatorConsoleWidthInterior, SeparatorMaximumHeightInterior)}"
);
return builder.ToString();
Expand Down Expand Up @@ -294,18 +293,18 @@ private static void RenderContentsWithSelection(int lineIdx, ref Screen screen,
{
if (lineColIdx + 1 > lineBuilder.Length)
{
lineBuilder.Append(unhighlightedColorBackground.VTSequenceForeground);
lineBuilder.Append(highlightedColorBackground.VTSequenceBackground);
lineBuilder.Append(ColorTools.RenderSetConsoleColor(unhighlightedColorBackground));
lineBuilder.Append(ColorTools.RenderSetConsoleColor(highlightedColorBackground, true, true));
lineBuilder.Append(' ');
lineBuilder.Append(unhighlightedColorBackground.VTSequenceBackground);
lineBuilder.Append(highlightedColorBackground.VTSequenceForeground);
lineBuilder.Append(ColorTools.RenderSetConsoleColor(unhighlightedColorBackground, true));
lineBuilder.Append(ColorTools.RenderSetConsoleColor(highlightedColorBackground));
}
else
{
lineBuilder.Insert(lineColIdx + 1, unhighlightedColorBackground.VTSequenceBackground);
lineBuilder.Insert(lineColIdx + 1, highlightedColorBackground.VTSequenceForeground);
lineBuilder.Insert(lineColIdx, unhighlightedColorBackground.VTSequenceForeground);
lineBuilder.Insert(lineColIdx, highlightedColorBackground.VTSequenceBackground);
lineBuilder.Insert(lineColIdx + 1, ColorTools.RenderSetConsoleColor(unhighlightedColorBackground, true));
lineBuilder.Insert(lineColIdx + 1, ColorTools.RenderSetConsoleColor(highlightedColorBackground));
lineBuilder.Insert(lineColIdx, ColorTools.RenderSetConsoleColor(unhighlightedColorBackground));
lineBuilder.Insert(lineColIdx, ColorTools.RenderSetConsoleColor(highlightedColorBackground, true, true));
}
}
Expand Down Expand Up @@ -333,8 +332,8 @@ private static void RenderContentsWithSelection(int lineIdx, ref Screen screen,
// Change the color depending on the highlighted line and column
sels.Append(
$"{CsiSequences.GenerateCsiCursorPosition(2, SeparatorMinimumHeightInterior + count + 1)}" +
$"{highlightedColorBackground.VTSequenceForeground}" +
$"{unhighlightedColorBackground.VTSequenceBackground}" +
$"{ColorTools.RenderSetConsoleColor(highlightedColorBackground)}" +
$"{ColorTools.RenderSetConsoleColor(unhighlightedColorBackground, true)}" +
line
);
count++;
Expand Down

0 comments on commit fd29961

Please sign in to comment.