Skip to content

Commit 43d7d4b

Browse files
committed
Feature: Add vertical scrolling support with Ctrl+Up/Down.
1 parent 26e90c3 commit 43d7d4b

File tree

2 files changed

+48
-14
lines changed

2 files changed

+48
-14
lines changed

G33kShell.Desktop/Console/Views/ConsoleView.axaml.cs

Lines changed: 20 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -143,22 +143,29 @@ public override void Render(DrawingContext context)
143143

144144
// Draw the screen cursor.
145145
var cursor = m_windowManager.Cursor;
146-
if (cursor?.IsVisible == true && cursor.X >= 0 && cursor.X < screen.Width && cursor.Y >= 0 && cursor.Y < screen.Height)
146+
if (cursor?.IsVisible == true)
147147
{
148-
var foregroundColor = m_windowManager.Skin.ForegroundColor;
149-
if (cursor.IsBusy)
148+
var cursorY = cursor.Y + m_windowManager.OffsetY;
149+
if (cursorY >= 0 && cursorY < screen.Height)
150150
{
151-
var animChars = "/-\\|";
152-
var animFrame = (Environment.TickCount64 / 100) % animChars.Length;
153-
DrawTextRun(context, new StringBuilder(animChars, (int)animFrame, 1, 1), cursor.X, cursor.Y, foregroundColor, screen.Chars[cursor.Y][cursor.X].Background);
154-
}
155-
else
156-
{
157-
var isFlashOn = (Environment.TickCount64 - cursor.MoveTime) % 1000 < 500;
158-
if (isFlashOn)
151+
if (cursor.X >= 0 && cursor.X < screen.Width)
159152
{
160-
var cursorRect = new Rect(cursor.X * CharWidth + Padding.Left, cursor.Y * CharHeight + Padding.Top, CharWidth, CharHeight);
161-
context.FillRectangle(GetBrush(foregroundColor), cursorRect);
153+
var foregroundColor = m_windowManager.Skin.ForegroundColor;
154+
if (cursor.IsBusy)
155+
{
156+
var animChars = "/-\\|";
157+
var animFrame = (Environment.TickCount64 / 100) % animChars.Length;
158+
DrawTextRun(context, new StringBuilder(animChars, (int)animFrame, 1, 1), cursor.X, cursorY, foregroundColor, screen.Chars[cursorY][cursor.X].Background);
159+
}
160+
else
161+
{
162+
var isFlashOn = (Environment.TickCount64 - cursor.MoveTime) % 1000 < 500;
163+
if (isFlashOn)
164+
{
165+
var cursorRect = new Rect(cursor.X * CharWidth + Padding.Left, cursorY * CharHeight + Padding.Top, CharWidth, CharHeight);
166+
context.FillRectangle(GetBrush(foregroundColor), cursorRect);
167+
}
168+
}
162169
}
163170
}
164171
}

G33kShell.Desktop/Console/WindowManager.cs

Lines changed: 28 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
using System;
1313
using System.Collections.Generic;
1414
using System.Linq;
15+
using Avalonia.Input;
1516
using Avalonia.Layout;
1617
using DTC.Core;
1718
using G33kShell.Desktop.Console.Controls;
@@ -27,6 +28,7 @@ public class WindowManager
2728
private readonly List<ConsoleEvent> m_consoleEvents = new List<ConsoleEvent>();
2829
private SkinBase m_skin;
2930
private ConsoleCursor m_cursor;
31+
internal int OffsetY { get; private set; }
3032

3133
public Visual Root { get; }
3234

@@ -86,7 +88,7 @@ public void Render()
8688
visual.ActualX = pos.x;
8789
visual.ActualY = pos.y;
8890
using (visual.Screen.Lock(out var sourceScreen))
89-
sourceScreen.CopyTo(targetScreen, pos.x, pos.y);
91+
sourceScreen.CopyTo(targetScreen, pos.x, pos.y + OffsetY);
9092
}
9193
}
9294
}
@@ -225,6 +227,31 @@ public void ProcessEvents()
225227
var visualTree = GetVisualTree(Root).ToArray();
226228
foreach (var consoleEvent in m_consoleEvents)
227229
{
230+
if (consoleEvent is KeyConsoleEvent keyEvent && keyEvent.Direction == KeyConsoleEvent.KeyDirection.Down)
231+
{
232+
if ((keyEvent.Modifiers & KeyModifiers.Control) != KeyModifiers.None)
233+
{
234+
switch (keyEvent.Key)
235+
{
236+
case Key.Up:
237+
OffsetY++;
238+
Root.InvalidateVisual();
239+
continue;
240+
case Key.Down:
241+
OffsetY--;
242+
Root.InvalidateVisual();
243+
continue;
244+
}
245+
}
246+
247+
// Any other key resets scroll offset.
248+
if (OffsetY != 0 && keyEvent.Modifiers == KeyModifiers.None)
249+
{
250+
Root.InvalidateVisual();
251+
OffsetY = 0;
252+
}
253+
}
254+
228255
foreach (var visual in visualTree)
229256
{
230257
var handled = false;

0 commit comments

Comments
 (0)