Core.cs 24 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812
  1. //
  2. //
  3. // Pending:
  4. // - Check for NeedDisplay on the hierarchy and repaint
  5. // - Layout support
  6. // - "Colors" type or "Attributes" type?
  7. // - What to surface as "BackgroundCOlor" when clearing a window, an attribute or colors?
  8. //
  9. // Optimziations
  10. // - Add rendering limitation to the exposed area
  11. using System;
  12. using System.Collections;
  13. using System.Collections.Generic;
  14. namespace Terminal {
  15. public class Responder {
  16. public virtual bool CanFocus { get; set; }
  17. public bool HasFocus { get; internal set; }
  18. // Key handling
  19. /// <summary>
  20. /// This method can be overwritten by view that
  21. /// want to provide accelerator functionality
  22. /// (Alt-key for example).
  23. /// </summary>
  24. /// <remarks>
  25. /// <para>
  26. /// Before keys are sent to the subview on the
  27. /// current view, all the views are
  28. /// processed and the key is passed to the widgets
  29. /// to allow some of them to process the keystroke
  30. /// as a hot-key. </para>
  31. /// <para>
  32. /// For example, if you implement a button that
  33. /// has a hotkey ok "o", you would catch the
  34. /// combination Alt-o here. If the event is
  35. /// caught, you must return true to stop the
  36. /// keystroke from being dispatched to other
  37. /// views.
  38. /// </para>
  39. /// </remarks>
  40. public virtual bool ProcessHotKey (KeyEvent kb)
  41. {
  42. return false;
  43. }
  44. /// <summary>
  45. /// If the view is focused, gives the view a
  46. /// chance to process the keystroke.
  47. /// </summary>
  48. /// <remarks>
  49. /// <para>
  50. /// Views can override this method if they are
  51. /// interested in processing the given keystroke.
  52. /// If they consume the keystroke, they must
  53. /// return true to stop the keystroke from being
  54. /// processed by other widgets or consumed by the
  55. /// widget engine. If they return false, the
  56. /// keystroke will be passed using the ProcessColdKey
  57. /// method to other views to process.
  58. /// </para>
  59. /// </remarks>
  60. public virtual bool ProcessKey (KeyEvent kb)
  61. {
  62. return false;
  63. }
  64. /// <summary>
  65. /// This method can be overwritten by views that
  66. /// want to provide accelerator functionality
  67. /// (Alt-key for example), but without
  68. /// interefering with normal ProcessKey behavior.
  69. /// </summary>
  70. /// <remarks>
  71. /// <para>
  72. /// After keys are sent to the subviews on the
  73. /// current view, all the view are
  74. /// processed and the key is passed to the views
  75. /// to allow some of them to process the keystroke
  76. /// as a cold-key. </para>
  77. /// <para>
  78. /// This functionality is used, for example, by
  79. /// default buttons to act on the enter key.
  80. /// Processing this as a hot-key would prevent
  81. /// non-default buttons from consuming the enter
  82. /// keypress when they have the focus.
  83. /// </para>
  84. /// </remarks>
  85. public virtual bool ProcessColdKey (KeyEvent kb)
  86. {
  87. return false;
  88. }
  89. // Mouse events
  90. public virtual void MouseEvent (Event.Mouse me) { }
  91. }
  92. public class View : Responder, IEnumerable {
  93. View container = null;
  94. View focused = null;
  95. public static ConsoleDriver Driver = Application.Driver;
  96. public static IList<View> empty = new List<View> (0).AsReadOnly ();
  97. List<View> subviews;
  98. public IList<View> Subviews => subviews == null ? empty : subviews.AsReadOnly ();
  99. internal bool NeedDisplay { get; private set; } = true;
  100. // The frame for the object
  101. Rect frame;
  102. // The frame for this view
  103. public Rect Frame {
  104. get => frame;
  105. set {
  106. frame = value;
  107. SetNeedsDisplay ();
  108. }
  109. }
  110. public IEnumerator GetEnumerator ()
  111. {
  112. foreach (var v in subviews)
  113. yield return v;
  114. }
  115. public Rect Bounds {
  116. get => new Rect (Point.Empty, Frame.Size);
  117. set {
  118. Frame = new Rect (frame.Location, value.Size);
  119. }
  120. }
  121. public View SuperView => container;
  122. public View (Rect frame)
  123. {
  124. this.Frame = frame;
  125. CanFocus = false;
  126. }
  127. /// <summary>
  128. /// Invoke to flag that this view needs to be redisplayed, by any code
  129. /// that alters the state of the view.
  130. /// </summary>
  131. public void SetNeedsDisplay ()
  132. {
  133. NeedDisplay = true;
  134. if (container != null)
  135. container.SetNeedsDisplay ();
  136. }
  137. /// <summary>
  138. /// Adds a subview to this view.
  139. /// </summary>
  140. /// <remarks>
  141. /// </remarks>
  142. public virtual void Add (View view)
  143. {
  144. if (view == null)
  145. return;
  146. if (subviews == null)
  147. subviews = new List<View> ();
  148. subviews.Add (view);
  149. view.container = this;
  150. if (view.CanFocus)
  151. CanFocus = true;
  152. }
  153. /// <summary>
  154. /// Removes all the widgets from this container.
  155. /// </summary>
  156. /// <remarks>
  157. /// </remarks>
  158. public virtual void RemoveAll ()
  159. {
  160. if (subviews == null)
  161. return;
  162. while (subviews.Count > 0) {
  163. var view = subviews [0];
  164. Remove (view);
  165. subviews.RemoveAt (0);
  166. }
  167. }
  168. /// <summary>
  169. /// Removes a widget from this container.
  170. /// </summary>
  171. /// <remarks>
  172. /// </remarks>
  173. public virtual void Remove (View view)
  174. {
  175. if (view == null)
  176. return;
  177. subviews.Remove (view);
  178. view.container = null;
  179. if (subviews.Count < 1)
  180. this.CanFocus = false;
  181. }
  182. /// <summary>
  183. /// Clears the view region with the current color.
  184. /// </summary>
  185. /// <remarks>
  186. /// <para>
  187. /// This clears the entire region used by this view.
  188. /// </para>
  189. /// </remarks>
  190. public void Clear ()
  191. {
  192. var h = Frame.Height;
  193. var w = Frame.Width;
  194. for (int line = 0; line < h; line++) {
  195. Move (0, line);
  196. for (int col = 0; col < w; col++)
  197. Driver.AddCh (' ');
  198. }
  199. }
  200. /// <summary>
  201. /// Converts the (col,row) position from the view into a screen (col,row). The values are clamped to (0..ScreenDim-1)
  202. /// </summary>
  203. /// <param name="col">View-based column.</param>
  204. /// <param name="row">View-based row.</param>
  205. /// <param name="rcol">Absolute column, display relative.</param>
  206. /// <param name="rrow">Absolute row, display relative.</param>
  207. internal void ViewToScreen (int col, int row, out int rcol, out int rrow, bool clipped = true)
  208. {
  209. // Computes the real row, col relative to the screen.
  210. rrow = row + frame.Y;
  211. rcol = col + frame.X;
  212. var ccontainer = container;
  213. while (ccontainer != null) {
  214. rrow += ccontainer.frame.Y;
  215. rcol += ccontainer.frame.X;
  216. ccontainer = ccontainer.container;
  217. }
  218. // The following ensures that the cursor is always in the screen boundaries.
  219. if (clipped) {
  220. rrow = Math.Max (0, Math.Min (rrow, Driver.Rows - 1));
  221. rcol = Math.Max (0, Math.Min (rcol, Driver.Cols - 1));
  222. }
  223. }
  224. Rect RectToScreen (Rect rect)
  225. {
  226. ViewToScreen (rect.X, rect.Y, out var x, out var y, clipped: false);
  227. return new Rect (x, y, rect.Width, rect.Height);
  228. }
  229. Rect ScreenClip (Rect rect)
  230. {
  231. var x = rect.X < 0 ? 0 : rect.X;
  232. var y = rect.Y < 0 ? 0 : rect.Y;
  233. var w = rect.X + rect.Width >= Driver.Cols ? Driver.Cols - rect.X : rect.Width;
  234. var h = rect.Y + rect.Height >= Driver.Rows ? Driver.Rows - rect.Y : rect.Height;
  235. return new Rect (x, y, w, h);
  236. }
  237. /// <summary>
  238. /// Draws a frame in the current view, clipped by the boundary of this view
  239. /// </summary>
  240. /// <param name="rect">Rectangular region for the frame to be drawn.</param>
  241. /// <param name="fill">If set to <c>true</c> it fill will the contents.</param>
  242. public void DrawFrame (Rect rect, bool fill = false)
  243. {
  244. var scrRect = RectToScreen (rect);
  245. var savedClip = Driver.Clip;
  246. Driver.Clip = ScreenClip (RectToScreen (Bounds));
  247. Driver.DrawFrame (scrRect, fill);
  248. Driver.Clip = savedClip;
  249. }
  250. /// <summary>
  251. /// This moves the cursor to the specified column and row in the view.
  252. /// </summary>
  253. /// <returns>The move.</returns>
  254. /// <param name="col">Col.</param>
  255. /// <param name="row">Row.</param>
  256. public void Move (int col, int row)
  257. {
  258. ViewToScreen (col, row, out var rcol, out var rrow);
  259. Driver.Move (rcol, rrow);
  260. }
  261. /// <summary>
  262. /// Positions the cursor in the right position based on the currently focused view in the chain.
  263. /// </summary>
  264. public virtual void PositionCursor ()
  265. {
  266. if (focused != null)
  267. focused.PositionCursor ();
  268. else
  269. Move (frame.X, frame.Y);
  270. }
  271. /// <summary>
  272. /// Returns the currently focused view inside this view, or null if nothing is focused.
  273. /// </summary>
  274. /// <value>The focused.</value>
  275. public View Focused => focused;
  276. /// <summary>
  277. /// Displays the specified character in the specified column and row.
  278. /// </summary>
  279. /// <param name="col">Col.</param>
  280. /// <param name="row">Row.</param>
  281. /// <param name="ch">Ch.</param>
  282. public void AddCh (int col, int row, int ch)
  283. {
  284. if (row < 0 || col < 0)
  285. return;
  286. if (row > frame.Height - 1 || col > frame.Width - 1)
  287. return;
  288. Move (col, row);
  289. Driver.AddCh (ch);
  290. }
  291. /// <summary>
  292. /// Performs a redraw of this view and its subviews, only redraws the views that have been flagged for a re-display.
  293. /// </summary>
  294. public virtual void Redraw (Rect region)
  295. {
  296. var clipRect = new Rect (Point.Empty, frame.Size);
  297. if (subviews != null) {
  298. foreach (var view in subviews) {
  299. if (view.NeedDisplay) {
  300. if (view.Frame.IntersectsWith (clipRect) && view.Frame.IntersectsWith (region)) {
  301. // TODO: optimize this by computing the intersection of region and view.Bounds
  302. view.Redraw (view.Bounds);
  303. }
  304. view.NeedDisplay = false;
  305. }
  306. }
  307. }
  308. NeedDisplay = false;
  309. }
  310. /// <summary>
  311. /// Focuses the specified sub-view.
  312. /// </summary>
  313. /// <param name="view">View.</param>
  314. public void SetFocus (View view)
  315. {
  316. if (view == null)
  317. return;
  318. if (!view.CanFocus)
  319. return;
  320. if (focused == view)
  321. return;
  322. // Make sure that this view is a subview
  323. View c;
  324. for (c = view.container; c != null; c = c.container)
  325. if (c == this)
  326. break;
  327. if (c == null)
  328. throw new ArgumentException ("the specified view is not part of the hierarchy of this view");
  329. if (focused != null)
  330. focused.HasFocus = false;
  331. focused = view;
  332. view.HasFocus = true;
  333. if (view != null)
  334. view.EnsureFocus ();
  335. focused.PositionCursor ();
  336. }
  337. /// <summary>
  338. /// Finds the first view in the hierarchy that wants to get the focus if nothing is currently focused, otherwise, it does nothing.
  339. /// </summary>
  340. public void EnsureFocus ()
  341. {
  342. if (focused == null)
  343. FocusFirst ();
  344. }
  345. /// <summary>
  346. /// Focuses the first focusable subview if one exists.
  347. /// </summary>
  348. public void FocusFirst ()
  349. {
  350. if (subviews == null)
  351. return;
  352. foreach (var view in subviews) {
  353. if (view.CanFocus) {
  354. SetFocus (view);
  355. return;
  356. }
  357. }
  358. }
  359. /// <summary>
  360. /// Focuses the last focusable subview if one exists.
  361. /// </summary>
  362. public void FocusLast ()
  363. {
  364. if (subviews == null)
  365. return;
  366. for (int i = subviews.Count; i > 0;) {
  367. i--;
  368. View v = subviews [i];
  369. if (v.CanFocus) {
  370. SetFocus (v);
  371. return;
  372. }
  373. }
  374. }
  375. /// <summary>
  376. /// Focuses the previous view.
  377. /// </summary>
  378. /// <returns><c>true</c>, if previous was focused, <c>false</c> otherwise.</returns>
  379. public bool FocusPrev ()
  380. {
  381. if (focused == null) {
  382. FocusLast ();
  383. return true;
  384. }
  385. int focused_idx = -1;
  386. for (int i = subviews.Count; i > 0;) {
  387. i--;
  388. View w = subviews [i];
  389. if (w.HasFocus) {
  390. if (w.FocusPrev ())
  391. return true;
  392. focused_idx = i;
  393. continue;
  394. }
  395. if (w.CanFocus && focused_idx != -1) {
  396. focused.HasFocus = false;
  397. if (w.CanFocus)
  398. w.FocusLast ();
  399. SetFocus (w);
  400. return true;
  401. }
  402. }
  403. if (focused != null) {
  404. focused.HasFocus = false;
  405. focused = null;
  406. }
  407. return false;
  408. }
  409. /// <summary>
  410. /// Focuses the next view.
  411. /// </summary>
  412. /// <returns><c>true</c>, if next was focused, <c>false</c> otherwise.</returns>
  413. public bool FocusNext ()
  414. {
  415. if (focused == null) {
  416. FocusFirst ();
  417. return focused != null;
  418. }
  419. int n = subviews.Count;
  420. int focused_idx = -1;
  421. for (int i = 0; i < n; i++) {
  422. View w = subviews [i];
  423. if (w.HasFocus) {
  424. if (w.FocusNext ())
  425. return true;
  426. focused_idx = i;
  427. continue;
  428. }
  429. if (w.CanFocus && focused_idx != -1) {
  430. focused.HasFocus = false;
  431. if (w != null && w.CanFocus)
  432. w.FocusFirst ();
  433. SetFocus (w);
  434. return true;
  435. }
  436. }
  437. if (focused != null) {
  438. focused.HasFocus = false;
  439. focused = null;
  440. }
  441. return false;
  442. }
  443. public virtual void LayoutSubviews ()
  444. {
  445. }
  446. }
  447. /// <summary>
  448. /// Toplevel views can be modally executed.
  449. /// </summary>
  450. public class Toplevel : View {
  451. public bool Running;
  452. public Toplevel (Rect frame) : base (frame)
  453. {
  454. }
  455. public static Toplevel Create ()
  456. {
  457. return new Toplevel (new Rect (0, 0, Driver.Cols, Driver.Rows));
  458. }
  459. public override bool CanFocus {
  460. get => true;
  461. }
  462. public override bool ProcessKey (KeyEvent kb)
  463. {
  464. if (ProcessHotKey (kb))
  465. return true;
  466. // Process the key normally
  467. if (Focused?.ProcessKey (kb) == true)
  468. return true;
  469. if (ProcessColdKey (kb))
  470. return true;
  471. switch (kb.Key) {
  472. case Key.ControlC:
  473. // TODO: stop current execution of this container
  474. break;
  475. case Key.ControlZ:
  476. // TODO: should suspend
  477. // console_csharp_send_sigtstp ();
  478. break;
  479. case Key.Tab:
  480. var old = Focused;
  481. if (!FocusNext ())
  482. FocusNext ();
  483. old?.SetNeedsDisplay ();
  484. Focused?.SetNeedsDisplay ();
  485. break;
  486. case Key.BackTab:
  487. old = Focused;
  488. if (!FocusPrev ())
  489. FocusPrev ();
  490. old?.SetNeedsDisplay ();
  491. Focused?.SetNeedsDisplay ();
  492. break;
  493. }
  494. return false;
  495. }
  496. #if false
  497. public override void Redraw ()
  498. {
  499. base.Redraw ();
  500. for (int i = 0; i < Driver.Cols; i++) {
  501. Driver.Move (0, i);
  502. Driver.AddStr ("Line: " + i);
  503. }
  504. }
  505. #endif
  506. }
  507. /// <summary>
  508. /// A toplevel view that draws a frame around its region
  509. /// </summary>
  510. public class Window : Toplevel, IEnumerable {
  511. View contentView;
  512. string title;
  513. public string Title {
  514. get => title;
  515. set {
  516. title = value;
  517. SetNeedsDisplay ();
  518. }
  519. }
  520. public Window (Rect frame, string title = null) : base (frame)
  521. {
  522. this.Title = title;
  523. frame.Inflate (-1, -1);
  524. contentView = new View (frame);
  525. base.Add(contentView);
  526. }
  527. public new IEnumerator GetEnumerator ()
  528. {
  529. return contentView.GetEnumerator ();
  530. }
  531. void DrawFrame ()
  532. {
  533. DrawFrame (new Rect(0, 0, Frame.Width, Frame.Height), true);
  534. }
  535. public override void Add (View view)
  536. {
  537. contentView.Add (view);
  538. }
  539. public override void Redraw (Rect bounds)
  540. {
  541. Driver.SetAttribute (Colors.Base.Normal);
  542. DrawFrame ();
  543. if (HasFocus)
  544. Driver.SetAttribute (Colors.Dialog.Normal);
  545. var width = Frame.Width;
  546. if (Title != null && width > 4) {
  547. Move (1, 0);
  548. Driver.AddCh (' ');
  549. var str = Title.Length > width ? Title.Substring (0, width - 4) : Title;
  550. Driver.AddStr (str);
  551. Driver.AddCh (' ');
  552. }
  553. Driver.SetAttribute (Colors.Dialog.Normal);
  554. contentView.Redraw (contentView.Bounds);
  555. }
  556. }
  557. public class Application {
  558. public static ConsoleDriver Driver = new CursesDriver ();
  559. public static Toplevel Top { get; private set; }
  560. public static Mono.Terminal.MainLoop MainLoop { get; private set; }
  561. static Stack<View> toplevels = new Stack<View> ();
  562. static Responder focus;
  563. /// <summary>
  564. /// This event is raised on each iteration of the
  565. /// main loop.
  566. /// </summary>
  567. /// <remarks>
  568. /// See also <see cref="Timeout"/>
  569. /// </remarks>
  570. static public event EventHandler Iteration;
  571. public static void MakeFirstResponder (Responder newResponder)
  572. {
  573. if (newResponder == null)
  574. throw new ArgumentNullException ();
  575. throw new NotImplementedException ();
  576. }
  577. /// <summary>
  578. /// Initializes the Application
  579. /// </summary>
  580. public static void Init ()
  581. {
  582. if (Top != null)
  583. return;
  584. Driver.Init (TerminalResized);
  585. MainLoop = new Mono.Terminal.MainLoop ();
  586. Top = Toplevel.Create ();
  587. focus = Top;
  588. }
  589. public class RunState : IDisposable {
  590. internal RunState (Toplevel view)
  591. {
  592. Toplevel = view;
  593. }
  594. internal Toplevel Toplevel;
  595. public void Dispose ()
  596. {
  597. Dispose (true);
  598. GC.SuppressFinalize(this);
  599. }
  600. public virtual void Dispose (bool disposing)
  601. {
  602. if (Toplevel != null){
  603. Application.End (Toplevel);
  604. Toplevel = null;
  605. }
  606. }
  607. }
  608. static void KeyEvent (Key key)
  609. {
  610. }
  611. static public RunState Begin (Toplevel toplevel)
  612. {
  613. if (toplevel == null)
  614. throw new ArgumentNullException (nameof(toplevel));
  615. var rs = new RunState (toplevel);
  616. Init ();
  617. toplevels.Push (toplevel);
  618. Driver.PrepareToRun (MainLoop, toplevel);
  619. toplevel.LayoutSubviews ();
  620. toplevel.FocusFirst ();
  621. Redraw (toplevel);
  622. toplevel.PositionCursor ();
  623. Driver.Refresh ();
  624. return rs;
  625. }
  626. static public void End (RunState rs)
  627. {
  628. if (rs == null)
  629. throw new ArgumentNullException (nameof (rs));
  630. rs.Dispose ();
  631. }
  632. static void Shutdown ()
  633. {
  634. Driver.End ();
  635. }
  636. static void Redraw (View view)
  637. {
  638. view.Redraw (view.Bounds);
  639. Driver.Refresh ();
  640. }
  641. static void Refresh (View view)
  642. {
  643. view.Redraw (view.Bounds);
  644. Driver.Refresh ();
  645. }
  646. public static void Refresh ()
  647. {
  648. Driver.RedrawTop ();
  649. View last = null;
  650. foreach (var v in toplevels){
  651. v.Redraw (v.Bounds);
  652. last = v;
  653. }
  654. if (last != null)
  655. last.PositionCursor ();
  656. Driver.Refresh ();
  657. }
  658. internal static void End (View view)
  659. {
  660. if (toplevels.Peek () != view)
  661. throw new ArgumentException ("The view that you end with must be balanced");
  662. toplevels.Pop ();
  663. if (toplevels.Count == 0)
  664. Shutdown ();
  665. else
  666. Refresh ();
  667. }
  668. /// <summary>
  669. /// Runs the main loop for the created dialog
  670. /// </summary>
  671. /// <remarks>
  672. /// Use the wait parameter to control whether this is a
  673. /// blocking or non-blocking call.
  674. /// </remarks>
  675. public static void RunLoop(RunState state, bool wait = true)
  676. {
  677. if (state == null)
  678. throw new ArgumentNullException(nameof(state));
  679. if (state.Toplevel == null)
  680. throw new ObjectDisposedException("state");
  681. for (state.Toplevel.Running = true; state.Toplevel.Running;) {
  682. if (MainLoop.EventsPending(wait)){
  683. MainLoop.MainIteration();
  684. if (Iteration != null)
  685. Iteration(null, EventArgs.Empty);
  686. } else if (wait == false)
  687. return;
  688. if (state.Toplevel.NeedDisplay)
  689. state.Toplevel.Redraw (state.Toplevel.Bounds);
  690. }
  691. }
  692. public static void Run ()
  693. {
  694. Run (Top);
  695. }
  696. /// <summary>
  697. /// Runs the main loop on the given container.
  698. /// </summary>
  699. /// <remarks>
  700. /// This method is used to start processing events
  701. /// for the main application, but it is also used to
  702. /// run modal dialog boxes.
  703. /// </remarks>
  704. public static void Run (Toplevel view)
  705. {
  706. var runToken = Begin (view);
  707. RunLoop (runToken);
  708. End (runToken);
  709. }
  710. static void TerminalResized ()
  711. {
  712. foreach (var t in toplevels) {
  713. t.Frame = new Rect (0, 0, Driver.Cols, Driver.Rows);
  714. }
  715. }
  716. }
  717. }