forked from tonerdo/readline
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathKeyParser.cs
32 lines (25 loc) · 3.28 KB
/
KeyParser.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
using System;
using System.Collections.Generic;
namespace ReadLine;
public class KeyParser
{
static TerminalFormatStrings _tfs = new(new TermInfo.Database("term", Convert.FromBase64String(EncodedTerminalDb)));
static string EncodedTerminalDb => EncodedTerminalDb_linux;
// grab linux-console data from KeyParser.Tests to cover more sequences
static string EncodedTerminalDb_linux => "GgEUAB0AEAB9AUUDbGludXh8bGludXggY29uc29sZQAAAQAAAQEAAAAAAAAAAQEAAAAAAAEAAAAAAAABAQD//wgA/////////////////////////////wgAQAASAP//AAACAAQAFQAaACEAJQApAP//NABFAEcASwBXAP//WQBlAP//aQBtAHkAfQD/////gQCDAIgA/////40AkgD/////lwCcAKEApgCvALEA/////7YAuwDBAMcA////////////////2QDdAP//4QD////////jAP//6AD//////////+wA8QD3APwAAQEGAQsBEQEXAR0BIwEoAf//LQH//zEBNgE7Af///////z8B////////////////////////////////////////QwH//0YBTwFYAWEB//9qAXMBfAH//4UB//////////////////+OAf///////5QBlwGiAaUBpwGqAQEC//8EAv///////////////wYC//////////8KAv//TQL/////UQJXAv////9dAv////////////////////9hAv//////////////////////////////////////////////////ZgL//////////////////////////////////////////////////////////////////////////////////2gCbgJ0AnoCgAKGAowCkgKYAp4C//////////////////////////////////////////////////////////////////////////////////////////////////////////////////+kAv////////////////////////////////////////////////////////////+pArQCuQK/AsMCzALQAv//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////IQP///////8lAy8D////////////////////////////////////////////////OQM/AwcADQAbWyVpJXAxJWQ7JXAyJWRyABtbM2cAG1tIG1tKABtbSwAbW0oAG1slaSVwMSVkRwAbWyVpJXAxJWQ7JXAyJWRIAAoAG1tIABtbPzI1bBtbPzFjAAgAG1s/MjVoG1s/MGMAG1t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AAWE0Aa0VORDUAa0hPTTUAa2EyAGtiMQBrYjMAa2MyAHhtAA=="; // /lib/terminfo/l/linux
public static ConsoleKeyInfo[] Parse(char[] input)
{
var list = new List<ConsoleKeyInfo>();
Parse(input, list.Add);
return list.ToArray();
}
public static void Parse(char[] input, Action<ConsoleKeyInfo> keyHandler)
{
int startpos = 0;
while (startpos < input.Length)
{
var key = System.IO.KeyParser.Parse(input, _tfs, 0, 0, ref startpos, input.Length);
keyHandler.Invoke(key);
}
}
}