public LineEditor (string name, int histsize = 10, params Handler[] addlHandlers)
		{
			handlers = new [] {
				new Handler (ConsoleKey.Home,       CmdHome),
				new Handler (ConsoleKey.End,        CmdEnd),
				new Handler (ConsoleKey.LeftArrow,  CmdLeft),
				new Handler (ConsoleKey.RightArrow, CmdRight),
				new Handler (ConsoleKey.UpArrow,    CmdHistoryPrev),
				new Handler (ConsoleKey.DownArrow,  CmdHistoryNext),
				new Handler (ConsoleKey.Enter,      CmdDone),
				new Handler (ConsoleKey.Backspace,  CmdBackspace),
				new Handler (ConsoleKey.Delete,     CmdDeleteChar),
				new Handler (ConsoleKey.Tab,        CmdTabOrComplete),
				
				// Emacs keys
				Handler.Control ('A', CmdHome),
				Handler.Control ('E', CmdEnd),
				Handler.Control ('B', CmdLeft),
				Handler.Control ('F', CmdRight),
				Handler.Control ('P', CmdHistoryPrev),
				Handler.Control ('N', CmdHistoryNext),
				Handler.Control ('K', CmdKillToEOF),
				Handler.Control ('Y', CmdYank),
				Handler.Control ('D', CmdDeleteChar),
				Handler.Control ('L', CmdRefresh),
				Handler.Control ('R', CmdReverseSearch),
				Handler.Control ('G', delegate {} ),
				Handler.Alt ('B', ConsoleKey.B, CmdBackwardWord),
				Handler.Alt ('F', ConsoleKey.F, CmdForwardWord),
				
				Handler.Alt ('D', ConsoleKey.D, CmdDeleteWord),
				Handler.Alt ((char) 8, ConsoleKey.Backspace, CmdDeleteBackword),
				
				// DEBUG
				Handler.Control ('T', CmdDebug),

				// quote
				Handler.Control ('Q', () => HandleChar(Console.ReadKey(true).KeyChar))
			};

			if (addlHandlers != null)
			{
				//additional handlers should override any default handlers
				var dictionary = handlers.ToDictionary(h => h.CKI);
				foreach (var handler in addlHandlers)
				{
					dictionary[handler.CKI] = handler;
				}
				handlers = dictionary.Values.ToArray();
			}

			rendered_text = new StringBuilder ();
			text = new StringBuilder ();

			history = new History (name, histsize);
			
			//if (File.Exists ("log"))File.Delete ("log");
			//log = File.CreateText ("log"); 
		}
		public LineEditor (string name, int histsize)
		{
			handlers = new Handler [] {
				new Handler (ConsoleKey.Home,       CmdHome),
				new Handler (ConsoleKey.End,        CmdEnd),
				new Handler (ConsoleKey.LeftArrow,  CmdLeft),
				new Handler (ConsoleKey.RightArrow, CmdRight),
				new Handler (ConsoleKey.UpArrow,    CmdHistoryPrev),
				new Handler (ConsoleKey.DownArrow,  CmdHistoryNext),
				new Handler (ConsoleKey.Enter,      CmdDone),
				new Handler (ConsoleKey.Backspace,  CmdBackspace),
				new Handler (ConsoleKey.Delete,     CmdDeleteChar),
				new Handler (ConsoleKey.Tab,        CmdTabOrComplete),
				
				// Emacs keys
				Handler.Control ('A', CmdHome),
				Handler.Control ('E', CmdEnd),
				Handler.Control ('B', CmdLeft),
				Handler.Control ('F', CmdRight),
				Handler.Control ('P', CmdHistoryPrev),
				Handler.Control ('N', CmdHistoryNext),
				Handler.Control ('K', CmdKillToEOF),
				Handler.Control ('Y', CmdYank),
				Handler.Control ('D', CmdDeleteChar),
				Handler.Control ('L', CmdRefresh),
				Handler.Control ('R', CmdReverseSearch),
				Handler.Control ('G', delegate {} ),
				Handler.Alt ('B', ConsoleKey.B, CmdBackwardWord),
				Handler.Alt ('F', ConsoleKey.F, CmdForwardWord),
				
				Handler.Alt ('D', ConsoleKey.D, CmdDeleteWord),
				Handler.Alt ((char) 8, ConsoleKey.Backspace, CmdDeleteBackword),
				
				// DEBUG
				Handler.Control ('T', CmdDebug),

				// quote
				Handler.Control ('Q', delegate { HandleChar (Console.ReadKey (true).KeyChar); })
			};

			rendered_text = new StringBuilder ();
			text = new StringBuilder ();

			history = new History (name, histsize);
			
			//if (File.Exists ("log"))File.Delete ("log");
			//log = File.CreateText ("log"); 
		}
