Application.Run.cs 23 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579
  1. #nullable enable
  2. using System.Diagnostics;
  3. using System.Diagnostics.CodeAnalysis;
  4. namespace Terminal.Gui.App;
  5. public static partial class Application // Run (Begin -> Run -> Layout/Draw -> End -> Stop)
  6. {
  7. /// <summary>Gets or sets the key to quit the application.</summary>
  8. [ConfigurationProperty (Scope = typeof (SettingsScope))]
  9. public static Key QuitKey
  10. {
  11. get => Keyboard.QuitKey;
  12. set => Keyboard.QuitKey = value;
  13. }
  14. /// <summary>Gets or sets the key to activate arranging views using the keyboard.</summary>
  15. [ConfigurationProperty (Scope = typeof (SettingsScope))]
  16. public static Key ArrangeKey
  17. {
  18. get => Keyboard.ArrangeKey;
  19. set => Keyboard.ArrangeKey = value;
  20. }
  21. // When `End ()` is called, it is possible `RunState.Toplevel` is a different object than `Top`.
  22. // This variable is set in `End` in this case so that `Begin` correctly sets `Top`.
  23. private static Toplevel? _cachedRunStateToplevel;
  24. /// <summary>
  25. /// Notify that a new <see cref="RunState"/> was created (<see cref="Begin(Toplevel)"/> was called). The token is
  26. /// created in <see cref="Begin(Toplevel)"/> and this event will be fired before that function exits.
  27. /// </summary>
  28. /// <remarks>
  29. /// If <see cref="EndAfterFirstIteration"/> is <see langword="true"/> callers to <see cref="Begin(Toplevel)"/>
  30. /// must also subscribe to <see cref="NotifyStopRunState"/> and manually dispose of the <see cref="RunState"/> token
  31. /// when the application is done.
  32. /// </remarks>
  33. public static event EventHandler<RunStateEventArgs>? NotifyNewRunState;
  34. /// <summary>Notify that an existent <see cref="RunState"/> is stopping (<see cref="End(RunState)"/> was called).</summary>
  35. /// <remarks>
  36. /// If <see cref="EndAfterFirstIteration"/> is <see langword="true"/> callers to <see cref="Begin(Toplevel)"/>
  37. /// must also subscribe to <see cref="NotifyStopRunState"/> and manually dispose of the <see cref="RunState"/> token
  38. /// when the application is done.
  39. /// </remarks>
  40. public static event EventHandler<ToplevelEventArgs>? NotifyStopRunState;
  41. /// <summary>Building block API: Prepares the provided <see cref="Toplevel"/> for execution.</summary>
  42. /// <returns>
  43. /// The <see cref="RunState"/> handle that needs to be passed to the <see cref="End(RunState)"/> method upon
  44. /// completion.
  45. /// </returns>
  46. /// <param name="toplevel">The <see cref="Toplevel"/> to prepare execution for.</param>
  47. /// <remarks>
  48. /// This method prepares the provided <see cref="Toplevel"/> for running with the focus, it adds this to the list
  49. /// of <see cref="Toplevel"/>s, lays out the SubViews, focuses the first element, and draws the <see cref="Toplevel"/>
  50. /// in the screen. This is usually followed by executing the <see cref="RunLoop"/> method, and then the
  51. /// <see cref="End(RunState)"/> method upon termination which will undo these changes.
  52. /// </remarks>
  53. public static RunState Begin (Toplevel toplevel)
  54. {
  55. ArgumentNullException.ThrowIfNull (toplevel);
  56. //#if DEBUG_IDISPOSABLE
  57. // Debug.Assert (!toplevel.WasDisposed);
  58. // if (_cachedRunStateToplevel is { } && _cachedRunStateToplevel != toplevel)
  59. // {
  60. // Debug.Assert (_cachedRunStateToplevel.WasDisposed);
  61. // }
  62. //#endif
  63. // Ensure the mouse is ungrabbed.
  64. if (Mouse.MouseGrabView is { })
  65. {
  66. Mouse.UngrabMouse ();
  67. }
  68. var rs = new RunState (toplevel);
  69. #if DEBUG_IDISPOSABLE
  70. if (View.EnableDebugIDisposableAsserts && Top is { } && toplevel != Top && !TopLevels.Contains (Top))
  71. {
  72. // This assertion confirm if the Top was already disposed
  73. Debug.Assert (Top.WasDisposed);
  74. Debug.Assert (Top == _cachedRunStateToplevel);
  75. }
  76. #endif
  77. lock (TopLevels)
  78. {
  79. if (Top is { } && toplevel != Top && !TopLevels.Contains (Top))
  80. {
  81. // If Top was already disposed and isn't on the Toplevels Stack,
  82. // clean it up here if is the same as _cachedRunStateToplevel
  83. if (Top == _cachedRunStateToplevel)
  84. {
  85. Top = null;
  86. }
  87. else
  88. {
  89. // Probably this will never hit
  90. throw new ObjectDisposedException (Top.GetType ().FullName);
  91. }
  92. }
  93. // BUGBUG: We should not depend on `Id` internally.
  94. // BUGBUG: It is super unclear what this code does anyway.
  95. if (string.IsNullOrEmpty (toplevel.Id))
  96. {
  97. var count = 1;
  98. var id = (TopLevels.Count + count).ToString ();
  99. while (TopLevels.Count > 0 && TopLevels.FirstOrDefault (x => x.Id == id) is { })
  100. {
  101. count++;
  102. id = (TopLevels.Count + count).ToString ();
  103. }
  104. toplevel.Id = (TopLevels.Count + count).ToString ();
  105. TopLevels.Push (toplevel);
  106. }
  107. else
  108. {
  109. Toplevel? dup = TopLevels.FirstOrDefault (x => x.Id == toplevel.Id);
  110. if (dup is null)
  111. {
  112. TopLevels.Push (toplevel);
  113. }
  114. }
  115. //if (TopLevels.FindDuplicates (new ToplevelEqualityComparer ()).Count > 0)
  116. //{
  117. // throw new ArgumentException ("There are duplicates Toplevel IDs");
  118. //}
  119. }
  120. if (Top is null)
  121. {
  122. Top = toplevel;
  123. }
  124. if ((Top?.Modal == false && toplevel.Modal)
  125. || (Top?.Modal == false && !toplevel.Modal)
  126. || (Top?.Modal == true && toplevel.Modal))
  127. {
  128. if (toplevel.Visible)
  129. {
  130. if (Top is { HasFocus: true })
  131. {
  132. Top.HasFocus = false;
  133. }
  134. // Force leave events for any entered views in the old Top
  135. if (GetLastMousePosition () is { })
  136. {
  137. RaiseMouseEnterLeaveEvents (GetLastMousePosition ()!.Value, new ());
  138. }
  139. Top?.OnDeactivate (toplevel);
  140. Toplevel previousTop = Top!;
  141. Top = toplevel;
  142. Top.OnActivate (previousTop);
  143. }
  144. }
  145. // View implements ISupportInitializeNotification which is derived from ISupportInitialize
  146. if (!toplevel.IsInitialized)
  147. {
  148. toplevel.BeginInit ();
  149. toplevel.EndInit (); // Calls Layout
  150. }
  151. // Call ConfigurationManager Apply here to ensure all subscribers to ConfigurationManager.Applied
  152. // can update their state appropriately.
  153. // BUGBUG: DO NOT DO THIS. Leave this commented out until we can figure out how to do this right
  154. //Apply ();
  155. // Try to set initial focus to any TabStop
  156. if (!toplevel.HasFocus)
  157. {
  158. toplevel.SetFocus ();
  159. }
  160. toplevel.OnLoaded ();
  161. ApplicationImpl.Instance.LayoutAndDraw (true);
  162. if (PositionCursor ())
  163. {
  164. Driver?.UpdateCursor ();
  165. }
  166. NotifyNewRunState?.Invoke (toplevel, new (rs));
  167. return rs;
  168. }
  169. /// <summary>
  170. /// Calls <see cref="View.PositionCursor"/> on the most focused view.
  171. /// </summary>
  172. /// <remarks>
  173. /// Does nothing if there is no most focused view.
  174. /// <para>
  175. /// If the most focused view is not visible within it's superview, the cursor will be hidden.
  176. /// </para>
  177. /// </remarks>
  178. /// <returns><see langword="true"/> if a view positioned the cursor and the position is visible.</returns>
  179. internal static bool PositionCursor ()
  180. {
  181. // Find the most focused view and position the cursor there.
  182. View? mostFocused = Navigation?.GetFocused ();
  183. // If the view is not visible or enabled, don't position the cursor
  184. if (mostFocused is null || !mostFocused.Visible || !mostFocused.Enabled)
  185. {
  186. var current = CursorVisibility.Invisible;
  187. Driver?.GetCursorVisibility (out current);
  188. if (current != CursorVisibility.Invisible)
  189. {
  190. Driver?.SetCursorVisibility (CursorVisibility.Invisible);
  191. }
  192. return false;
  193. }
  194. // If the view is not visible within it's superview, don't position the cursor
  195. Rectangle mostFocusedViewport = mostFocused.ViewportToScreen (mostFocused.Viewport with { Location = Point.Empty });
  196. Rectangle superViewViewport =
  197. mostFocused.SuperView?.ViewportToScreen (mostFocused.SuperView.Viewport with { Location = Point.Empty }) ?? Driver!.Screen;
  198. if (!superViewViewport.IntersectsWith (mostFocusedViewport))
  199. {
  200. return false;
  201. }
  202. Point? cursor = mostFocused.PositionCursor ();
  203. Driver!.GetCursorVisibility (out CursorVisibility currentCursorVisibility);
  204. if (cursor is { })
  205. {
  206. // Convert cursor to screen coords
  207. cursor = mostFocused.ViewportToScreen (mostFocused.Viewport with { Location = cursor.Value }).Location;
  208. // If the cursor is not in a visible location in the SuperView, hide it
  209. if (!superViewViewport.Contains (cursor.Value))
  210. {
  211. if (currentCursorVisibility != CursorVisibility.Invisible)
  212. {
  213. Driver.SetCursorVisibility (CursorVisibility.Invisible);
  214. }
  215. return false;
  216. }
  217. // Show it
  218. if (currentCursorVisibility == CursorVisibility.Invisible)
  219. {
  220. Driver.SetCursorVisibility (mostFocused.CursorVisibility);
  221. }
  222. return true;
  223. }
  224. if (currentCursorVisibility != CursorVisibility.Invisible)
  225. {
  226. Driver.SetCursorVisibility (CursorVisibility.Invisible);
  227. }
  228. return false;
  229. }
  230. /// <summary>
  231. /// Runs the application by creating a <see cref="Toplevel"/> object and calling
  232. /// <see cref="Run(Toplevel, Func{Exception, bool})"/>.
  233. /// </summary>
  234. /// <remarks>
  235. /// <para>Calling <see cref="Init"/> first is not needed as this function will initialize the application.</para>
  236. /// <para>
  237. /// <see cref="Shutdown"/> must be called when the application is closing (typically after Run> has returned) to
  238. /// ensure resources are cleaned up and terminal settings restored.
  239. /// </para>
  240. /// <para>
  241. /// The caller is responsible for disposing the object returned by this method.
  242. /// </para>
  243. /// </remarks>
  244. /// <returns>The created <see cref="Toplevel"/> object. The caller is responsible for disposing this object.</returns>
  245. [RequiresUnreferencedCode ("AOT")]
  246. [RequiresDynamicCode ("AOT")]
  247. public static Toplevel Run (Func<Exception, bool>? errorHandler = null, IConsoleDriver? driver = null)
  248. {
  249. return ApplicationImpl.Instance.Run (errorHandler, driver);
  250. }
  251. /// <summary>
  252. /// Runs the application by creating a <see cref="Toplevel"/>-derived object of type <c>T</c> and calling
  253. /// <see cref="Run(Toplevel, Func{Exception, bool})"/>.
  254. /// </summary>
  255. /// <remarks>
  256. /// <para>Calling <see cref="Init"/> first is not needed as this function will initialize the application.</para>
  257. /// <para>
  258. /// <see cref="Shutdown"/> must be called when the application is closing (typically after Run> has returned) to
  259. /// ensure resources are cleaned up and terminal settings restored.
  260. /// </para>
  261. /// <para>
  262. /// The caller is responsible for disposing the object returned by this method.
  263. /// </para>
  264. /// </remarks>
  265. /// <param name="errorHandler"></param>
  266. /// <param name="driver">
  267. /// The <see cref="IConsoleDriver"/> to use. If not specified the default driver for the platform will
  268. /// be used. Must be <see langword="null"/> if <see cref="Init"/> has already been called.
  269. /// </param>
  270. /// <returns>The created T object. The caller is responsible for disposing this object.</returns>
  271. [RequiresUnreferencedCode ("AOT")]
  272. [RequiresDynamicCode ("AOT")]
  273. public static T Run<T> (Func<Exception, bool>? errorHandler = null, IConsoleDriver? driver = null)
  274. where T : Toplevel, new()
  275. {
  276. return ApplicationImpl.Instance.Run<T> (errorHandler, driver);
  277. }
  278. /// <summary>Runs the Application using the provided <see cref="Toplevel"/> view.</summary>
  279. /// <remarks>
  280. /// <para>
  281. /// This method is used to start processing events for the main application, but it is also used to run other
  282. /// modal <see cref="View"/>s such as <see cref="Dialog"/> boxes.
  283. /// </para>
  284. /// <para>
  285. /// To make a <see cref="Run(Toplevel,System.Func{System.Exception,bool})"/> stop execution, call
  286. /// <see cref="Application.RequestStop"/>.
  287. /// </para>
  288. /// <para>
  289. /// Calling <see cref="Run(Toplevel,System.Func{System.Exception,bool})"/> is equivalent to calling
  290. /// <see cref="Begin(Toplevel)"/>, followed by <see cref="RunLoop(RunState)"/>, and then calling
  291. /// <see cref="End(RunState)"/>.
  292. /// </para>
  293. /// <para>
  294. /// Alternatively, to have a program control the main loop and process events manually, call
  295. /// <see cref="Begin(Toplevel)"/> to set things up manually and then repeatedly call
  296. /// <see cref="RunLoop(RunState)"/> with the wait parameter set to false. By doing this the
  297. /// <see cref="RunLoop(RunState)"/> method will only process any pending events, timers handlers and then
  298. /// return control immediately.
  299. /// </para>
  300. /// <para>
  301. /// When using <see cref="Run{T}"/> or
  302. /// <see cref="Run(System.Func{System.Exception,bool},IConsoleDriver)"/>
  303. /// <see cref="Init"/> will be called automatically.
  304. /// </para>
  305. /// <para>
  306. /// RELEASE builds only: When <paramref name="errorHandler"/> is <see langword="null"/> any exceptions will be
  307. /// rethrown. Otherwise, if <paramref name="errorHandler"/> will be called. If <paramref name="errorHandler"/>
  308. /// returns <see langword="true"/> the <see cref="RunLoop(RunState)"/> will resume; otherwise this method will
  309. /// exit.
  310. /// </para>
  311. /// </remarks>
  312. /// <param name="view">The <see cref="Toplevel"/> to run as a modal.</param>
  313. /// <param name="errorHandler">
  314. /// RELEASE builds only: Handler for any unhandled exceptions (resumes when returns true,
  315. /// rethrows when null).
  316. /// </param>
  317. public static void Run (Toplevel view, Func<Exception, bool>? errorHandler = null) { ApplicationImpl.Instance.Run (view, errorHandler); }
  318. /// <summary>Adds a timeout to the application.</summary>
  319. /// <remarks>
  320. /// When time specified passes, the callback will be invoked. If the callback returns true, the timeout will be
  321. /// reset, repeating the invocation. If it returns false, the timeout will stop and be removed. The returned value is a
  322. /// token that can be used to stop the timeout by calling <see cref="RemoveTimeout(object)"/>.
  323. /// </remarks>
  324. public static object? AddTimeout (TimeSpan time, Func<bool> callback) { return ApplicationImpl.Instance.AddTimeout (time, callback); }
  325. /// <summary>Removes a previously scheduled timeout</summary>
  326. /// <remarks>The token parameter is the value returned by <see cref="AddTimeout"/>.</remarks>
  327. /// Returns
  328. /// <see langword="true"/>
  329. /// if the timeout is successfully removed; otherwise,
  330. /// <see langword="false"/>
  331. /// .
  332. /// This method also returns
  333. /// <see langword="false"/>
  334. /// if the timeout is not found.
  335. public static bool RemoveTimeout (object token) { return ApplicationImpl.Instance.RemoveTimeout (token); }
  336. /// <summary>Runs <paramref name="action"/> on the thread that is processing events</summary>
  337. /// <param name="action">the action to be invoked on the main processing thread.</param>
  338. public static void Invoke (Action action) { ApplicationImpl.Instance.Invoke (action); }
  339. // TODO: Determine if this is really needed. The only code that calls WakeUp I can find
  340. // is ProgressBarStyles, and it's not clear it needs to.
  341. /// <summary>Wakes up the running application that might be waiting on input.</summary>
  342. public static void Wakeup () { MainLoop?.Wakeup (); }
  343. /// <summary>
  344. /// Causes any Toplevels that need layout to be laid out. Then draws any Toplevels that need display. Only Views that
  345. /// need to be laid out (see <see cref="View.NeedsLayout"/>) will be laid out.
  346. /// Only Views that need to be drawn (see <see cref="View.NeedsDraw"/>) will be drawn.
  347. /// </summary>
  348. /// <param name="forceDraw">
  349. /// If <see langword="true"/> the entire View hierarchy will be redrawn. The default is <see langword="false"/> and
  350. /// should only be overriden for testing.
  351. /// </param>
  352. public static void LayoutAndDraw (bool forceRedraw = false)
  353. {
  354. ApplicationImpl.Instance.LayoutAndDraw (forceRedraw);
  355. }
  356. /// <summary>This event is raised on each iteration of the main loop.</summary>
  357. /// <remarks>See also <see cref="Timeout"/></remarks>
  358. public static event EventHandler<IterationEventArgs>? Iteration;
  359. /// <summary>The <see cref="MainLoop"/> driver for the application</summary>
  360. /// <value>The main loop.</value>
  361. internal static MainLoop? MainLoop { get; set; }
  362. /// <summary>
  363. /// Set to true to cause <see cref="End"/> to be called after the first iteration. Set to false (the default) to
  364. /// cause the application to continue running until Application.RequestStop () is called.
  365. /// </summary>
  366. public static bool EndAfterFirstIteration { get; set; }
  367. /// <summary>Building block API: Runs the main loop for the created <see cref="Toplevel"/>.</summary>
  368. /// <param name="state">The state returned by the <see cref="Begin(Toplevel)"/> method.</param>
  369. public static void RunLoop (RunState state)
  370. {
  371. ArgumentNullException.ThrowIfNull (state);
  372. ObjectDisposedException.ThrowIf (state.Toplevel is null, "state");
  373. var firstIteration = true;
  374. for (state.Toplevel.Running = true; state.Toplevel?.Running == true;)
  375. {
  376. if (MainLoop is { })
  377. {
  378. MainLoop.Running = true;
  379. }
  380. if (EndAfterFirstIteration && !firstIteration)
  381. {
  382. return;
  383. }
  384. firstIteration = RunIteration (ref state, firstIteration);
  385. }
  386. if (MainLoop is { })
  387. {
  388. MainLoop.Running = false;
  389. }
  390. // Run one last iteration to consume any outstanding input events from Driver
  391. // This is important for remaining OnKeyUp events.
  392. RunIteration (ref state, firstIteration);
  393. }
  394. /// <summary>Run one application iteration.</summary>
  395. /// <param name="state">The state returned by <see cref="Begin(Toplevel)"/>.</param>
  396. /// <param name="firstIteration">
  397. /// Set to <see langword="true"/> if this is the first run loop iteration.
  398. /// </param>
  399. /// <returns><see langword="false"/> if at least one iteration happened.</returns>
  400. public static bool RunIteration (ref RunState state, bool firstIteration = false)
  401. {
  402. // If the driver has events pending do an iteration of the driver MainLoop
  403. if (MainLoop is { Running: true } && MainLoop.EventsPending ())
  404. {
  405. // Notify Toplevel it's ready
  406. if (firstIteration)
  407. {
  408. state.Toplevel.OnReady ();
  409. }
  410. MainLoop.RunIteration ();
  411. Iteration?.Invoke (null, new ());
  412. }
  413. firstIteration = false;
  414. if (Top is null)
  415. {
  416. return firstIteration;
  417. }
  418. LayoutAndDraw (TopLevels.Any (v => v.NeedsLayout || v.NeedsDraw));
  419. if (PositionCursor ())
  420. {
  421. Driver?.UpdateCursor ();
  422. }
  423. return firstIteration;
  424. }
  425. /// <summary>Stops the provided <see cref="Toplevel"/>, causing or the <paramref name="top"/> if provided.</summary>
  426. /// <param name="top">The <see cref="Toplevel"/> to stop.</param>
  427. /// <remarks>
  428. /// <para>This will cause <see cref="Application.Run(Toplevel, Func{Exception, bool})"/> to return.</para>
  429. /// <para>
  430. /// Calling <see cref="RequestStop(Toplevel)"/> is equivalent to setting the
  431. /// <see cref="Toplevel.Running"/>
  432. /// property on the currently running <see cref="Toplevel"/> to false.
  433. /// </para>
  434. /// </remarks>
  435. public static void RequestStop (Toplevel? top = null) { ApplicationImpl.Instance.RequestStop (top); }
  436. internal static void OnNotifyStopRunState (Toplevel top)
  437. {
  438. if (EndAfterFirstIteration)
  439. {
  440. NotifyStopRunState?.Invoke (top, new (top));
  441. }
  442. }
  443. /// <summary>
  444. /// Building block API: completes the execution of a <see cref="Toplevel"/> that was started with
  445. /// <see cref="Begin(Toplevel)"/> .
  446. /// </summary>
  447. /// <param name="runState">The <see cref="RunState"/> returned by the <see cref="Begin(Toplevel)"/> method.</param>
  448. public static void End (RunState runState)
  449. {
  450. ArgumentNullException.ThrowIfNull (runState);
  451. if (Popover?.GetActivePopover () as View is { Visible: true } visiblePopover)
  452. {
  453. ApplicationPopover.HideWithQuitCommand (visiblePopover);
  454. }
  455. runState.Toplevel.OnUnloaded ();
  456. // End the RunState.Toplevel
  457. // First, take it off the Toplevel Stack
  458. if (TopLevels.TryPop (out Toplevel? topOfStack))
  459. {
  460. if (topOfStack != runState.Toplevel)
  461. {
  462. // If the top of the stack is not the RunState.Toplevel then
  463. // this call to End is not balanced with the call to Begin that started the RunState
  464. throw new ArgumentException ("End must be balanced with calls to Begin");
  465. }
  466. }
  467. // Notify that it is closing
  468. runState.Toplevel?.OnClosed (runState.Toplevel);
  469. if (TopLevels.TryPeek (out Toplevel? newTop))
  470. {
  471. Top = newTop;
  472. Top?.SetNeedsDraw ();
  473. }
  474. if (runState.Toplevel is { HasFocus: true })
  475. {
  476. runState.Toplevel.HasFocus = false;
  477. }
  478. if (Top is { HasFocus: false })
  479. {
  480. Top.SetFocus ();
  481. }
  482. _cachedRunStateToplevel = runState.Toplevel;
  483. runState.Toplevel = null;
  484. runState.Dispose ();
  485. LayoutAndDraw (true);
  486. }
  487. internal static void RaiseIteration ()
  488. {
  489. Iteration?.Invoke (null, new ());
  490. }
  491. }