Skip to content

Commit 0b15b37

Browse files
committed
Added hot-key <esc> h to launch a GUI history picker. Renamed 'prod' to 'product'. Cleaned up some formatting stuff in 'autoload.tl'. Cleaned up 'file/read-lines' to make the regex optional and to make it work with pattern lambdas (docs updated).
1 parent 53f7797 commit 0b15b37

7 files changed

Lines changed: 350 additions & 66 deletions

File tree

src/BraidLineEditor.cs

Lines changed: 24 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -174,8 +174,12 @@ public static Handler Alt(char c, ConsoleKey k, KeyHandler h)
174174

175175
private string _defaultPrompt;
176176

177+
// Hook for doing tab completion externally
177178
public static Func<string, string, string, object> BraidCompleter {get; set;}
178179

180+
// Hook for editiong history externally
181+
public static Func<object> HistoryEditor {get; set; }
182+
179183
public LineEditor(string name)
180184
: this(name, 1000)
181185
{
@@ -214,6 +218,9 @@ public LineEditor(string name, int histsize)
214218

215219
// Edit the current line in vi
216220
Handler.Control('\\', CmdVisualEdit),
221+
222+
// Select history entry to invoke
223+
Handler.Control('H', CmdHistoryEdit),
217224

218225
Handler.Control('D', CmdDeleteChar),
219226
Handler.Control('L', CmdRefresh),
@@ -225,7 +232,9 @@ public LineEditor(string name, int histsize)
225232

226233
Handler.Alt('V', ConsoleKey.V, CmdVisualEdit),
227234

228-
Handler.Alt('H', ConsoleKey.H, CmdHome),
235+
// Handler.Alt('H', ConsoleKey.H, CmdHome),
236+
Handler.Alt('H', ConsoleKey.H, CmdHistoryEdit),
237+
229238
Handler.Alt('M', ConsoleKey.M, CmdMiddle),
230239
Handler.Alt('E', ConsoleKey.E, CmdEnd),
231240
// Handler.Alt('B', ConsoleKey.B, CmdBackwardWord),
@@ -626,7 +635,7 @@ private void InsertChar(char c)
626635
//
627636
// Commands
628637
//
629-
private void CmdDone()
638+
public void CmdDone()
630639
{
631640
this._done = true;
632641
}
@@ -1043,7 +1052,18 @@ private void CmdVisualEdit()
10431052
System.IO.File.Delete(tempFile);
10441053
SetText(newText);
10451054
CmdDone();
1046-
}
1055+
}
1056+
1057+
/// <summary>
1058+
/// Launch the history editor
1059+
/// </summary>
1060+
private void CmdHistoryEdit()
1061+
{
1062+
if (HistoryEditor != null)
1063+
{
1064+
HistoryEditor.Invoke();
1065+
}
1066+
}
10471067

10481068
private void CmdHistoryNext()
10491069
{
@@ -1326,7 +1346,7 @@ private void InitText(string initial)
13261346
ForceCursor(this._cursor);
13271347
}
13281348

1329-
private void SetText(string newtext)
1349+
public void SetText(string newtext)
13301350
{
13311351
Console.SetCursorPosition(0, this._homeRow);
13321352
InitText(newtext);

0 commit comments

Comments
 (0)