HexView.cs 22 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780
  1. //
  2. // HexView.cs: A hexadecimal viewer
  3. //
  4. // TODO:
  5. // - Support searching and highlighting of the search result
  6. // - Bug showing the last line
  7. //
  8. namespace Terminal.Gui;
  9. /// <summary>An hex viewer and editor <see cref="View"/> over a <see cref="System.IO.Stream"/></summary>
  10. /// <remarks>
  11. /// <para>
  12. /// <see cref="HexView"/> provides a hex editor on top of a seekable <see cref="Stream"/> with the left side
  13. /// showing an hex dump of the values in the <see cref="Stream"/> and the right side showing the contents (filtered
  14. /// to non-control sequence ASCII characters).
  15. /// </para>
  16. /// <para>Users can switch from one side to the other by using the tab key.</para>
  17. /// <para>
  18. /// To enable editing, set <see cref="AllowEdits"/> to true. When <see cref="AllowEdits"/> is true the user can
  19. /// make changes to the hexadecimal values of the <see cref="Stream"/>. Any changes are tracked in the
  20. /// <see cref="Edits"/> property (a <see cref="SortedDictionary{TKey, TValue}"/>) indicating the position where the
  21. /// changes were made and the new values. A convenience method, <see cref="ApplyEdits"/> will apply the edits to
  22. /// the <see cref="Stream"/>.
  23. /// </para>
  24. /// <para>Control the first byte shown by setting the <see cref="DisplayStart"/> property to an offset in the stream.</para>
  25. /// </remarks>
  26. public class HexView : View
  27. {
  28. private const int bsize = 4;
  29. private const int displayWidth = 9;
  30. private int bpl;
  31. private long displayStart, pos;
  32. private SortedDictionary<long, byte> edits = [];
  33. private bool firstNibble, leftSide;
  34. private Stream source;
  35. private static readonly Rune SpaceCharRune = new (' ');
  36. private static readonly Rune PeriodCharRune = new ('.');
  37. /// <summary>Initializes a <see cref="HexView"/> class.</summary>
  38. /// <param name="source">
  39. /// The <see cref="Stream"/> to view and edit as hex, this <see cref="Stream"/> must support seeking,
  40. /// or an exception will be thrown.
  41. /// </param>
  42. public HexView (Stream source)
  43. {
  44. Source = source;
  45. // BUG: This will always call the most-derived definition of CanFocus.
  46. // Either seal it or don't set it here.
  47. CanFocus = true;
  48. CursorVisibility = CursorVisibility.Default;
  49. leftSide = true;
  50. firstNibble = true;
  51. // PERF: Closure capture of 'this' creates a lot of overhead.
  52. // BUG: Closure capture of 'this' may have unexpected results depending on how this is called.
  53. // The above two comments apply to all of the lambdas passed to all calls to AddCommand below.
  54. // Things this view knows how to do
  55. AddCommand (Command.Left, () => MoveLeft ());
  56. AddCommand (Command.Right, () => MoveRight ());
  57. AddCommand (Command.Down, () => MoveDown (bytesPerLine));
  58. AddCommand (Command.Up, () => MoveUp (bytesPerLine));
  59. AddCommand (Command.Accept, () => ToggleSide ());
  60. AddCommand (Command.PageUp, () => MoveUp (bytesPerLine * Frame.Height));
  61. AddCommand (Command.PageDown, () => MoveDown (bytesPerLine * Frame.Height));
  62. AddCommand (Command.Start, () => MoveHome ());
  63. AddCommand (Command.End, () => MoveEnd ());
  64. AddCommand (Command.LeftStart, () => MoveLeftStart ());
  65. AddCommand (Command.RightEnd, () => MoveEndOfLine ());
  66. AddCommand (Command.StartOfPage, () => MoveUp (bytesPerLine * ((int)(position - displayStart) / bytesPerLine)));
  67. AddCommand (
  68. Command.EndOfPage,
  69. () => MoveDown (bytesPerLine * (Frame.Height - 1 - (int)(position - displayStart) / bytesPerLine))
  70. );
  71. // Default keybindings for this view
  72. KeyBindings.Add (Key.CursorLeft, Command.Left);
  73. KeyBindings.Add (Key.CursorRight, Command.Right);
  74. KeyBindings.Add (Key.CursorDown, Command.Down);
  75. KeyBindings.Add (Key.CursorUp, Command.Up);
  76. KeyBindings.Add (Key.V.WithAlt, Command.PageUp);
  77. KeyBindings.Add (Key.PageUp, Command.PageUp);
  78. KeyBindings.Add (Key.V.WithCtrl, Command.PageDown);
  79. KeyBindings.Add (Key.PageDown, Command.PageDown);
  80. KeyBindings.Add (Key.Home, Command.Start);
  81. KeyBindings.Add (Key.End, Command.End);
  82. KeyBindings.Add (Key.CursorLeft.WithCtrl, Command.LeftStart);
  83. KeyBindings.Add (Key.CursorRight.WithCtrl, Command.RightEnd);
  84. KeyBindings.Add (Key.CursorUp.WithCtrl, Command.StartOfPage);
  85. KeyBindings.Add (Key.CursorDown.WithCtrl, Command.EndOfPage);
  86. LayoutComplete += HexView_LayoutComplete;
  87. }
  88. /// <summary>Initializes a <see cref="HexView"/> class.</summary>
  89. public HexView () : this (new MemoryStream ()) { }
  90. /// <summary>
  91. /// Gets or sets whether this <see cref="HexView"/> allow editing of the <see cref="Stream"/> of the underlying
  92. /// <see cref="Stream"/>.
  93. /// </summary>
  94. /// <value><c>true</c> if allow edits; otherwise, <c>false</c>.</value>
  95. public bool AllowEdits { get; set; } = true;
  96. /// <summary>The bytes length per line.</summary>
  97. public int BytesPerLine => bytesPerLine;
  98. /// <summary>Gets the current cursor position starting at one for both, line and column.</summary>
  99. public Point CursorPosition
  100. {
  101. get
  102. {
  103. if (!IsInitialized)
  104. {
  105. return Point.Empty;
  106. }
  107. var delta = (int)position;
  108. int line = delta / bytesPerLine + 1;
  109. int item = delta % bytesPerLine + 1;
  110. return new Point (item, line);
  111. }
  112. }
  113. /// <summary>
  114. /// Sets or gets the offset into the <see cref="Stream"/> that will be displayed at the top of the
  115. /// <see cref="HexView"/>
  116. /// </summary>
  117. /// <value>The display start.</value>
  118. public long DisplayStart
  119. {
  120. get => displayStart;
  121. set
  122. {
  123. position = value;
  124. SetDisplayStart (value);
  125. }
  126. }
  127. /// <summary>
  128. /// Gets a <see cref="SortedDictionary{TKey, TValue}"/> describing the edits done to the <see cref="HexView"/>.
  129. /// Each Key indicates an offset where an edit was made and the Value is the changed byte.
  130. /// </summary>
  131. /// <value>The edits.</value>
  132. public IReadOnlyDictionary<long, byte> Edits => edits;
  133. /// <summary>Gets the current character position starting at one, related to the <see cref="Stream"/>.</summary>
  134. public long Position => position + 1;
  135. /// <summary>
  136. /// Sets or gets the <see cref="Stream"/> the <see cref="HexView"/> is operating on; the stream must support
  137. /// seeking ( <see cref="Stream.CanSeek"/> == true).
  138. /// </summary>
  139. /// <value>The source.</value>
  140. public Stream Source
  141. {
  142. get => source;
  143. set
  144. {
  145. if (value is null)
  146. {
  147. throw new ArgumentNullException ("source");
  148. }
  149. if (!value.CanSeek)
  150. {
  151. throw new ArgumentException ("The source stream must be seekable (CanSeek property)", "source");
  152. }
  153. source = value;
  154. if (displayStart > source.Length)
  155. {
  156. DisplayStart = 0;
  157. }
  158. if (position > source.Length)
  159. {
  160. position = 0;
  161. }
  162. SetNeedsDisplay ();
  163. }
  164. }
  165. private int bytesPerLine
  166. {
  167. get => bpl;
  168. set
  169. {
  170. bpl = value;
  171. OnPositionChanged ();
  172. }
  173. }
  174. private long position
  175. {
  176. get => pos;
  177. set
  178. {
  179. pos = value;
  180. OnPositionChanged ();
  181. }
  182. }
  183. /// <summary>
  184. /// This method applies and edits made to the <see cref="Stream"/> and resets the contents of the
  185. /// <see cref="Edits"/> property.
  186. /// </summary>
  187. /// <param name="stream">If provided also applies the changes to the passed <see cref="Stream"/></param>
  188. /// .
  189. public void ApplyEdits (Stream stream = null)
  190. {
  191. foreach (KeyValuePair<long, byte> kv in edits)
  192. {
  193. source.Position = kv.Key;
  194. source.WriteByte (kv.Value);
  195. source.Flush ();
  196. if (stream is { })
  197. {
  198. stream.Position = kv.Key;
  199. stream.WriteByte (kv.Value);
  200. stream.Flush ();
  201. }
  202. }
  203. edits = new SortedDictionary<long, byte> ();
  204. SetNeedsDisplay ();
  205. }
  206. /// <summary>
  207. /// This method discards the edits made to the <see cref="Stream"/> by resetting the contents of the
  208. /// <see cref="Edits"/> property.
  209. /// </summary>
  210. public void DiscardEdits () { edits = new SortedDictionary<long, byte> (); }
  211. /// <summary>Event to be invoked when an edit is made on the <see cref="Stream"/>.</summary>
  212. public event EventHandler<HexViewEditEventArgs> Edited;
  213. /// <inheritdoc/>
  214. protected internal override bool OnMouseEvent (MouseEvent me)
  215. {
  216. if (!me.Flags.HasFlag (MouseFlags.Button1Clicked)
  217. && !me.Flags.HasFlag (MouseFlags.Button1DoubleClicked)
  218. && !me.Flags.HasFlag (MouseFlags.WheeledDown)
  219. && !me.Flags.HasFlag (MouseFlags.WheeledUp))
  220. {
  221. return false;
  222. }
  223. if (!HasFocus)
  224. {
  225. SetFocus ();
  226. }
  227. if (me.Flags == MouseFlags.WheeledDown)
  228. {
  229. DisplayStart = Math.Min (DisplayStart + bytesPerLine, source.Length);
  230. return true;
  231. }
  232. if (me.Flags == MouseFlags.WheeledUp)
  233. {
  234. DisplayStart = Math.Max (DisplayStart - bytesPerLine, 0);
  235. return true;
  236. }
  237. if (me.Position.X < displayWidth)
  238. {
  239. return true;
  240. }
  241. int nblocks = bytesPerLine / bsize;
  242. int blocksSize = nblocks * 14;
  243. int blocksRightOffset = displayWidth + blocksSize - 1;
  244. if (me.Position.X > blocksRightOffset + bytesPerLine - 1)
  245. {
  246. return true;
  247. }
  248. leftSide = me.Position.X >= blocksRightOffset;
  249. long lineStart = me.Position.Y * bytesPerLine + displayStart;
  250. int x = me.Position.X - displayWidth + 1;
  251. int block = x / 14;
  252. x -= block * 2;
  253. int empty = x % 3;
  254. int item = x / 3;
  255. if (!leftSide && item > 0 && (empty == 0 || x == block * 14 + 14 - 1 - block * 2))
  256. {
  257. return true;
  258. }
  259. firstNibble = true;
  260. if (leftSide)
  261. {
  262. position = Math.Min (lineStart + me.Position.X - blocksRightOffset, source.Length);
  263. }
  264. else
  265. {
  266. position = Math.Min (lineStart + item, source.Length);
  267. }
  268. if (me.Flags == MouseFlags.Button1DoubleClicked)
  269. {
  270. leftSide = !leftSide;
  271. if (leftSide)
  272. {
  273. firstNibble = empty == 1;
  274. }
  275. else
  276. {
  277. firstNibble = true;
  278. }
  279. }
  280. SetNeedsDisplay ();
  281. return true;
  282. }
  283. ///<inheritdoc/>
  284. public override void OnDrawContent (Rectangle viewport)
  285. {
  286. Attribute currentAttribute;
  287. Attribute current = ColorScheme.Focus;
  288. Driver.SetAttribute (current);
  289. Move (0, 0);
  290. int nblocks = bytesPerLine / bsize;
  291. var data = new byte [nblocks * bsize * viewport.Height];
  292. Source.Position = displayStart;
  293. int n = source.Read (data, 0, data.Length);
  294. Attribute activeColor = ColorScheme.HotNormal;
  295. Attribute trackingColor = ColorScheme.HotFocus;
  296. for (var line = 0; line < viewport.Height; line++)
  297. {
  298. Rectangle lineRect = new (0, line, viewport.Width, 1);
  299. if (!Viewport.Contains (lineRect))
  300. {
  301. continue;
  302. }
  303. Move (0, line);
  304. Driver.SetAttribute (ColorScheme.HotNormal);
  305. Driver.AddStr ($"{displayStart + line * nblocks * bsize:x8} ");
  306. currentAttribute = ColorScheme.HotNormal;
  307. SetAttribute (GetNormalColor ());
  308. for (var block = 0; block < nblocks; block++)
  309. {
  310. for (var b = 0; b < bsize; b++)
  311. {
  312. int offset = line * nblocks * bsize + block * bsize + b;
  313. byte value = GetData (data, offset, out bool edited);
  314. if (offset + displayStart == position || edited)
  315. {
  316. SetAttribute (leftSide ? activeColor : trackingColor);
  317. }
  318. else
  319. {
  320. SetAttribute (GetNormalColor ());
  321. }
  322. Driver.AddStr (offset >= n && !edited ? " " : $"{value:x2}");
  323. SetAttribute (GetNormalColor ());
  324. Driver.AddRune (SpaceCharRune);
  325. }
  326. Driver.AddStr (block + 1 == nblocks ? " " : "| ");
  327. }
  328. for (var bitem = 0; bitem < nblocks * bsize; bitem++)
  329. {
  330. int offset = line * nblocks * bsize + bitem;
  331. byte b = GetData (data, offset, out bool edited);
  332. Rune c;
  333. if (offset >= n && !edited)
  334. {
  335. c = SpaceCharRune;
  336. }
  337. else
  338. {
  339. if (b < 32)
  340. {
  341. c = PeriodCharRune;
  342. }
  343. else if (b > 127)
  344. {
  345. c = PeriodCharRune;
  346. }
  347. else
  348. {
  349. Rune.DecodeFromUtf8 (new ReadOnlySpan<byte> (ref b), out c, out _);
  350. }
  351. }
  352. if (offset + displayStart == position || edited)
  353. {
  354. SetAttribute (leftSide ? trackingColor : activeColor);
  355. }
  356. else
  357. {
  358. SetAttribute (GetNormalColor ());
  359. }
  360. Driver.AddRune (c);
  361. }
  362. }
  363. void SetAttribute (Attribute attribute)
  364. {
  365. if (currentAttribute != attribute)
  366. {
  367. currentAttribute = attribute;
  368. Driver.SetAttribute (attribute);
  369. }
  370. }
  371. }
  372. /// <summary>Method used to invoke the <see cref="Edited"/> event passing the <see cref="KeyValuePair{TKey, TValue}"/>.</summary>
  373. /// <param name="e">The key value pair.</param>
  374. public virtual void OnEdited (HexViewEditEventArgs e) { Edited?.Invoke (this, e); }
  375. /// <summary>
  376. /// Method used to invoke the <see cref="PositionChanged"/> event passing the <see cref="HexViewEventArgs"/>
  377. /// arguments.
  378. /// </summary>
  379. public virtual void OnPositionChanged () { PositionChanged?.Invoke (this, new HexViewEventArgs (Position, CursorPosition, BytesPerLine)); }
  380. /// <inheritdoc/>
  381. public override bool OnProcessKeyDown (Key keyEvent)
  382. {
  383. if (!AllowEdits)
  384. {
  385. return false;
  386. }
  387. // Ignore control characters and other special keys
  388. if (keyEvent < Key.Space || keyEvent.KeyCode > KeyCode.CharMask)
  389. {
  390. return false;
  391. }
  392. if (leftSide)
  393. {
  394. int value;
  395. var k = (char)keyEvent.KeyCode;
  396. if (k >= 'A' && k <= 'F')
  397. {
  398. value = k - 'A' + 10;
  399. }
  400. else if (k >= 'a' && k <= 'f')
  401. {
  402. value = k - 'a' + 10;
  403. }
  404. else if (k >= '0' && k <= '9')
  405. {
  406. value = k - '0';
  407. }
  408. else
  409. {
  410. return false;
  411. }
  412. byte b;
  413. if (!edits.TryGetValue (position, out b))
  414. {
  415. source.Position = position;
  416. b = (byte)source.ReadByte ();
  417. }
  418. RedisplayLine (position);
  419. if (firstNibble)
  420. {
  421. firstNibble = false;
  422. b = (byte)((b & 0xf) | (value << bsize));
  423. edits [position] = b;
  424. OnEdited (new HexViewEditEventArgs (position, edits [position]));
  425. }
  426. else
  427. {
  428. b = (byte)((b & 0xf0) | value);
  429. edits [position] = b;
  430. OnEdited (new HexViewEditEventArgs (position, edits [position]));
  431. MoveRight ();
  432. }
  433. return true;
  434. }
  435. return false;
  436. }
  437. /// <summary>Event to be invoked when the position and cursor position changes.</summary>
  438. public event EventHandler<HexViewEventArgs> PositionChanged;
  439. ///<inheritdoc/>
  440. public override Point? PositionCursor ()
  441. {
  442. var delta = (int)(position - displayStart);
  443. int line = delta / bytesPerLine;
  444. int item = delta % bytesPerLine;
  445. int block = item / bsize;
  446. int column = item % bsize * 3;
  447. int x = displayWidth + block * 14 + column + (firstNibble ? 0 : 1);
  448. int y = line;
  449. if (!leftSide)
  450. {
  451. x = displayWidth + bytesPerLine / bsize * 14 + item - 1;
  452. }
  453. Move (x, y);
  454. return new (x, y);
  455. }
  456. internal void SetDisplayStart (long value)
  457. {
  458. if (value > 0 && value >= source.Length)
  459. {
  460. displayStart = source.Length - 1;
  461. }
  462. else if (value < 0)
  463. {
  464. displayStart = 0;
  465. }
  466. else
  467. {
  468. displayStart = value;
  469. }
  470. SetNeedsDisplay ();
  471. }
  472. //
  473. // This is used to support editing of the buffer on a peer List<>,
  474. // the offset corresponds to an offset relative to DisplayStart, and
  475. // the buffer contains the contents of a screenful of data, so the
  476. // offset is relative to the buffer.
  477. //
  478. //
  479. private byte GetData (byte [] buffer, int offset, out bool edited)
  480. {
  481. long pos = DisplayStart + offset;
  482. if (edits.TryGetValue (pos, out byte v))
  483. {
  484. edited = true;
  485. return v;
  486. }
  487. edited = false;
  488. return buffer [offset];
  489. }
  490. private void HexView_LayoutComplete (object sender, LayoutEventArgs e)
  491. {
  492. // Small buffers will just show the position, with the bsize field value (4 bytes)
  493. bytesPerLine = bsize;
  494. if (Viewport.Width - displayWidth > 17)
  495. {
  496. bytesPerLine = bsize * ((Viewport.Width - displayWidth) / 18);
  497. }
  498. }
  499. private bool MoveDown (int bytes)
  500. {
  501. RedisplayLine (position);
  502. if (position + bytes < source.Length)
  503. {
  504. position += bytes;
  505. }
  506. else if ((bytes == bytesPerLine * Viewport.Height && source.Length >= DisplayStart + bytesPerLine * Viewport.Height)
  507. || (bytes <= bytesPerLine * Viewport.Height - bytesPerLine
  508. && source.Length <= DisplayStart + bytesPerLine * Viewport.Height))
  509. {
  510. long p = position;
  511. while (p + bytesPerLine < source.Length)
  512. {
  513. p += bytesPerLine;
  514. }
  515. position = p;
  516. }
  517. if (position >= DisplayStart + bytesPerLine * Viewport.Height)
  518. {
  519. SetDisplayStart (DisplayStart + bytes);
  520. SetNeedsDisplay ();
  521. }
  522. else
  523. {
  524. RedisplayLine (position);
  525. }
  526. return true;
  527. }
  528. private bool MoveEnd ()
  529. {
  530. position = source.Length;
  531. if (position >= DisplayStart + bytesPerLine * Viewport.Height)
  532. {
  533. SetDisplayStart (position);
  534. SetNeedsDisplay ();
  535. }
  536. else
  537. {
  538. RedisplayLine (position);
  539. }
  540. return true;
  541. }
  542. private bool MoveEndOfLine ()
  543. {
  544. position = Math.Min (position / bytesPerLine * bytesPerLine + bytesPerLine - 1, source.Length);
  545. SetNeedsDisplay ();
  546. return true;
  547. }
  548. private bool MoveHome ()
  549. {
  550. DisplayStart = 0;
  551. SetNeedsDisplay ();
  552. return true;
  553. }
  554. private bool MoveLeft ()
  555. {
  556. RedisplayLine (position);
  557. if (leftSide)
  558. {
  559. if (!firstNibble)
  560. {
  561. firstNibble = true;
  562. return true;
  563. }
  564. firstNibble = false;
  565. }
  566. if (position == 0)
  567. {
  568. return true;
  569. }
  570. if (position - 1 < DisplayStart)
  571. {
  572. SetDisplayStart (displayStart - bytesPerLine);
  573. SetNeedsDisplay ();
  574. }
  575. else
  576. {
  577. RedisplayLine (position);
  578. }
  579. position--;
  580. return true;
  581. }
  582. private bool MoveRight ()
  583. {
  584. RedisplayLine (position);
  585. if (leftSide)
  586. {
  587. if (firstNibble)
  588. {
  589. firstNibble = false;
  590. return true;
  591. }
  592. firstNibble = true;
  593. }
  594. if (position < source.Length)
  595. {
  596. position++;
  597. }
  598. if (position >= DisplayStart + bytesPerLine * Viewport.Height)
  599. {
  600. SetDisplayStart (DisplayStart + bytesPerLine);
  601. SetNeedsDisplay ();
  602. }
  603. else
  604. {
  605. RedisplayLine (position);
  606. }
  607. return true;
  608. }
  609. private bool MoveLeftStart ()
  610. {
  611. position = position / bytesPerLine * bytesPerLine;
  612. SetNeedsDisplay ();
  613. return true;
  614. }
  615. private bool MoveUp (int bytes)
  616. {
  617. RedisplayLine (position);
  618. if (position - bytes > -1)
  619. {
  620. position -= bytes;
  621. }
  622. if (position < DisplayStart)
  623. {
  624. SetDisplayStart (DisplayStart - bytes);
  625. SetNeedsDisplay ();
  626. }
  627. else
  628. {
  629. RedisplayLine (position);
  630. }
  631. return true;
  632. }
  633. private void RedisplayLine (long pos)
  634. {
  635. if (bytesPerLine == 0)
  636. {
  637. return;
  638. }
  639. var delta = (int)(pos - DisplayStart);
  640. int line = delta / bytesPerLine;
  641. SetNeedsDisplay (new (0, line, Viewport.Width, 1));
  642. }
  643. private bool ToggleSide ()
  644. {
  645. leftSide = !leftSide;
  646. RedisplayLine (position);
  647. firstNibble = true;
  648. return true;
  649. }
  650. }