Skip to content

Commit

Permalink
feat(Pod Console): handle arrow keys
Browse files Browse the repository at this point in the history
  • Loading branch information
IvanJosipovic committed Sep 9, 2024
1 parent 0c55c6a commit bdc83e4
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 4 deletions.
6 changes: 4 additions & 2 deletions src/KubeUI/ViewModels/Workloads/Pod/PodConsoleViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -62,8 +62,10 @@ public async Task Connect()
var memory = new Memory<char>(new char[1024]);
await _streamReader.ReadAsync(memory).ConfigureAwait(false);
var str = memory.ToString()
.Replace("\0", "", StringComparison.Ordinal)
.Replace("\a", "", StringComparison.Ordinal);
.Replace("\0", "", StringComparison.Ordinal) // null character
.Replace("\a", "", StringComparison.Ordinal) // bell or alert
.Replace("\b", "", StringComparison.Ordinal) // moves the cursor two positions to the left.
;
str = RemoveAnsiEscapeSequences(str);
if (!string.IsNullOrEmpty(str))
{
Expand Down
30 changes: 28 additions & 2 deletions src/KubeUI/Views/Workloads/Pod/PodConsoleView.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,15 @@ namespace KubeUI.Views;

public sealed class PodConsoleView : MyViewBase<PodConsoleViewModel>
{
private readonly ILogger<PodConsoleView> _logger;

private Installation _textMateInstallation;

private RegistryOptions _registryOptions;

public PodConsoleView()
public PodConsoleView(ILogger<PodConsoleView> logger)
{
_logger = logger;
_registryOptions = new RegistryOptions(Application.Current.ActualThemeVariant == ThemeVariant.Light ? ThemeName.Light : ThemeName.DarkPlus);

Application.Current.ActualThemeVariantChanged += Current_ActualThemeVariantChanged;
Expand Down Expand Up @@ -96,7 +99,30 @@ protected override object Build(PodConsoleViewModel? vm)
}
}
dc1.Send(e.KeySymbol);
if (e.KeySymbol != null)
{
dc1.Send(e.KeySymbol);
}
else if (e.Key == Key.Up)
{
dc1.Send("\x1b[A");
}
else if (e.Key == Key.Down)
{
dc1.Send("\x1b[B");
}
else if (e.Key == Key.Left)
{
dc1.Send("\x1b[D");
}
else if (e.Key == Key.Right)
{
dc1.Send("\x1b[C");
}
else
{
_logger.LogWarning("Unmapped key: {0}", e.Key);
}
}
})
.ContextMenu(new ContextMenu()
Expand Down

0 comments on commit bdc83e4

Please sign in to comment.