Application.cs 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660
  1. //
  2. // Authors:
  3. // Miguel de Icaza ([email protected])
  4. //
  5. // Pending:
  6. // - Check for NeedDisplay on the hierarchy and repaint
  7. // - Layout support
  8. // - "Colors" type or "Attributes" type?
  9. // - What to surface as "BackgroundCOlor" when clearing a window, an attribute or colors?
  10. //
  11. // Optimziations
  12. // - Add rendering limitation to the exposed area
  13. using System;
  14. using System.Collections.Generic;
  15. using System.Threading;
  16. using System.ComponentModel;
  17. using System.Linq;
  18. namespace Terminal.Gui {
  19. /// <summary>
  20. /// The application driver for Terminal.Gui.
  21. /// </summary>
  22. /// <remarks>
  23. /// <para>
  24. /// You can hook up to the <see cref="Iteration"/> event to have your method
  25. /// invoked on each iteration of the <see cref="Terminal.Gui.MainLoop"/>.
  26. /// </para>
  27. /// <para>
  28. /// Creates a instance of <see cref="Terminal.Gui.MainLoop"/> to process input events, handle timers and
  29. /// other sources of data. It is accessible via the <see cref="MainLoop"/> property.
  30. /// </para>
  31. /// <para>
  32. /// When invoked sets the SynchronizationContext to one that is tied
  33. /// to the mainloop, allowing user code to use async/await.
  34. /// </para>
  35. /// </remarks>
  36. public static class Application {
  37. /// <summary>
  38. /// The current <see cref="ConsoleDriver"/> in use.
  39. /// </summary>
  40. public static ConsoleDriver Driver;
  41. /// <summary>
  42. /// The <see cref="Toplevel"/> object used for the application on startup (<seealso cref="Application.Top"/>)
  43. /// </summary>
  44. /// <value>The top.</value>
  45. public static Toplevel Top { get; private set; }
  46. /// <summary>
  47. /// The current <see cref="Toplevel"/> object. This is updated when <see cref="Application.Run()"/> enters and leaves to point to the current <see cref="Toplevel"/> .
  48. /// </summary>
  49. /// <value>The current.</value>
  50. public static Toplevel Current { get; private set; }
  51. /// <summary>
  52. /// TThe current <see cref="View"/> object being redrawn.
  53. /// </summary>
  54. /// /// <value>The current.</value>
  55. public static View CurrentView { get; set; }
  56. /// <summary>
  57. /// The <see cref="MainLoop"/> driver for the applicaiton
  58. /// </summary>
  59. /// <value>The main loop.</value>
  60. public static MainLoop MainLoop { get; private set; }
  61. static Stack<Toplevel> toplevels = new Stack<Toplevel> ();
  62. /// <summary>
  63. /// This event is raised on each iteration of the <see cref="MainLoop"/>
  64. /// </summary>
  65. /// <remarks>
  66. /// See also <see cref="Timeout"/>
  67. /// </remarks>
  68. public static event EventHandler Iteration;
  69. /// <summary>
  70. /// Returns a rectangle that is centered in the screen for the provided size.
  71. /// </summary>
  72. /// <returns>The centered rect.</returns>
  73. /// <param name="size">Size for the rectangle.</param>
  74. public static Rect MakeCenteredRect (Size size)
  75. {
  76. return new Rect (new Point ((Driver.Cols - size.Width) / 2, (Driver.Rows - size.Height) / 2), size);
  77. }
  78. //
  79. // provides the sync context set while executing code in Terminal.Gui, to let
  80. // users use async/await on their code
  81. //
  82. class MainLoopSyncContext : SynchronizationContext {
  83. MainLoop mainLoop;
  84. public MainLoopSyncContext (MainLoop mainLoop)
  85. {
  86. this.mainLoop = mainLoop;
  87. }
  88. public override SynchronizationContext CreateCopy ()
  89. {
  90. return new MainLoopSyncContext (MainLoop);
  91. }
  92. public override void Post (SendOrPostCallback d, object state)
  93. {
  94. mainLoop.AddIdle (() => {
  95. d (state);
  96. return false;
  97. });
  98. mainLoop.Driver.Wakeup ();
  99. }
  100. public override void Send (SendOrPostCallback d, object state)
  101. {
  102. mainLoop.Invoke (() => {
  103. d (state);
  104. });
  105. }
  106. }
  107. /// <summary>
  108. /// If set, it forces the use of the System.Console-based driver.
  109. /// </summary>
  110. public static bool UseSystemConsole;
  111. /// <summary>
  112. /// Initializes a new instance of <see cref="Terminal.Gui"/> Application.
  113. /// </summary>
  114. /// <remarks>
  115. /// <para>
  116. /// Call this method once per instance (or after <see cref="Shutdown"/> has been called).
  117. /// </para>
  118. /// <para>
  119. /// Loads the right <see cref="ConsoleDriver"/> for the platform.
  120. /// </para>
  121. /// <para>
  122. /// Creates a <see cref="Toplevel"/> and assigns it to <see cref="Top"/> and <see cref="CurrentView"/>
  123. /// </para>
  124. /// </remarks>
  125. public static void Init () => Init (() => Toplevel.Create ());
  126. internal static bool _initialized = false;
  127. /// <summary>
  128. /// Initializes the Terminal.Gui application
  129. /// </summary>
  130. static void Init (Func<Toplevel> topLevelFactory)
  131. {
  132. if (_initialized) return;
  133. var p = Environment.OSVersion.Platform;
  134. IMainLoopDriver mainLoopDriver;
  135. if (UseSystemConsole) {
  136. mainLoopDriver = new NetMainLoop ();
  137. Driver = new NetDriver ();
  138. } else if (p == PlatformID.Win32NT || p == PlatformID.Win32S || p == PlatformID.Win32Windows) {
  139. var windowsDriver = new WindowsDriver ();
  140. mainLoopDriver = windowsDriver;
  141. Driver = windowsDriver;
  142. } else {
  143. mainLoopDriver = new UnixMainLoop ();
  144. Driver = new CursesDriver ();
  145. }
  146. Driver.Init (TerminalResized);
  147. MainLoop = new MainLoop (mainLoopDriver);
  148. SynchronizationContext.SetSynchronizationContext (new MainLoopSyncContext (MainLoop));
  149. Top = topLevelFactory ();
  150. Current = Top;
  151. CurrentView = Top;
  152. _initialized = true;
  153. }
  154. /// <summary>
  155. /// Captures the execution state for the provided <see cref="Toplevel"/> view.
  156. /// </summary>
  157. public class RunState : IDisposable {
  158. internal RunState (Toplevel view)
  159. {
  160. Toplevel = view;
  161. }
  162. internal Toplevel Toplevel;
  163. /// <summary>
  164. /// Releases alTop = l resource used by the <see cref="Application.RunState"/> object.
  165. /// </summary>
  166. /// <remarks>Call <see cref="Dispose()"/> when you are finished using the <see cref="Application.RunState"/>. The
  167. /// <see cref="Dispose()"/> method leaves the <see cref="Application.RunState"/> in an unusable state. After
  168. /// calling <see cref="Dispose()"/>, you must release all references to the
  169. /// <see cref="Application.RunState"/> so the garbage collector can reclaim the memory that the
  170. /// <see cref="Application.RunState"/> was occupying.</remarks>
  171. public void Dispose ()
  172. {
  173. Dispose (true);
  174. GC.SuppressFinalize (this);
  175. }
  176. /// <summary>
  177. /// Dispose the specified disposing.
  178. /// </summary>
  179. /// <returns>The dispose.</returns>
  180. /// <param name="disposing">If set to <c>true</c> disposing.</param>
  181. protected virtual void Dispose (bool disposing)
  182. {
  183. if (Toplevel != null) {
  184. End (Toplevel);
  185. Toplevel = null;
  186. }
  187. }
  188. }
  189. static void ProcessKeyEvent (KeyEvent ke)
  190. {
  191. var chain = toplevels.ToList ();
  192. foreach (var topLevel in chain) {
  193. if (topLevel.ProcessHotKey (ke))
  194. return;
  195. if (topLevel.Modal)
  196. break;
  197. }
  198. foreach (var topLevel in chain) {
  199. if (topLevel.ProcessKey (ke))
  200. return;
  201. if (topLevel.Modal)
  202. break;
  203. }
  204. foreach (var topLevel in chain) {
  205. // Process the key normally
  206. if (topLevel.ProcessColdKey (ke))
  207. return;
  208. if (topLevel.Modal)
  209. break;
  210. }
  211. }
  212. static void ProcessKeyDownEvent (KeyEvent ke)
  213. {
  214. var chain = toplevels.ToList ();
  215. foreach (var topLevel in chain) {
  216. if (topLevel.OnKeyDown (ke))
  217. return;
  218. if (topLevel.Modal)
  219. break;
  220. }
  221. }
  222. static void ProcessKeyUpEvent (KeyEvent ke)
  223. {
  224. var chain = toplevels.ToList ();
  225. foreach (var topLevel in chain) {
  226. if (topLevel.OnKeyUp (ke))
  227. return;
  228. if (topLevel.Modal)
  229. break;
  230. }
  231. }
  232. static View FindDeepestView (View start, int x, int y, out int resx, out int resy)
  233. {
  234. var startFrame = start.Frame;
  235. if (!startFrame.Contains (x, y)) {
  236. resx = 0;
  237. resy = 0;
  238. return null;
  239. }
  240. if (start.InternalSubviews != null) {
  241. int count = start.InternalSubviews.Count;
  242. if (count > 0) {
  243. var rx = x - startFrame.X;
  244. var ry = y - startFrame.Y;
  245. for (int i = count - 1; i >= 0; i--) {
  246. View v = start.InternalSubviews [i];
  247. if (v.Frame.Contains (rx, ry)) {
  248. var deep = FindDeepestView (v, rx, ry, out resx, out resy);
  249. if (deep == null)
  250. return v;
  251. return deep;
  252. }
  253. }
  254. }
  255. }
  256. resx = x - startFrame.X;
  257. resy = y - startFrame.Y;
  258. return start;
  259. }
  260. internal static View mouseGrabView;
  261. /// <summary>
  262. /// Grabs the mouse, forcing all mouse events to be routed to the specified view until UngrabMouse is called.
  263. /// </summary>
  264. /// <returns>The grab.</returns>
  265. /// <param name="view">View that will receive all mouse events until UngrabMouse is invoked.</param>
  266. public static void GrabMouse (View view)
  267. {
  268. if (view == null)
  269. return;
  270. mouseGrabView = view;
  271. Driver.UncookMouse ();
  272. }
  273. /// <summary>
  274. /// Releases the mouse grab, so mouse events will be routed to the view on which the mouse is.
  275. /// </summary>
  276. public static void UngrabMouse ()
  277. {
  278. mouseGrabView = null;
  279. Driver.CookMouse ();
  280. }
  281. /// <summary>
  282. /// Merely a debugging aid to see the raw mouse events
  283. /// </summary>
  284. public static Action<MouseEvent> RootMouseEvent;
  285. internal static View wantContinuousButtonPressedView;
  286. static View lastMouseOwnerView;
  287. static void ProcessMouseEvent (MouseEvent me)
  288. {
  289. var view = FindDeepestView (Current, me.X, me.Y, out int rx, out int ry);
  290. if (view != null && view.WantContinuousButtonPressed)
  291. wantContinuousButtonPressedView = view;
  292. else
  293. wantContinuousButtonPressedView = null;
  294. RootMouseEvent?.Invoke (me);
  295. if (mouseGrabView != null) {
  296. var newxy = mouseGrabView.ScreenToView (me.X, me.Y);
  297. var nme = new MouseEvent () {
  298. X = newxy.X,
  299. Y = newxy.Y,
  300. Flags = me.Flags,
  301. OfX = me.X - newxy.X,
  302. OfY = me.Y - newxy.Y,
  303. View = view
  304. };
  305. if (OutsideFrame (new Point (nme.X, nme.Y), mouseGrabView.Frame))
  306. lastMouseOwnerView.OnMouseLeave (me);
  307. if (mouseGrabView != null) {
  308. mouseGrabView.MouseEvent (nme);
  309. return;
  310. }
  311. }
  312. if (view != null) {
  313. var nme = new MouseEvent () {
  314. X = rx,
  315. Y = ry,
  316. Flags = me.Flags,
  317. OfX = rx,
  318. OfY = ry,
  319. View = view
  320. };
  321. if (lastMouseOwnerView == null) {
  322. lastMouseOwnerView = view;
  323. view.OnMouseEnter (nme);
  324. } else if (lastMouseOwnerView != view) {
  325. lastMouseOwnerView.OnMouseLeave (nme);
  326. view.OnMouseEnter (nme);
  327. lastMouseOwnerView = view;
  328. }
  329. if (!view.WantMousePositionReports && me.Flags == MouseFlags.ReportMousePosition)
  330. return;
  331. if (view.WantContinuousButtonPressed)
  332. wantContinuousButtonPressedView = view;
  333. else
  334. wantContinuousButtonPressedView = null;
  335. // Should we bubbled up the event, if it is not handled?
  336. view.MouseEvent (nme);
  337. }
  338. }
  339. static bool OutsideFrame (Point p, Rect r)
  340. {
  341. return p.X < 0 || p.X > r.Width - 1 || p.Y < 0 || p.Y > r.Height - 1;
  342. }
  343. /// <summary>
  344. /// This event is fired once when the application is first loaded. The dimensions of the
  345. /// terminal are provided.
  346. /// </summary>
  347. public static event EventHandler<ResizedEventArgs> Loaded;
  348. /// <summary>
  349. /// Building block API: Prepares the provided <see cref="Toplevel"/> for execution.
  350. /// </summary>
  351. /// <returns>The runstate handle that needs to be passed to the <see cref="End(RunState)"/> method upon completion.</returns>
  352. /// <param name="toplevel">Toplevel to prepare execution for.</param>
  353. /// <remarks>
  354. /// This method prepares the provided toplevel for running with the focus,
  355. /// it adds this to the list of toplevels, sets up the mainloop to process the
  356. /// event, lays out the subviews, focuses the first element, and draws the
  357. /// toplevel in the screen. This is usually followed by executing
  358. /// the <see cref="RunLoop"/> method, and then the <see cref="End(RunState)"/> method upon termination which will
  359. /// undo these changes.
  360. /// </remarks>
  361. public static RunState Begin (Toplevel toplevel)
  362. {
  363. if (toplevel == null)
  364. throw new ArgumentNullException (nameof (toplevel));
  365. var rs = new RunState (toplevel);
  366. Init ();
  367. if (toplevel is ISupportInitializeNotification initializableNotification &&
  368. !initializableNotification.IsInitialized) {
  369. initializableNotification.BeginInit ();
  370. initializableNotification.EndInit ();
  371. } else if (toplevel is ISupportInitialize initializable) {
  372. initializable.BeginInit ();
  373. initializable.EndInit ();
  374. }
  375. toplevels.Push (toplevel);
  376. Current = toplevel;
  377. Driver.PrepareToRun (MainLoop, ProcessKeyEvent, ProcessKeyDownEvent, ProcessKeyUpEvent, ProcessMouseEvent);
  378. if (toplevel.LayoutStyle == LayoutStyle.Computed)
  379. toplevel.RelativeLayout (new Rect (0, 0, Driver.Cols, Driver.Rows));
  380. toplevel.LayoutSubviews ();
  381. Loaded?.Invoke (null, new ResizedEventArgs () { Rows = Driver.Rows, Cols = Driver.Cols });
  382. toplevel.WillPresent ();
  383. Redraw (toplevel);
  384. toplevel.PositionCursor ();
  385. Driver.Refresh ();
  386. return rs;
  387. }
  388. /// <summary>
  389. /// Building block API: completes the execution of a <see cref="Toplevel"/> that was started with <see cref="Begin(Toplevel)"/> .
  390. /// </summary>
  391. /// <param name="runState">The runstate returned by the <see cref="Begin(Toplevel)"/> method.</param>
  392. public static void End (RunState runState)
  393. {
  394. if (runState == null)
  395. throw new ArgumentNullException (nameof (runState));
  396. runState.Dispose ();
  397. runState = null;
  398. }
  399. /// <summary>
  400. /// Shutdown an application initalized with <see cref="Init()"/>
  401. /// </summary>
  402. public static void Shutdown ()
  403. {
  404. foreach (var t in toplevels) {
  405. t.Running = false;
  406. }
  407. toplevels.Clear ();
  408. Current = null;
  409. CurrentView = null;
  410. Top = null;
  411. MainLoop = null;
  412. Driver.End ();
  413. _initialized = false;
  414. }
  415. static void Redraw (View view)
  416. {
  417. Application.CurrentView = view;
  418. view.Redraw (view.Bounds);
  419. Driver.Refresh ();
  420. }
  421. static void Refresh (View view)
  422. {
  423. view.Redraw (view.Bounds);
  424. Driver.Refresh ();
  425. }
  426. /// <summary>
  427. /// Triggers a refresh of the entire display.
  428. /// </summary>
  429. public static void Refresh ()
  430. {
  431. Driver.UpdateScreen ();
  432. View last = null;
  433. foreach (var v in toplevels.Reverse ()) {
  434. v.SetNeedsDisplay ();
  435. v.Redraw (v.Bounds);
  436. last = v;
  437. }
  438. last?.PositionCursor ();
  439. Driver.Refresh ();
  440. }
  441. internal static void End (View view)
  442. {
  443. if (toplevels.Peek () != view)
  444. throw new ArgumentException ("The view that you end with must be balanced");
  445. toplevels.Pop ();
  446. if (toplevels.Count == 0)
  447. Shutdown ();
  448. else {
  449. Current = toplevels.Peek ();
  450. Refresh ();
  451. }
  452. }
  453. /// <summary>
  454. /// Building block API: Runs the main loop for the created dialog
  455. /// </summary>
  456. /// <remarks>
  457. /// Use the wait parameter to control whether this is a
  458. /// blocking or non-blocking call.
  459. /// </remarks>
  460. /// <param name="state">The state returned by the Begin method.</param>
  461. /// <param name="wait">By default this is true which will execute the runloop waiting for events, if you pass false, you can use this method to run a single iteration of the events.</param>
  462. public static void RunLoop (RunState state, bool wait = true)
  463. {
  464. if (state == null)
  465. throw new ArgumentNullException (nameof (state));
  466. if (state.Toplevel == null)
  467. throw new ObjectDisposedException ("state");
  468. bool firstIteration = true;
  469. for (state.Toplevel.Running = true; state.Toplevel.Running;) {
  470. if (MainLoop.EventsPending (wait)) {
  471. // Notify Toplevel it's ready
  472. if (firstIteration) {
  473. state.Toplevel.OnReady ();
  474. }
  475. firstIteration = false;
  476. MainLoop.MainIteration ();
  477. Iteration?.Invoke (null, EventArgs.Empty);
  478. } else if (wait == false)
  479. return;
  480. if (state.Toplevel.NeedDisplay != null && (!state.Toplevel.NeedDisplay.IsEmpty || state.Toplevel.childNeedsDisplay)) {
  481. state.Toplevel.Redraw (state.Toplevel.Bounds);
  482. if (DebugDrawBounds)
  483. DrawBounds (state.Toplevel);
  484. state.Toplevel.PositionCursor ();
  485. Driver.Refresh ();
  486. } else
  487. Driver.UpdateCursor ();
  488. }
  489. }
  490. internal static bool DebugDrawBounds = false;
  491. // Need to look into why this does not work properly.
  492. static void DrawBounds (View v)
  493. {
  494. v.DrawFrame (v.Frame, padding: 0, fill: false);
  495. if (v.InternalSubviews != null && v.InternalSubviews.Count > 0)
  496. foreach (var sub in v.InternalSubviews)
  497. DrawBounds (sub);
  498. }
  499. /// <summary>
  500. /// Runs the application by calling <see cref="Run(Toplevel)"/> with the value of <see cref="Top"/>
  501. /// </summary>
  502. public static void Run ()
  503. {
  504. Run (Top);
  505. }
  506. /// <summary>
  507. /// Runs the application by calling <see cref="Run(Toplevel)"/> with a new instance of the specified <see cref="Toplevel"/>-derived class
  508. /// </summary>
  509. public static void Run<T> () where T : Toplevel, new()
  510. {
  511. Init (() => new T ());
  512. Run (Top);
  513. }
  514. /// <summary>
  515. /// Runs the main loop on the given <see cref="Toplevel"/> container.
  516. /// </summary>
  517. /// <remarks>
  518. /// <para>
  519. /// This method is used to start processing events
  520. /// for the main application, but it is also used to
  521. /// run other modal <see cref="View"/>s such as <see cref="Dialog"/> boxes.
  522. /// </para>
  523. /// <para>
  524. /// To make a <see cref="Run(Toplevel)"/> stop execution, call <see cref="Application.RequestStop"/>.
  525. /// </para>
  526. /// <para>
  527. /// Calling <see cref="Run(Toplevel)"/> is equivalent to calling <see cref="Begin(Toplevel)"/>, followed by <see cref="RunLoop(RunState, bool)"/>,
  528. /// and then calling <see cref="End(RunState)"/>.
  529. /// </para>
  530. /// <para>
  531. /// Alternatively, to have a program control the main loop and
  532. /// process events manually, call <see cref="Begin(Toplevel)"/> to set things up manually and then
  533. /// repeatedly call <see cref="RunLoop(RunState, bool)"/> with the wait parameter set to false. By doing this
  534. /// the <see cref="RunLoop(RunState, bool)"/> method will only process any pending events, timers, idle handlers and
  535. /// then return control immediately.
  536. /// </para>
  537. /// </remarks>
  538. public static void Run (Toplevel view)
  539. {
  540. var runToken = Begin (view);
  541. RunLoop (runToken);
  542. End (runToken);
  543. }
  544. /// <summary>
  545. /// Stops running the most recent <see cref="Toplevel"/>.
  546. /// </summary>
  547. /// <remarks>
  548. /// <para>
  549. /// This will cause <see cref="Application.Run()"/> to return.
  550. /// </para>
  551. /// <para>
  552. /// Calling <see cref="Application.RequestStop"/> is equivalent to setting the <see cref="Toplevel.Running"/> property on the curently running <see cref="Toplevel"/> to false.
  553. /// </para>
  554. /// </remarks>
  555. public static void RequestStop ()
  556. {
  557. Current.Running = false;
  558. }
  559. /// <summary>
  560. /// Event arguments for the <see cref="Application.Resized"/> event.
  561. /// </summary>
  562. public class ResizedEventArgs : EventArgs {
  563. /// <summary>
  564. /// The number of rows in the resized terminal.
  565. /// </summary>
  566. public int Rows { get; set; }
  567. /// <summary>
  568. /// The number of columns in the resized terminal.
  569. /// </summary>
  570. public int Cols { get; set; }
  571. }
  572. /// <summary>
  573. /// Invoked when the terminal was resized. The new size of the terminal is provided.
  574. /// </summary>
  575. public static event EventHandler<ResizedEventArgs> Resized;
  576. static void TerminalResized ()
  577. {
  578. var full = new Rect (0, 0, Driver.Cols, Driver.Rows);
  579. Resized?.Invoke (null, new ResizedEventArgs () { Cols = full.Width, Rows = full.Height });
  580. Driver.Clip = full;
  581. foreach (var t in toplevels) {
  582. t.PositionToplevels ();
  583. t.RelativeLayout (full);
  584. t.LayoutSubviews ();
  585. }
  586. Refresh ();
  587. }
  588. }
  589. }