Core.cs 25 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821
  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. public override bool ProcessKey (KeyEvent kb)
  338. {
  339. if (Focused?.ProcessKey (kb) == true)
  340. return true;
  341. return false;
  342. }
  343. /// <summary>
  344. /// Finds the first view in the hierarchy that wants to get the focus if nothing is currently focused, otherwise, it does nothing.
  345. /// </summary>
  346. public void EnsureFocus ()
  347. {
  348. if (focused == null)
  349. FocusFirst ();
  350. }
  351. /// <summary>
  352. /// Focuses the first focusable subview if one exists.
  353. /// </summary>
  354. public void FocusFirst ()
  355. {
  356. if (subviews == null)
  357. return;
  358. foreach (var view in subviews) {
  359. if (view.CanFocus) {
  360. SetFocus (view);
  361. return;
  362. }
  363. }
  364. }
  365. /// <summary>
  366. /// Focuses the last focusable subview if one exists.
  367. /// </summary>
  368. public void FocusLast ()
  369. {
  370. if (subviews == null)
  371. return;
  372. for (int i = subviews.Count; i > 0;) {
  373. i--;
  374. View v = subviews [i];
  375. if (v.CanFocus) {
  376. SetFocus (v);
  377. return;
  378. }
  379. }
  380. }
  381. /// <summary>
  382. /// Focuses the previous view.
  383. /// </summary>
  384. /// <returns><c>true</c>, if previous was focused, <c>false</c> otherwise.</returns>
  385. public bool FocusPrev ()
  386. {
  387. if (focused == null) {
  388. FocusLast ();
  389. return true;
  390. }
  391. int focused_idx = -1;
  392. for (int i = subviews.Count; i > 0;) {
  393. i--;
  394. View w = subviews [i];
  395. if (w.HasFocus) {
  396. if (w.FocusPrev ())
  397. return true;
  398. focused_idx = i;
  399. continue;
  400. }
  401. if (w.CanFocus && focused_idx != -1) {
  402. focused.HasFocus = false;
  403. if (w.CanFocus)
  404. w.FocusLast ();
  405. SetFocus (w);
  406. return true;
  407. }
  408. }
  409. if (focused != null) {
  410. focused.HasFocus = false;
  411. focused = null;
  412. }
  413. return false;
  414. }
  415. /// <summary>
  416. /// Focuses the next view.
  417. /// </summary>
  418. /// <returns><c>true</c>, if next was focused, <c>false</c> otherwise.</returns>
  419. public bool FocusNext ()
  420. {
  421. if (focused == null) {
  422. FocusFirst ();
  423. return focused != null;
  424. }
  425. int n = subviews.Count;
  426. int focused_idx = -1;
  427. for (int i = 0; i < n; i++) {
  428. View w = subviews [i];
  429. if (w.HasFocus) {
  430. if (w.FocusNext ())
  431. return true;
  432. focused_idx = i;
  433. continue;
  434. }
  435. if (w.CanFocus && focused_idx != -1) {
  436. focused.HasFocus = false;
  437. if (w != null && w.CanFocus)
  438. w.FocusFirst ();
  439. SetFocus (w);
  440. return true;
  441. }
  442. }
  443. if (focused != null) {
  444. focused.HasFocus = false;
  445. focused = null;
  446. }
  447. return false;
  448. }
  449. public virtual void LayoutSubviews ()
  450. {
  451. }
  452. }
  453. /// <summary>
  454. /// Toplevel views can be modally executed.
  455. /// </summary>
  456. public class Toplevel : View {
  457. public bool Running;
  458. public Toplevel (Rect frame) : base (frame)
  459. {
  460. }
  461. public static Toplevel Create ()
  462. {
  463. return new Toplevel (new Rect (0, 0, Driver.Cols, Driver.Rows));
  464. }
  465. public override bool CanFocus {
  466. get => true;
  467. }
  468. public override bool ProcessKey (KeyEvent kb)
  469. {
  470. if (ProcessHotKey (kb))
  471. return true;
  472. if (base.ProcessKey (kb))
  473. return true;
  474. // Process the key normally
  475. if (ProcessColdKey (kb))
  476. return true;
  477. switch (kb.Key) {
  478. case Key.ControlC:
  479. // TODO: stop current execution of this container
  480. break;
  481. case Key.ControlZ:
  482. // TODO: should suspend
  483. // console_csharp_send_sigtstp ();
  484. break;
  485. case Key.Tab:
  486. var old = Focused;
  487. if (!FocusNext ())
  488. FocusNext ();
  489. old?.SetNeedsDisplay ();
  490. Focused?.SetNeedsDisplay ();
  491. break;
  492. case Key.BackTab:
  493. old = Focused;
  494. if (!FocusPrev ())
  495. FocusPrev ();
  496. old?.SetNeedsDisplay ();
  497. Focused?.SetNeedsDisplay ();
  498. break;
  499. }
  500. return false;
  501. }
  502. #if false
  503. public override void Redraw ()
  504. {
  505. base.Redraw ();
  506. for (int i = 0; i < Driver.Cols; i++) {
  507. Driver.Move (0, i);
  508. Driver.AddStr ("Line: " + i);
  509. }
  510. }
  511. #endif
  512. }
  513. /// <summary>
  514. /// A toplevel view that draws a frame around its region
  515. /// </summary>
  516. public class Window : Toplevel, IEnumerable {
  517. View contentView;
  518. string title;
  519. public string Title {
  520. get => title;
  521. set {
  522. title = value;
  523. SetNeedsDisplay ();
  524. }
  525. }
  526. public Window (Rect frame, string title = null) : base (frame)
  527. {
  528. this.Title = title;
  529. frame.Inflate (-1, -1);
  530. contentView = new View (frame);
  531. base.Add(contentView);
  532. }
  533. public new IEnumerator GetEnumerator ()
  534. {
  535. return contentView.GetEnumerator ();
  536. }
  537. void DrawFrame ()
  538. {
  539. DrawFrame (new Rect(0, 0, Frame.Width, Frame.Height), true);
  540. }
  541. public override void Add (View view)
  542. {
  543. contentView.Add (view);
  544. }
  545. public override void Redraw (Rect bounds)
  546. {
  547. Driver.SetAttribute (Colors.Base.Normal);
  548. DrawFrame ();
  549. if (HasFocus)
  550. Driver.SetAttribute (Colors.Dialog.Normal);
  551. var width = Frame.Width;
  552. if (Title != null && width > 4) {
  553. Move (1, 0);
  554. Driver.AddCh (' ');
  555. var str = Title.Length > width ? Title.Substring (0, width - 4) : Title;
  556. Driver.AddStr (str);
  557. Driver.AddCh (' ');
  558. }
  559. Driver.SetAttribute (Colors.Dialog.Normal);
  560. contentView.Redraw (contentView.Bounds);
  561. }
  562. }
  563. public class Application {
  564. public static ConsoleDriver Driver = new CursesDriver ();
  565. public static Toplevel Top { get; private set; }
  566. public static Mono.Terminal.MainLoop MainLoop { get; private set; }
  567. static Stack<View> toplevels = new Stack<View> ();
  568. static Responder focus;
  569. /// <summary>
  570. /// This event is raised on each iteration of the
  571. /// main loop.
  572. /// </summary>
  573. /// <remarks>
  574. /// See also <see cref="Timeout"/>
  575. /// </remarks>
  576. static public event EventHandler Iteration;
  577. public static void MakeFirstResponder (Responder newResponder)
  578. {
  579. if (newResponder == null)
  580. throw new ArgumentNullException ();
  581. throw new NotImplementedException ();
  582. }
  583. /// <summary>
  584. /// Initializes the Application
  585. /// </summary>
  586. public static void Init ()
  587. {
  588. if (Top != null)
  589. return;
  590. Driver.Init (TerminalResized);
  591. MainLoop = new Mono.Terminal.MainLoop ();
  592. Top = Toplevel.Create ();
  593. focus = Top;
  594. }
  595. public class RunState : IDisposable {
  596. internal RunState (Toplevel view)
  597. {
  598. Toplevel = view;
  599. }
  600. internal Toplevel Toplevel;
  601. public void Dispose ()
  602. {
  603. Dispose (true);
  604. GC.SuppressFinalize(this);
  605. }
  606. public virtual void Dispose (bool disposing)
  607. {
  608. if (Toplevel != null){
  609. Application.End (Toplevel);
  610. Toplevel = null;
  611. }
  612. }
  613. }
  614. static void KeyEvent (Key key)
  615. {
  616. }
  617. static public RunState Begin (Toplevel toplevel)
  618. {
  619. if (toplevel == null)
  620. throw new ArgumentNullException (nameof(toplevel));
  621. var rs = new RunState (toplevel);
  622. Init ();
  623. toplevels.Push (toplevel);
  624. Driver.PrepareToRun (MainLoop, toplevel);
  625. toplevel.LayoutSubviews ();
  626. toplevel.FocusFirst ();
  627. Redraw (toplevel);
  628. toplevel.PositionCursor ();
  629. Driver.Refresh ();
  630. return rs;
  631. }
  632. static public void End (RunState rs)
  633. {
  634. if (rs == null)
  635. throw new ArgumentNullException (nameof (rs));
  636. rs.Dispose ();
  637. }
  638. static void Shutdown ()
  639. {
  640. Driver.End ();
  641. }
  642. static void Redraw (View view)
  643. {
  644. view.Redraw (view.Bounds);
  645. Driver.Refresh ();
  646. }
  647. static void Refresh (View view)
  648. {
  649. view.Redraw (view.Bounds);
  650. Driver.Refresh ();
  651. }
  652. public static void Refresh ()
  653. {
  654. Driver.RedrawTop ();
  655. View last = null;
  656. foreach (var v in toplevels){
  657. v.Redraw (v.Bounds);
  658. last = v;
  659. }
  660. if (last != null)
  661. last.PositionCursor ();
  662. Driver.Refresh ();
  663. }
  664. internal static void End (View view)
  665. {
  666. if (toplevels.Peek () != view)
  667. throw new ArgumentException ("The view that you end with must be balanced");
  668. toplevels.Pop ();
  669. if (toplevels.Count == 0)
  670. Shutdown ();
  671. else
  672. Refresh ();
  673. }
  674. /// <summary>
  675. /// Runs the main loop for the created dialog
  676. /// </summary>
  677. /// <remarks>
  678. /// Use the wait parameter to control whether this is a
  679. /// blocking or non-blocking call.
  680. /// </remarks>
  681. public static void RunLoop(RunState state, bool wait = true)
  682. {
  683. if (state == null)
  684. throw new ArgumentNullException(nameof(state));
  685. if (state.Toplevel == null)
  686. throw new ObjectDisposedException("state");
  687. for (state.Toplevel.Running = true; state.Toplevel.Running;) {
  688. if (MainLoop.EventsPending(wait)){
  689. MainLoop.MainIteration();
  690. if (Iteration != null)
  691. Iteration(null, EventArgs.Empty);
  692. } else if (wait == false)
  693. return;
  694. if (state.Toplevel.NeedDisplay)
  695. state.Toplevel.Redraw (state.Toplevel.Bounds);
  696. }
  697. }
  698. public static void Run ()
  699. {
  700. Run (Top);
  701. }
  702. /// <summary>
  703. /// Runs the main loop on the given container.
  704. /// </summary>
  705. /// <remarks>
  706. /// This method is used to start processing events
  707. /// for the main application, but it is also used to
  708. /// run modal dialog boxes.
  709. /// </remarks>
  710. public static void Run (Toplevel view)
  711. {
  712. var runToken = Begin (view);
  713. RunLoop (runToken);
  714. End (runToken);
  715. }
  716. static void TerminalResized ()
  717. {
  718. foreach (var t in toplevels) {
  719. t.Frame = new Rect (0, 0, Driver.Cols, Driver.Rows);
  720. }
  721. }
  722. }
  723. }