Exemple #3
0
		public LineEditor (string name, int histsize)
		{
			handlers = new Handler [] {
				new Handler (ConsoleKey.Home, CmdHome),
				new Handler (ConsoleKey.End, CmdEnd),
				new Handler (ConsoleKey.LeftArrow, CmdLeft),
				new Handler (ConsoleKey.RightArrow, CmdRight),
				new Handler (ConsoleKey.UpArrow, CmdHistoryPrev),
				new Handler (ConsoleKey.DownArrow, CmdHistoryNext),
				new Handler (ConsoleKey.Enter, CmdDone),
				new Handler (ConsoleKey.Backspace, CmdBackspace),
				new Handler (ConsoleKey.Delete, CmdDeleteChar),
				new Handler (ConsoleKey.Tab, CmdTabOrComplete),
				new Handler (ConsoleKey.Escape, CmdKillLine),
				
				// Doesn't work on mono?
				Handler.Control ((char)0, ConsoleKey.LeftArrow, CmdBackwardWord),
				Handler.Control ((char)0, ConsoleKey.RightArrow, CmdForwardWord),

				Handler.Control ('O', ConsoleKey.O, delegate() {
					if (CtrlOPressed != null)
						CtrlOPressed (this, new EventArgs ());
				}
				),
				Handler.Control ('S', ConsoleKey.S, delegate() {
					if (CtrlSPressed != null)
						CtrlSPressed (this, new EventArgs ());
				}
				),
				Handler.Control ('U', ConsoleKey.U, delegate() {
					if (CtrlUPressed != null)
						CtrlUPressed (this, new EventArgs ());
				}
				),

				// Emacs keys
				Handler.Control ('A', ConsoleKey.A, CmdHome),
				Handler.Control ('E', ConsoleKey.E, CmdEnd),
				Handler.Control ('B', ConsoleKey.B, CmdLeft),
				Handler.Control ('F', ConsoleKey.F, CmdRight),
				Handler.Control ('P', ConsoleKey.P, CmdHistoryPrev),
				Handler.Control ('N', ConsoleKey.N, CmdHistoryNext),
				Handler.Control ('K', ConsoleKey.K, CmdKillToEOF),
				Handler.Control ('Y', ConsoleKey.Y, CmdYank),
				Handler.Control ('D', ConsoleKey.D, CmdDeleteChar),
				Handler.Control ('L', ConsoleKey.L, CmdRefresh),
				Handler.Control ('R', ConsoleKey.R, CmdReverseSearch),
				Handler.Control ('G', ConsoleKey.G, delegate {
				}
				),

				Handler.Alt ('B', ConsoleKey.B, CmdBackwardWord),
				Handler.Alt ('F', ConsoleKey.F, CmdForwardWord),
				
				Handler.Alt ('D', ConsoleKey.D, CmdDeleteWord),
				Handler.Alt ((char)8, ConsoleKey.Backspace, CmdDeleteBackword),
				
				// DEBUG
				//Handler.Control ('T', CmdDebug),

				// quote
				Handler.Control ('Q', ConsoleKey.Q, delegate {
					HandleChar (Console.ReadKey (true).KeyChar);
				}
				)
			};

			rendered_text = new StringBuilder ();
			text = new StringBuilder ();

			history = new History (name, histsize);
			
			//if (File.Exists ("log"))File.Delete ("log");
			//log = File.CreateText ("log"); 
		}