Implement common emacs bindings (closes #3)

This commit is contained in:
Laura Hausmann 2023-01-18 02:34:36 +01:00
parent 6382f10dae
commit 9dd2f06160
Signed by: zotan
GPG key ID: D044E84C5BE01605
2 changed files with 23 additions and 14 deletions

View file

@ -413,7 +413,7 @@ namespace tgcli {
}
public class CloseCommand : Command {
public CloseCommand() : base("c", "^E", "closes a chat", "", 0) { }
public CloseCommand() : base("c", "^D", "closes a chat", "", 0) { }
public override void Handler(List<string> inputParams) {
if (currentChatId == 0) {
@ -486,7 +486,7 @@ namespace tgcli {
}
public class UnreadsCommand : Command {
public UnreadsCommand() : base("u", "^U", "displays unread chat", "[all]", -1) { }
public UnreadsCommand() : base("u", "", "displays unread chat", "[all]", -1) { }
public override void Handler(List<string> inputParams) {
var unreads = GetUnreadChats(inputParams.Count == 1 && inputParams[0].Equals("all"));

View file

@ -289,22 +289,11 @@ namespace tgcli {
// InsertToInputLine("⏎ ");
// ScreenUpdate();
// return;
case ConsoleKey.D when key.Modifiers.HasFlag(ConsoleModifiers.Control):
HandleCommand(currentChatId == 0 ? "q" : "c");
ScreenUpdate();
return;
case ConsoleKey.Q when key.Modifiers.HasFlag(ConsoleModifiers.Control):
HandleCommand("q");
ScreenUpdate();
return;
case ConsoleKey.E when key.Modifiers.HasFlag(ConsoleModifiers.Control):
HandleCommand("c");
ScreenUpdate();
return;
case ConsoleKey.U when key.Modifiers.HasFlag(ConsoleModifiers.Control):
HandleCommand("u");
ScreenUpdate();
return;
case ConsoleKey.O when key.Modifiers.HasFlag(ConsoleModifiers.Control):
SetInputLine(currentInputLine switch {
"/o " => "/os ",
@ -314,10 +303,30 @@ namespace tgcli {
});
ScreenUpdate();
return;
// standard terminal commands
case ConsoleKey.L when key.Modifiers.HasFlag(ConsoleModifiers.Control):
HandleCommand("cl");
ScreenUpdate();
return;
case ConsoleKey.D when key.Modifiers.HasFlag(ConsoleModifiers.Control):
HandleCommand(currentChatId == 0 ? "q" : "c");
ScreenUpdate();
return;
// input navigation
case ConsoleKey.U when key.Modifiers.HasFlag(ConsoleModifiers.Control):
SetInputLine("");
ScreenUpdate();
return;
case ConsoleKey.A when key.Modifiers.HasFlag(ConsoleModifiers.Control):
currentInputPos = 0;
ScreenUpdate();
return;
case ConsoleKey.E when key.Modifiers.HasFlag(ConsoleModifiers.Control):
currentInputPos = currentInputLine.Length;
ScreenUpdate();
return;
}
if (!SpecialKeys.Contains(key.Key)) {